This commit is contained in:
seb
2026-10-16 12:35:07 +02:00
parent 70e3ae7a87
commit 796f6a3272
23 changed files with 193 additions and 38 deletions

View File

@@ -47,6 +47,14 @@ async function run() {
parentId: company.rootCategoryId,
name: 'Ledger Linked Article',
});
assert.equal(article.track_stock, false, 'Newly created article must have track_stock disabled');
await assert.rejects(
async () => store.article.setTrackStockBySku(googleAuthId, article.sku, true),
/At least one warehouse is required to enable stock tracking/,
'Should reject enabling stock tracking when no warehouse exists',
);
await store.articlesupplier.create(googleAuthId, article.sku, {
entityId: supplier.id,
sku: 'SKU-ABC',
@@ -278,6 +286,9 @@ async function run() {
assert.equal(articleDetail.article.warehouses[1].id, wh1.id);
assert.equal(articleDetail.article.warehouses[1].sort, 1);
// Enable stock tracking now that warehouses exist
await store.article.setTrackStockBySku(googleAuthId, article.sku, true);
// Add ledger row with warehouse
const rowWithWh = await store.ledger.add(googleAuthId, {
manifestarticle_id: manifestarticleId1,
@@ -318,6 +329,38 @@ async function run() {
const whListAfterDelete = await store.warehouse.list(googleAuthId);
assert.equal(whListAfterDelete.length, 1);
assert.equal(whListAfterDelete[0].id, wh1.id);
// Test last warehouse guard with track_stock articles
const freshCompany = await store.company.create({
name: 'Warehouse Test Co',
iso639: 'de',
taxrate: 19,
reducedtaxrate: 7,
googleAuthId,
});
await store.google_auth.setSelectedCompany(googleAuthId, freshCompany.id);
const testWh = await store.warehouse.create(googleAuthId, { name: 'Only Warehouse' });
const testArt = await store.article.createUnderParent({
googleAuthId,
parentId: freshCompany.rootCategoryId,
name: 'Tracked Article',
track_stock: true,
});
assert.equal(testArt.track_stock, true);
await assert.rejects(
async () => store.warehouse.delete(googleAuthId, testWh.id),
/Cannot delete the last warehouse while articles have stock tracking enabled/,
'Should reject deleting last warehouse when articles have track_stock enabled',
);
// Disable track_stock on the article, then deleting the last warehouse must succeed
await store.article.setTrackStockBySku(googleAuthId, testArt.sku, false);
await store.warehouse.delete(googleAuthId, testWh.id);
const remainingWh = await store.warehouse.list(googleAuthId);
assert.equal(remainingWh.length, 0);
// Switch back to original company
await store.google_auth.setSelectedCompany(googleAuthId, company.id);
console.log('✓ Warehouse CRUD and ledger enforcement passed');
console.log('✓ All ledger tests passed successfully!');

View File

@@ -47,12 +47,14 @@ async function run() {
parentId: company.rootCategoryId,
name: 'Item A',
sku: 'ITEM-A',
track_stock: true,
});
const itemB = await store.article.createUnderParent({
googleAuthId,
parentId: company.rootCategoryId,
name: 'Item B',
sku: 'ITEM-B',
track_stock: true,
});
// Stock up Item A (20) and Item B (20)

View File

@@ -157,14 +157,27 @@ async function runTests() {
parentId: cat.id,
name: 'Test Article',
});
assert.equal(article.track_stock, true, 'Default track_stock must be true');
assert.equal(article.track_stock, false, 'Default track_stock must be false');
const fetchedArt = await store.article.getBySku(googleAuthId, article.sku);
assert.equal(fetchedArt.article.track_stock, true, 'getBySku must return track_stock: true');
assert.equal(fetchedArt.article.track_stock, false, 'getBySku must return track_stock: false');
await store.article.setTrackStockBySku(googleAuthId, article.sku, false);
// Enabling track_stock without a warehouse must fail
await assert.rejects(
async () => store.article.setTrackStockBySku(googleAuthId, article.sku, true),
/At least one warehouse is required to enable stock tracking/,
);
// Create warehouse to allow enabling track_stock
await store.warehouse.create(googleAuthId, { name: 'Storage WH' });
await store.article.setTrackStockBySku(googleAuthId, article.sku, true);
const afterSet = await store.article.getBySku(googleAuthId, article.sku);
assert.equal(afterSet.article.track_stock, false, 'setTrackStockBySku false must update track_stock');
assert.equal(afterSet.article.track_stock, true, 'setTrackStockBySku true must update track_stock');
await store.article.updateBySku(googleAuthId, article.sku, { track_stock: false });
const afterDisable = await store.article.getBySku(googleAuthId, article.sku);
assert.equal(afterDisable.article.track_stock, false, 'updateBySku track_stock: false must update track_stock');
await store.article.updateBySku(googleAuthId, article.sku, { track_stock: true });
const afterUpdate = await store.article.getBySku(googleAuthId, article.sku);

View File

@@ -40,11 +40,13 @@ async function run() {
googleAuthId,
parentId: company.rootCategoryId,
name: 'Component Article 1',
track_stock: true,
});
const comp2 = await store.article.createUnderParent({
googleAuthId,
parentId: company.rootCategoryId,
name: 'Component Article 2',
track_stock: true,
});
// Create a bundle article