Use hook-backed outbound status mapping

This commit is contained in:
fatequod
2026-09-30 11:49:04 +02:00
parent 599a7b9863
commit 1f79463f51
9 changed files with 392 additions and 169 deletions
+27 -1
View File
@@ -1,7 +1,7 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { resolvePsStateId } = require('../src/status-mapper');
const { resolvePsStateId, readStatusMapping } = require('../src/status-mapper');
const STATUS_A = '507f191e810c19729de860ea';
const STATUS_B = '507f191e810c19729de860eb';
@@ -22,3 +22,29 @@ test('rejects an ambiguous outbound status mapping', () => {
{ psStateId: 3, orbitoStatusId: STATUS_A },
]), /kilku statusów PrestaShop/);
});
test('an outbound override affects only its Orbito status and preserves all other legacy assignments', () => {
const config = { 'mapping.state_2': STATUS_A, 'mapping.state_7': STATUS_B, [`mapping.orbito_${STATUS_A}`]: '7' };
const mapping = readStatusMapping(config);
assert.equal(resolvePsStateId(STATUS_A, mapping), 7);
assert.equal(resolvePsStateId(STATUS_B, mapping), 7);
assert.equal(config['mapping.state_2'], STATUS_A);
});
test('clearing an outbound field never resurrects its legacy mapping', () => {
for (const empty of ['', null]) {
const mapping = readStatusMapping({
'mapping.state_2': STATUS_A,
'mapping.state_7': STATUS_B,
[`mapping.orbito_${STATUS_A}`]: empty,
});
assert.equal(resolvePsStateId(STATUS_A, mapping), null);
assert.equal(resolvePsStateId(STATUS_B, mapping), 7);
}
});
test('invalid saved outbound state fails safely instead of sending a truncated state ID', () => {
for (const value of ['2foo', '-2', '0', '2.5']) {
assert.throws(() => readStatusMapping({ [`mapping.orbito_${STATUS_A}`]: value }), /Niepoprawny status/);
}
});