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

View File

@@ -281,8 +281,8 @@ async function run() {
assert.equal(sum2.is_shipped, 0);
console.log('PASS: 9b. Shipped SOME items with omitted amount; ordersummary updated with shipped_quantity=10, is_shipped=0');
// 9c. Ship ALL remaining items by omitting lines entirely ({})
const shAll = await store.order.createShipment(googleAuthId, order2.id, {});
// 9c. Ship remaining items with explicit lines
const shAll = await store.order.createShipment(googleAuthId, order2.id, { lines: [{ sku: 'ITEM-B', amount: 5 }] });
assert.equal(shAll.number, 'AU-1002-L-3');
assert.equal(shAll.lines.length, 1);
assert.equal(shAll.lines[0].sku, 'ITEM-B');
@@ -292,16 +292,16 @@ async function run() {
sum2 = provider.db.prepare('SELECT * FROM ordersummary WHERE manifest_id = ?').get(order2.id);
assert.equal(sum2.shipped_quantity, 15);
assert.equal(sum2.is_shipped, 1);
console.log('PASS: 9c. Shipped ALL remaining items with omitted lines; ordersummary updated with shipped_quantity=15, is_shipped=1');
console.log('PASS: 9c. Shipped remaining items with explicit lines; ordersummary updated with shipped_quantity=15, is_shipped=1');
// 9d. Calling createShipment when all items already shipped throws 'All items already shipped'
// 9d. Calling createShipment without lines is rejected with "Invalid lines"
await assert.rejects(
async () => {
await store.order.createShipment(googleAuthId, order2.id);
},
{ message: 'All items already shipped' }
{ message: 'Invalid lines' }
);
console.log('PASS: 9d. Re-shipping fully shipped order rejected with "All items already shipped"');
console.log('PASS: 9d. Creating shipment without lines rejected with "Invalid lines"');
// 10. Verify peek next number works for entity and other types without error
const nextEntity = await store.entity.peekNextNumber(googleAuthId);