feat: automatically remove items from stock when empty (quantity <= 0)
Build and Push Fridger Container / Build & Push Fridger Image (push) Successful in 1m16s
Build and Push Fridger Container / Build & Push Fridger Image (push) Successful in 1m16s
This commit is contained in:
@@ -76,15 +76,25 @@ console.log('Testing absolute set (100g remaining)...');
|
||||
const updatedAbs = db.adjustQuantity(newItem.id, { newQuantity: 100 });
|
||||
assert.strictEqual(updatedAbs.quantity, 100);
|
||||
|
||||
// Consume remaining
|
||||
console.log('Testing consume all...');
|
||||
// Consume remaining -> should automatically remove from stock
|
||||
console.log('Testing consume all (auto-remove on empty)...');
|
||||
const finished = db.adjustQuantity(newItem.id, { newQuantity: 0 });
|
||||
assert.strictEqual(finished.quantity, 0);
|
||||
assert.strictEqual(finished.deleted, true, 'Result should indicate item was deleted');
|
||||
assert.strictEqual(db.getItemById(newItem.id), undefined, 'Item should be automatically removed from DB when empty');
|
||||
|
||||
// Delete test item
|
||||
const deleted = db.deleteItem(newItem.id);
|
||||
assert.strictEqual(deleted, true);
|
||||
assert.strictEqual(db.getItemById(newItem.id), undefined);
|
||||
// Test packet removal to 0 -> should automatically remove from stock
|
||||
console.log('Testing packet removal to 0 (auto-remove on empty)...');
|
||||
const autoRemovePack = db.createItem({
|
||||
name: 'Test Packet Auto-Remove',
|
||||
quantity: 250,
|
||||
initial_quantity: 250,
|
||||
unit: 'g'
|
||||
});
|
||||
const packFinished = db.removePacket(autoRemovePack.id, 1);
|
||||
assert.strictEqual(packFinished.quantity, 0);
|
||||
assert.strictEqual(packFinished.deleted, true);
|
||||
assert.strictEqual(db.getItemById(autoRemovePack.id), undefined, 'Packet should be automatically removed when 0 left');
|
||||
|
||||
// Test stats
|
||||
const stats = db.getStats();
|
||||
|
||||
Reference in New Issue
Block a user