u
This commit is contained in:
@@ -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!');
|
||||
|
||||
Reference in New Issue
Block a user