feat(prestashop): delegate product ingestion to orders (1.1.13)

This commit is contained in:
fatequod
2026-09-22 10:49:24 +02:00
parent aa5297c5d8
commit 3030e9439c
7 changed files with 32 additions and 72 deletions
+6 -6
View File
@@ -29,7 +29,7 @@ test('first run safely starts at the newest order without backfilling history',
assert.deepEqual(result, { status: 'initialized', cursor: 812, processed: 0 });
});
test('a failed order is skipped so later orders can still be imported', async () => {
test('a failed order leaves a retryable cursor gap while later orders are still inspected', async () => {
const writes = [];
const imported = [];
const errors = [];
@@ -49,15 +49,15 @@ test('a failed order is skipped so later orders can still be imported', async ()
});
assert.deepEqual(imported, [11, 12, 13]);
assert.deepEqual(writes, [13]);
assert.equal(config.lastOrderId, 13);
assert.deepEqual(result, { status: 'processed', cursor: 13, processed: 2 });
assert.deepEqual(writes, [11]);
assert.equal(config.lastOrderId, 11);
assert.deepEqual(result, { status: 'processed', cursor: 11, processed: 2 });
assert.deepEqual(errors, [{
message: 'Failed to import PS order; skipping order and continuing',
message: 'Failed to import PS order; keeping cursor before the gap and continuing',
details: {
orderId: 12,
previousCursor: 11,
cursor: 12,
cursor: 11,
error: 'invalid order',
},
}]);
+13 -30
View File
@@ -19,7 +19,7 @@ function loadImporter(Core, PsOrder) {
}
}
test('order import upserts verified metadata for the ordered product and pack items', async () => {
test('order import passes verified metadata and pack facts only through core/orders', async () => {
const upserts = [];
let createdOrder = null;
const Core = {
@@ -95,35 +95,18 @@ test('order import upserts verified metadata for the ordered product and pack it
};
await importFromPSOrder('1', api, { _id: 'default', orderStatus: '000000000000000000000001', statusMapping: [] });
assert.equal(upserts.length, 4);
assert.deepEqual(upserts.find(product => product.sourceId === 'product:10:combination:100'), {
sourceModule: 'core/prestashop', sourceId: 'product:10:combination:100', previousSourceId: '10',
sku: 'PACK-V', name: 'Pack', unitPrice: 9.5, tax: 0.23, weight: 2.5,
ean: '', brand: 'Pack Brand', warehouseLocation: 'PACK-V-BIN',
});
assert.deepEqual(upserts.find(product => product.sourceId === 'product:20:combination:200'), {
sourceModule: 'core/prestashop', sourceId: 'product:20:combination:200', previousSourceId: '20',
sku: 'ITEM-V', name: 'Item', unitPrice: 3.25, weight: 4.5,
brand: 'Item Brand', warehouseLocation: 'ITEM-V-BIN',
});
assert.deepEqual(
upserts.filter(product => product.sourceId.startsWith('product:30:')).map(product => product.sourceId),
['product:30:combination:300', 'product:30:combination:301']
);
assert.deepEqual(
upserts.filter(product => product.sourceId.startsWith('product:30:')).map(product => product.sku),
['VARIANT-BLUE', 'VARIANT-RED']
);
assert.deepEqual(upserts.find(product => product.sourceId === 'product:30:combination:300'), {
sourceModule: 'core/prestashop', sourceId: 'product:30:combination:300', previousSourceId: '30',
sku: 'VARIANT-BLUE', name: 'Variant Blue', unitPrice: 17, tax: 0.23, weight: 1.1,
ean: '5901234123457', brand: 'Variant Brand', warehouseLocation: 'BLUE-BIN',
});
assert.deepEqual(upserts.find(product => product.sourceId === 'product:30:combination:301'), {
sourceModule: 'core/prestashop', sourceId: 'product:30:combination:301', previousSourceId: '30',
sku: 'VARIANT-RED', name: 'Variant Red', unitPrice: 18, tax: 0.23, weight: 1.2,
ean: '5901234123464', brand: 'Variant Brand', warehouseLocation: 'RED-BIN',
});
assert.equal(upserts.length, 0, 'PrestaShop must not write the catalog beside core/orders');
assert.equal(createdOrder.products[0].sourceId, 'product:10:combination:100');
assert.equal(createdOrder.products[0].previousSourceId, '10');
assert.equal(createdOrder.products[0].sku, 'PACK-V');
assert.equal(createdOrder.products[0].brand, 'Pack Brand');
assert.equal(createdOrder.products[0].warehouseLocation, 'PACK-V-BIN');
assert.equal(createdOrder.products[0].pack[0].sourceId, 'product:20:combination:200');
assert.equal(createdOrder.products[0].pack[0].previousSourceId, '20');
assert.equal(createdOrder.products[0].pack[0].baseUnitPrice, 3.25);
assert.deepEqual(createdOrder.products.slice(1).map(product => product.sku), [
'VARIANT-BLUE', 'VARIANT-RED',
]);
assert.equal(createdOrder.products[0].unitPrice, 10, 'order keeps its transactional net price');
assert.equal(createdOrder.products[0].baseUnitPrice, 9.5, 'order also carries the catalog base price');
});