Fix composition lookup by external product ID
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m1s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m1s
This commit is contained in:
@@ -208,7 +208,7 @@ const withFakeDatabase = async (run) => {
|
||||
if (normalizedSql.includes('FROM product_compositions composition')) {
|
||||
const compositions = state.compositions.filter(item => (
|
||||
item.source === params[0]
|
||||
&& (params[1] === '' || item.finished_tiny_product_id === params[1] || item.finished_product_sku === String(params[1]).toUpperCase())
|
||||
&& (params[1] === '' || item.finished_tiny_product_id === params[1] || item.external_source_id === params[1] || item.finished_product_sku === String(params[1]).toUpperCase())
|
||||
));
|
||||
return {
|
||||
rows: compositions.map(composition => ({
|
||||
@@ -342,6 +342,36 @@ test('product composition detail lookup returns stored components', async () =>
|
||||
});
|
||||
});
|
||||
|
||||
test('product composition detail lookup supports an exported composition linked by external product ID', async () => {
|
||||
await withFakeDatabase(async () => {
|
||||
const response = await invokeHandler(tinyCompositionImportHandler, {
|
||||
body: {
|
||||
compositions: [{
|
||||
externalSourceId: '919483307',
|
||||
finishedProductSku: 'BLCS.PTO.G',
|
||||
finishedProductDescription: 'BASE LISA CAMISETA COR PRETO TAMANHO - G',
|
||||
finishedProductUnit: 'UN',
|
||||
finishedTinyProductId: '',
|
||||
components: [{
|
||||
componentSku: 'ETIQ.T.G',
|
||||
componentName: 'ETIQUETA DE TAMANHO G',
|
||||
quantityPerUnit: 1,
|
||||
unit: 'UN'
|
||||
}]
|
||||
}]
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(response.statusCode, 201);
|
||||
|
||||
const detail = await invokeHandler(productCompositionHandler, { params: { productId: '919483307' } });
|
||||
assert.equal(detail.statusCode, 200);
|
||||
assert.equal(detail.body.composition.finishedProductSku, 'BLCS.PTO.G');
|
||||
assert.equal(detail.body.composition.finishedTinyProductId, '919483307');
|
||||
assert.equal(detail.body.composition.components.length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
test('product composition export endpoint returns every stored composition', async () => {
|
||||
await withFakeDatabase(async () => {
|
||||
await invokeHandler(tinySyncHandler, { body: compositionPayload() });
|
||||
|
||||
Reference in New Issue
Block a user