Release 1.2.2: recover missed PrestaShop status changes
This commit is contained in:
@@ -82,6 +82,39 @@ test('does not create a duplicate order history when PrestaShop already has the
|
||||
assert.equal(calls, 1);
|
||||
});
|
||||
|
||||
test('persists an attempt only before POST, and a persistence failure prevents POST', async t => {
|
||||
const originalFetch = Core.fetch;
|
||||
t.after(() => { Core.fetch = originalFetch; });
|
||||
const steps = [];
|
||||
Core.fetch = async (url, options) => {
|
||||
steps.push(options.method);
|
||||
return options.method === 'GET'
|
||||
? response(200, { order: { id: '21', current_state: '2' } })
|
||||
: response(201, { order_history: { id: '99', id_order: '21', id_order_state: '7' } });
|
||||
};
|
||||
const api = new PrestashopApi('https://shop.example', 'secret', true);
|
||||
await api.setOrderState(21, 7, { beforeWrite: async () => steps.push('persist') });
|
||||
assert.deepEqual(steps, ['GET', 'persist', 'POST']);
|
||||
steps.length = 0;
|
||||
await assert.rejects(api.setOrderState(21, 7, {
|
||||
beforeWrite: async () => { throw new Error('database unavailable'); },
|
||||
}), /database unavailable/);
|
||||
assert.deepEqual(steps, ['GET']);
|
||||
Core.fetch = async () => response(200, { order: { id: '21', current_state: '7' } });
|
||||
await api.setOrderState(21, 7, { beforeWrite: async () => assert.fail('unnecessary attempt') });
|
||||
});
|
||||
|
||||
test('uncertain status verification rejects a response for another order', async t => {
|
||||
const originalFetch = Core.fetch;
|
||||
t.after(() => { Core.fetch = originalFetch; });
|
||||
Core.fetch = async () => response(200, { order: { id: '22', current_state: '7' } });
|
||||
const api = new PrestashopApi('https://shop.example', 'secret', true);
|
||||
await assert.rejects(api.getOrderState(21), /Invalid PrestaShop order state/);
|
||||
await assert.rejects(api.setOrderState(21, 7, {
|
||||
beforeWrite: async () => assert.fail('wrong order must not reach POST'),
|
||||
}), /Invalid PrestaShop order state/);
|
||||
});
|
||||
|
||||
test('rejects non-retryable 4xx and invalid JSON', async t => {
|
||||
const originalFetch = Core.fetch;
|
||||
t.after(() => { Core.fetch = originalFetch; });
|
||||
|
||||
Reference in New Issue
Block a user