fix: Make transactions atomic / AutoLogout
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:kooltab2/models/product.dart';
|
||||
import 'package:kooltab2/models/tab_item.dart';
|
||||
import 'package:kooltab2/services/bar_tab_service.dart';
|
||||
import 'package:kooltab2/services/product_service.dart';
|
||||
@@ -27,38 +26,28 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'does not increase a tab item when its product is out of stock',
|
||||
() async {
|
||||
const product = Product(
|
||||
id: 'prod-1',
|
||||
name: 'Chips',
|
||||
category: 'Snacks',
|
||||
stockQuantity: 0,
|
||||
lowStockThreshold: 5,
|
||||
priceInCents: 150,
|
||||
);
|
||||
const item = TabItem(
|
||||
id: 'item-1',
|
||||
tabId: 'tab-1',
|
||||
productId: 'prod-1',
|
||||
productName: 'Chips',
|
||||
quantity: 20,
|
||||
unitPriceInCents: 150,
|
||||
);
|
||||
test('propagates an insufficient-stock error from the transaction', () async {
|
||||
const item = TabItem(
|
||||
id: 'item-1',
|
||||
tabId: 'tab-1',
|
||||
productId: 'prod-1',
|
||||
productName: 'Chips',
|
||||
quantity: 20,
|
||||
unitPriceInCents: 150,
|
||||
);
|
||||
|
||||
when(
|
||||
() => productService.getProducts(),
|
||||
).thenAnswer((_) async => [product]);
|
||||
await inventory.load();
|
||||
when(
|
||||
() => barTabService.adjustTabItemQuantity(tabItemId: 'item-1', delta: 1),
|
||||
).thenAnswer((_) async => throw const InsufficientStockException());
|
||||
|
||||
await expectLater(
|
||||
viewModel.changeItemQuantity(item, 21),
|
||||
throwsA(isA<InsufficientStockException>()),
|
||||
);
|
||||
await expectLater(
|
||||
viewModel.changeItemQuantity(item, 1),
|
||||
throwsA(isA<InsufficientStockException>()),
|
||||
);
|
||||
|
||||
expect(viewModel.errorMessage, isNull);
|
||||
verifyNoMoreInteractions(barTabService);
|
||||
},
|
||||
);
|
||||
expect(viewModel.errorMessage, isNull);
|
||||
verify(
|
||||
() => barTabService.adjustTabItemQuantity(tabItemId: 'item-1', delta: 1),
|
||||
).called(1);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user