fix: alot
This commit is contained in:
@@ -146,6 +146,21 @@ void main() {
|
||||
expect(server.syncRequests.last['cursor'], 'cursor-1');
|
||||
});
|
||||
|
||||
test('leaves undone drinks out of the snapshot total', () async {
|
||||
final tab = await barTabService.createTab(customerName: 'Alice');
|
||||
await barTabService.addProductToTab(tabId: tab.id, product: _beer);
|
||||
await barTabService.addProductToTab(tabId: tab.id, product: _beer);
|
||||
final item = (await barTabService.getTabById(tab.id))!.items.single;
|
||||
await barTabService.adjustTabItemQuantity(tabItemId: item.id, delta: -2);
|
||||
|
||||
await service.sync();
|
||||
|
||||
final snapshot = (server.syncRequests.single['openTabs'] as List).single;
|
||||
expect(snapshot['totalInCents'], 0);
|
||||
expect(snapshot['itemCount'], 0);
|
||||
expect(snapshot['items'], isEmpty);
|
||||
});
|
||||
|
||||
test('reports a server error as a failure, not a success', () async {
|
||||
server.syncResponse = http.Response('oops', 500);
|
||||
|
||||
@@ -222,6 +237,31 @@ void main() {
|
||||
expect(eventTypes(), contains(RemoteSyncEventType.tabClosedRemotely));
|
||||
});
|
||||
|
||||
test('charges what the dashboard saw when it asked', () async {
|
||||
final tab = await barTabService.createTab(customerName: 'Alice');
|
||||
for (var i = 0; i < 3; i++) {
|
||||
await barTabService.addProductToTab(tabId: tab.id, product: _beer);
|
||||
}
|
||||
await service.sync();
|
||||
final seen = (server.syncRequests.last['openTabs'] as List).single;
|
||||
|
||||
server.respondWith({
|
||||
'commands': [
|
||||
_closeCommand(
|
||||
id: 'cmd-1',
|
||||
tabId: tab.id,
|
||||
expectedVersion: seen['version'] as int,
|
||||
),
|
||||
],
|
||||
});
|
||||
await service.sync();
|
||||
|
||||
final closed = (await barTabService.getClosedTabs()).single;
|
||||
expect(closed.totalInCents, seen['totalInCents']);
|
||||
expect(closed.totalInCents, 1200);
|
||||
expect((await barTabService.getTabById(tab.id))!.totalInCents, 0);
|
||||
});
|
||||
|
||||
test('refuses to close a tab that changed since the request', () async {
|
||||
final tab = await barTabService.createTab(customerName: 'Alice');
|
||||
await barTabService.addProductToTab(tabId: tab.id, product: _beer);
|
||||
|
||||
Reference in New Issue
Block a user