Release PrestaShop 1.2.0: use hook contracts

This commit is contained in:
fatequod
2026-09-30 08:26:55 +02:00
parent 6b5e03246e
commit 599a7b9863
25 changed files with 276 additions and 62 deletions
+12 -11
View File
@@ -1,3 +1,4 @@
const { withHookFixtures } = require('./helpers/hook-fixtures');
const test = require('node:test');
const assert = require('node:assert/strict');
@@ -36,7 +37,7 @@ test('a failed order leaves a retryable cursor gap while later orders are still
const config = { _id: 'default', lastOrderId: 10 };
const api = { makeRequest: async () => ({ orders: [oldOrder(11), oldOrder(12), oldOrder(13)] }) };
const result = await importOrdersForShop(config, api, {
Core: { callModule: async () => ({ data: [] }) },
Core: withHookFixtures({ callModule: async () => ({ data: [] }) }),
PsOrder: {},
importFromPSOrder: async id => {
imported.push(id);
@@ -77,7 +78,7 @@ test('existing Orbito order repairs a missing mapping before advancing the curso
};
await importOrdersForShop(config, api, {
Core: { callModule: async () => ({ data: [{ _id: 'orbito-21', summary: { paid: 25 } }] }) },
Core: withHookFixtures({ callModule: async () => ({ data: [{ _id: 'orbito-21', summary: { paid: 25 } }] }) }),
PsOrder,
importFromPSOrder: async () => assert.fail('must not import an existing order'),
setLastOrderId: async id => writes.push(id),
@@ -100,11 +101,11 @@ test('payment sync appends only the cumulative delta with a deterministic transa
const result = await processPaymentMapping(mapping, config, {
getOrder: async () => ({ total_paid_real: '55.00', payment: 'Card', date_upd: '2026-01-02 12:00:00' }),
}, {
Core: { callModule: async (module, method, params) => {
Core: withHookFixtures({ callModule: async (module, method, params) => {
calls.push({ module, method, params });
if (method === 'search') return { data: [{ summary: { paid: 20, gross: 100 } }] };
return { success: true };
} },
} }),
PsOrder: { update: async (...args) => updates.push(args) },
nowDate: new Date('2026-01-02T12:01:00Z'),
nextCheckMs: 1000,
@@ -130,7 +131,7 @@ test('import waits for the 30-second stability window using shop time without gu
{ id: 13, reference: 'R13', date_add: '2026-09-25 15:00:00' },
] }),
}, {
Core: { callModule: async () => ({ data: [] }) },
Core: withHookFixtures({ callModule: async () => ({ data: [] }) }),
importFromPSOrder: async id => { imported.push(id); return { status: 'imported' }; },
setLastOrderId: async id => cursors.push(id),
now: () => Date.parse('2026-09-25T09:01:00Z'),
@@ -148,10 +149,10 @@ test('legacy mapping establishes a conservative baseline instead of duplicating
await processPaymentMapping({ _id: 'map-2', psOrderId: 45, orbitoOrderId: 'order-2' }, { _id: 'default' }, {
getOrder: async () => ({ total_paid_real: '50.00' }),
}, {
Core: { callModule: async (_module, method) => {
Core: withHookFixtures({ callModule: async (_module, method) => {
methods.push(method);
return { data: [{ summary: { paid: 50, gross: 100 } }] };
} },
} }),
PsOrder: { update: async (...args) => updates.push(args) },
nowDate: new Date(), nextCheckMs: 1000, retryCheckMs: 1000, Log: silentLog,
});
@@ -165,11 +166,11 @@ test('a mapping write failure retries the same payment transaction id safely', a
let failMappingWrite = true;
const mapping = { _id: 'map-3', psOrderId: 46, orbitoOrderId: 'order-3', paymentTotalSynced: 10 };
const dependencies = {
Core: { callModule: async (_module, method, params) => {
Core: withHookFixtures({ callModule: async (_module, method, params) => {
if (method === 'search') return { data: [{ summary: { paid: 10, gross: 100 } }] };
transactionIds.push(params.payment.transactionId);
return { success: true };
} },
} }),
PsOrder: { update: async (_query, update) => {
if (update.$set.paymentTotalSynced !== undefined && failMappingWrite) {
failMappingWrite = false;
@@ -204,9 +205,9 @@ test('payment scheduler drains multiple pages and includes orders older than fiv
},
update: async () => {},
};
const Core = { callModule: async (_module, method) => method === 'search'
const Core = withHookFixtures({ callModule: async (_module, method) => method === 'search'
? { data: [{ summary: { paid: 0, gross: 10 } }] }
: { success: true } };
: { success: true } });
const result = await syncPaymentsForShop(
{ _id: 'default' },