feat(prestashop): sync mapped statuses from Orbito in 1.1.11

This commit is contained in:
fatequod
2026-09-21 15:01:30 +02:00
parent af0dceaa1b
commit 11f1c99e2b
16 changed files with 587 additions and 32 deletions
+40
View File
@@ -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; });