Use hook-backed outbound status mapping
This commit is contained in:
@@ -68,6 +68,36 @@ test('syncs the current Orbito status to the mapped PrestaShop state', async ()
|
||||
assert.equal(result.synced, true);
|
||||
});
|
||||
|
||||
test('different Orbito statuses both synchronize to their shared PrestaShop state', async () => {
|
||||
const { registerContract } = require('../src/hook-contract');
|
||||
const { readStatusMapping } = require('../src/status-mapper');
|
||||
const { deps, calls } = dependencies();
|
||||
let statusId = OLD_STATUS;
|
||||
const hooks = new Map();
|
||||
registerContract({
|
||||
getInstanceId: () => 'alternative-orders-instance',
|
||||
getModuleInfo: () => ({ code: 'alternative/orders' }),
|
||||
registerHook: (name, handler) => hooks.set(name, handler),
|
||||
}, 'orders.search', async () => ({ data: [{
|
||||
_id: ORDER_ID, statusId,
|
||||
source: { moduleCode: 'core/prestashop', moduleId: deps.Core.getInstanceId(), sourceId: '21' },
|
||||
}] }));
|
||||
deps.Core.execHook = async (name, request) => [await hooks.get(name).call({
|
||||
caller: { moduleCode: 'core/prestashop', instanceId: deps.Core.getInstanceId() },
|
||||
}, request)];
|
||||
deps.loadConfig = async () => ({
|
||||
apiUrl: 'https://shop.test', apiKey: 'secret',
|
||||
statusMapping: readStatusMapping({
|
||||
[`mapping.orbito_${OLD_STATUS}`]: '7',
|
||||
[`mapping.orbito_${CURRENT_STATUS}`]: '7',
|
||||
}),
|
||||
});
|
||||
await syncOrderStatusToPrestashop({ orderId: ORDER_ID }, deps);
|
||||
statusId = CURRENT_STATUS;
|
||||
await syncOrderStatusToPrestashop({ orderId: ORDER_ID }, deps);
|
||||
assert.deepEqual(calls.setOrderState, [[21, 7], [21, 7]]);
|
||||
});
|
||||
|
||||
test('ignores status events for an order owned by another PrestaShop instance', async () => {
|
||||
const { deps, calls } = dependencies();
|
||||
deps.Core.callModule = async () => ({ data: [{
|
||||
|
||||
Reference in New Issue
Block a user