u
This commit is contained in:
@@ -403,6 +403,40 @@ async function run() {
|
||||
'Adjust must fail when article has no stock tracking',
|
||||
);
|
||||
|
||||
// 10b. Test prevention of negative stock on shipment creation and stock adjust
|
||||
console.log('10b. Testing prevention of negative stock on shipment creation and adjust...');
|
||||
const guardOrder = await store.order.create(googleAuthId, {
|
||||
number: 'ORD-GUARD-1',
|
||||
date: '2026-10-20',
|
||||
entityId: customer.id,
|
||||
lines: [{ sku: article.sku, name: 'Order Line', pu: 1, amount: 9999, net: 10, taxrate: 19 }],
|
||||
});
|
||||
|
||||
const currentArt = await store.article.getBySku(googleAuthId, article.sku);
|
||||
const curStock = currentArt.article.warehouses.find((w) => w.id === wh1.id)?.stock ?? 0;
|
||||
|
||||
// Explicit shipment requesting more than available stock must be rejected
|
||||
await assert.rejects(
|
||||
async () => store.shipment.create(googleAuthId, {
|
||||
orderId: guardOrder.id,
|
||||
warehouseId: wh1.id,
|
||||
lines: [{ sku: article.sku, amount: curStock + 10 }],
|
||||
}),
|
||||
/Insufficient stock for article/,
|
||||
'Shipment creation must fail when requested amount exceeds warehouse stock',
|
||||
);
|
||||
|
||||
// Manual stock adjust attempting to deduct more than current stock must be rejected
|
||||
await assert.rejects(
|
||||
async () => store.stock.adjust(googleAuthId, {
|
||||
sku: article.sku,
|
||||
warehouseId: wh1.id,
|
||||
amount: -(curStock + 10),
|
||||
}),
|
||||
/Insufficient stock for article/,
|
||||
'Stock adjust must fail when deduction exceeds available stock',
|
||||
);
|
||||
|
||||
// 11. Test before stock tracking is disabled, adjust to 0 has to be ledgerized
|
||||
console.log('11. Testing zero-adjustment before stock tracking is disabled...');
|
||||
const artBeforeDisable = await store.article.getBySku(googleAuthId, article.sku);
|
||||
|
||||
Reference in New Issue
Block a user