This commit is contained in:
seb
2026-10-20 05:33:11 +02:00
parent 5cb38874ca
commit bcefd81af7
23 changed files with 514 additions and 150 deletions

View File

@@ -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);