This commit is contained in:
seb
2026-09-26 23:06:05 +02:00
parent e491ecfa47
commit e7f92ebef8
41 changed files with 3632 additions and 1751 deletions

View File

@@ -112,6 +112,7 @@ async function run() {
JSON.stringify({
id: 1,
manifestarticle_id: manifestarticleId1,
warehouse_id: null,
transaction_type: 'GOODS_RECEIPT',
amount: 5,
transaction_text: 'Initial delivery movement',
@@ -228,6 +229,68 @@ async function run() {
'History should include second line goods receipt with details',
);
// 9. Test warehouse CRUD and linking with ledger
console.log('8. Testing warehouse CRUD and ledger association...');
const wh1 = await store.warehouse.create(googleAuthId, { name: 'Hauptlager' });
assert.equal(wh1.name, 'Hauptlager');
assert(wh1.id > 0);
const wh2 = await store.warehouse.create(googleAuthId, { name: 'Filiale Nord' });
assert.equal(wh2.name, 'Filiale Nord');
const whList = await store.warehouse.list(googleAuthId);
assert.equal(whList.length, 2);
assert(whList.some((w) => w.name === 'Hauptlager'));
assert(whList.some((w) => w.name === 'Filiale Nord'));
const whGet = await store.warehouse.getById(googleAuthId, wh1.id);
assert.equal(whGet.name, 'Hauptlager');
const whUpdated = await store.warehouse.update(googleAuthId, wh2.id, { name: 'Filiale Süd' });
assert.equal(whUpdated.name, 'Filiale Süd');
// Add ledger row with warehouse
const rowWithWh = await store.ledger.add(googleAuthId, {
manifestarticle_id: manifestarticleId1,
warehouse_id: wh1.id,
transaction_type: 'DELIVERY',
amount: 25,
transaction_text: 'Delivered directly to Hauptlager',
});
assert.equal(rowWithWh.warehouse_id, wh1.id);
assert.equal(rowWithWh.amount, 25);
// Filter by warehouse in listBySku and listByManifestarticleId
const whRowsBySku = await store.ledger.listBySku(googleAuthId, 'SKU-ABC', { warehouse_id: wh1.id });
assert.equal(whRowsBySku.length, 1);
assert.equal(whRowsBySku[0].id, rowWithWh.id);
assert.equal(whRowsBySku[0].warehouse_id, wh1.id);
const whRowsByLine = await store.ledger.listByManifestarticleId(googleAuthId, manifestarticleId1, { warehouse_id: wh1.id });
assert.equal(whRowsByLine.length, 1);
assert.equal(whRowsByLine[0].id, rowWithWh.id);
// Verify warehouse is recorded in article history
const historyWithWh = await store.article.getHistoryBySku(googleAuthId, article.sku);
assert(
historyWithWh.some((h) => h.text.includes('Lager: "Hauptlager"') && h.text.includes('Lieferant: "Supplier X"')),
'History should include warehouse name (Lager: "Hauptlager")',
);
// Trying to delete wh1 (used in ledger) must fail
await assert.rejects(
async () => store.warehouse.delete(googleAuthId, wh1.id),
/Warehouse in use in ledger/,
'Should reject deleting warehouse referenced in ledger',
);
// Deleting wh2 (not used in ledger) must succeed
await store.warehouse.delete(googleAuthId, wh2.id);
const whListAfterDelete = await store.warehouse.list(googleAuthId);
assert.equal(whListAfterDelete.length, 1);
assert.equal(whListAfterDelete[0].id, wh1.id);
console.log('✓ Warehouse CRUD and ledger enforcement passed');
console.log('✓ All ledger tests passed successfully!');
} finally {
try {