feat: make server owner of tabs
This commit is contained in:
@@ -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', () {
|
||||
|
||||
Reference in New Issue
Block a user