feat(prestashop): sync mapped statuses from Orbito in 1.1.11
This commit is contained in:
@@ -41,6 +41,46 @@ test('does not retry mutating requests', async t => {
|
||||
assert.equal(calls, 1);
|
||||
});
|
||||
|
||||
test('changes an order state by creating an idempotent PrestaShop order history', async t => {
|
||||
const originalFetch = Core.fetch;
|
||||
t.after(() => { Core.fetch = originalFetch; });
|
||||
const requests = [];
|
||||
Core.fetch = async (url, options) => {
|
||||
requests.push({ url, options });
|
||||
if (options.method === 'GET') {
|
||||
return response(200, { order: { id: '21', current_state: '2' } });
|
||||
}
|
||||
return response(201, { order_history: { id: '99', id_order: '21', id_order_state: '7' } });
|
||||
};
|
||||
const api = new PrestashopApi('https://shop.example', 'secret', false, { maxGetAttempts: 1 });
|
||||
|
||||
const result = await api.setOrderState(21, 7);
|
||||
|
||||
assert.equal(result.unchanged, false);
|
||||
assert.equal(requests.length, 2);
|
||||
assert.match(requests[0].url, /\/api\/orders\/21\?/);
|
||||
assert.equal(requests[1].options.method, 'POST');
|
||||
assert.match(requests[1].url, /\/api\/order_histories\?output_format=JSON$/);
|
||||
assert.match(requests[1].options.body, /<id_order_state>7<\/id_order_state>/);
|
||||
assert.match(requests[1].options.body, /<id_order>21<\/id_order>/);
|
||||
});
|
||||
|
||||
test('does not create a duplicate order history when PrestaShop already has the target state', async t => {
|
||||
const originalFetch = Core.fetch;
|
||||
t.after(() => { Core.fetch = originalFetch; });
|
||||
let calls = 0;
|
||||
Core.fetch = async () => {
|
||||
calls += 1;
|
||||
return response(200, { order: { id: '21', current_state: '7' } });
|
||||
};
|
||||
const api = new PrestashopApi('https://shop.example', 'secret', true, { maxGetAttempts: 1 });
|
||||
|
||||
const result = await api.setOrderState('21', '7');
|
||||
|
||||
assert.equal(result.unchanged, true);
|
||||
assert.equal(calls, 1);
|
||||
});
|
||||
|
||||
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