feat: make server owner of tabs

This commit is contained in:
2026-10-20 16:15:14 +02:00
parent 5754ae742d
commit 93acfe15a9
26 changed files with 3654 additions and 389 deletions
+7 -21
View File
@@ -226,7 +226,7 @@ void main() {
expect(storedProduct.stockQuantity, 99);
});
test('rolls back the tab insert when stock is unavailable', () async {
test('still sells when the stock is at zero', () async {
final tab = await service.createTab(customerName: 'John');
final product = createTestProduct();
@@ -234,13 +234,14 @@ void main() {
..where((row) => row.id.equals(product.id)))
.write(const ProductsCompanion(stockQuantity: Value(0)));
await expectLater(
service.addProductToTab(tabId: tab.id, product: product),
throwsA(isA<InsufficientStockException>()),
);
await service.addProductToTab(tabId: tab.id, product: product);
final updatedTab = await service.getTabById(tab.id);
expect(updatedTab!.items, isEmpty);
expect(updatedTab!.items.single.quantity, 1);
final storedProduct = await (database.select(
database.products,
)..where((row) => row.id.equals(product.id))).getSingle();
expect(storedProduct.stockQuantity, -1);
});
});
@@ -480,21 +481,6 @@ void main() {
expect(afterAdjust.version, afterAdd.version + 1);
expect(afterRename.version, afterAdjust.version + 1);
});
test('a failed add leaves the version untouched', () async {
final tab = await service.createTab(customerName: 'John');
final product = createTestProduct();
await (database.update(database.products)
..where((row) => row.id.equals(product.id)))
.write(const ProductsCompanion(stockQuantity: Value(0)));
await expectLater(
service.addProductToTab(tabId: tab.id, product: product),
throwsA(isA<InsufficientStockException>()),
);
expect((await service.getTabById(tab.id))!.version, tab.version);
});
});
group('watchOpenTabs', () {