u
This commit is contained in:
@@ -369,6 +369,11 @@ const MENU = {
|
||||
label: 'setWeightBySku',
|
||||
hint: 'googleAuthId, sku, weight → row',
|
||||
},
|
||||
{
|
||||
value: 'article.setTrackStockBySku',
|
||||
label: 'setTrackStockBySku',
|
||||
hint: 'googleAuthId, sku, trackStock (true|false) → row',
|
||||
},
|
||||
{
|
||||
value: 'article.setCategoryIdsBySku',
|
||||
label: 'setCategoryIdsBySku',
|
||||
@@ -1762,6 +1767,27 @@ async function runMethod(client, action) {
|
||||
),
|
||||
];
|
||||
}
|
||||
case 'article.setTrackStockBySku': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
const sku = await askText('sku', {
|
||||
validate: (v) => (!v?.trim() ? 'Required' : undefined),
|
||||
});
|
||||
if (sku == null) return;
|
||||
const trackStockRaw = await p.confirm({
|
||||
message: 'Track stock?',
|
||||
initialValue: true,
|
||||
});
|
||||
if (p.isCancel(trackStockRaw)) return;
|
||||
return [
|
||||
'result',
|
||||
await client.article.setTrackStockBySku(
|
||||
Number(googleAuthId),
|
||||
sku,
|
||||
Boolean(trackStockRaw),
|
||||
),
|
||||
];
|
||||
}
|
||||
case 'article.setCategoryIdsBySku': {
|
||||
const googleAuthId = await askInt('google_auth id');
|
||||
if (googleAuthId == null) return;
|
||||
|
||||
@@ -229,25 +229,54 @@ 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...');
|
||||
// 9. Test warehouse CRUD, sort, reorder, and linking with ledger
|
||||
console.log('8. Testing warehouse CRUD, sort, reorder, and ledger association...');
|
||||
const wh1 = await store.warehouse.create(googleAuthId, { name: 'Hauptlager' });
|
||||
assert.equal(wh1.name, 'Hauptlager');
|
||||
assert.equal(wh1.sort, 0);
|
||||
assert(wh1.id > 0);
|
||||
|
||||
const wh2 = await store.warehouse.create(googleAuthId, { name: 'Filiale Nord' });
|
||||
assert.equal(wh2.name, 'Filiale Nord');
|
||||
assert.equal(wh2.sort, 1);
|
||||
|
||||
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'));
|
||||
assert.equal(whList[0].id, wh1.id);
|
||||
assert.equal(whList[0].sort, 0);
|
||||
assert.equal(whList[1].id, wh2.id);
|
||||
assert.equal(whList[1].sort, 1);
|
||||
|
||||
const whGet = await store.warehouse.getById(googleAuthId, wh1.id);
|
||||
assert.equal(whGet.name, 'Hauptlager');
|
||||
assert.equal(whGet.sort, 0);
|
||||
|
||||
const whUpdated = await store.warehouse.update(googleAuthId, wh2.id, { name: 'Filiale Süd' });
|
||||
const whUpdated = await store.warehouse.update(googleAuthId, wh2.id, { name: 'Filiale Süd', sort: 5 });
|
||||
assert.equal(whUpdated.name, 'Filiale Süd');
|
||||
assert.equal(whUpdated.sort, 5);
|
||||
|
||||
// Test warehouse order
|
||||
await store.warehouse.order(googleAuthId, { warehouseIds: [wh2.id, wh1.id] });
|
||||
const whListReordered = await store.warehouse.list(googleAuthId);
|
||||
assert.equal(whListReordered[0].id, wh2.id);
|
||||
assert.equal(whListReordered[0].sort, 0);
|
||||
assert.equal(whListReordered[1].id, wh1.id);
|
||||
assert.equal(whListReordered[1].sort, 1);
|
||||
|
||||
// Test invalid warehouse order
|
||||
await assert.rejects(
|
||||
async () => store.warehouse.order(googleAuthId, { warehouseIds: [wh1.id] }),
|
||||
/Invalid warehouse order/,
|
||||
);
|
||||
|
||||
// Verify article detail includes warehouses with sort
|
||||
const articleDetail = await store.article.getBySku(googleAuthId, article.sku);
|
||||
assert(Array.isArray(articleDetail.article.warehouses), 'Article should have warehouses array');
|
||||
assert.equal(articleDetail.article.warehouses.length, 2);
|
||||
assert.equal(articleDetail.article.warehouses[0].id, wh2.id);
|
||||
assert.equal(articleDetail.article.warehouses[0].sort, 0);
|
||||
assert.equal(articleDetail.article.warehouses[1].id, wh1.id);
|
||||
assert.equal(articleDetail.article.warehouses[1].sort, 1);
|
||||
|
||||
// Add ledger row with warehouse
|
||||
const rowWithWh = await store.ledger.add(googleAuthId, {
|
||||
|
||||
@@ -154,6 +154,37 @@ async function runTests() {
|
||||
parentId: cat.id,
|
||||
name: 'Test Article',
|
||||
});
|
||||
assert.equal(article.track_stock, true, 'Default track_stock must be true');
|
||||
|
||||
const fetchedArt = await store.article.getBySku(googleAuthId, article.sku);
|
||||
assert.equal(fetchedArt.article.track_stock, true, 'getBySku must return track_stock: true');
|
||||
|
||||
await store.article.setTrackStockBySku(googleAuthId, article.sku, false);
|
||||
const afterSet = await store.article.getBySku(googleAuthId, article.sku);
|
||||
assert.equal(afterSet.article.track_stock, false, 'setTrackStockBySku false must update track_stock');
|
||||
|
||||
await store.article.updateBySku(googleAuthId, article.sku, { track_stock: true });
|
||||
const afterUpdate = await store.article.getBySku(googleAuthId, article.sku);
|
||||
assert.equal(afterUpdate.article.track_stock, true, 'updateBySku track_stock: true must update track_stock');
|
||||
|
||||
const history = await store.article.getHistoryBySku(googleAuthId, article.sku);
|
||||
assert(history.some((h) => h.text.includes('Bestandsführung geändert von "Nein" auf "Ja"')));
|
||||
|
||||
const nonTracked = await store.article.createUnderParent({
|
||||
googleAuthId,
|
||||
parentId: cat.id,
|
||||
name: 'Service Item',
|
||||
track_stock: false,
|
||||
});
|
||||
assert.equal(nonTracked.track_stock, false, 'Explicit track_stock: false must be preserved');
|
||||
const fetchedNonTracked = await store.article.getBySku(googleAuthId, nonTracked.sku);
|
||||
assert.equal(fetchedNonTracked.article.track_stock, false);
|
||||
|
||||
const exported = await store.article.listExport(googleAuthId, cat.id);
|
||||
const foundExport = exported.find((a) => a.sku === article.sku);
|
||||
assert.equal(foundExport.track_stock, true, 'listExport must include track_stock');
|
||||
|
||||
console.log('Article track_stock tests passed!');
|
||||
|
||||
const sampleImage = await sharp({
|
||||
create: {
|
||||
|
||||
Reference in New Issue
Block a user