feat: make server own products
This commit is contained in:
+69
-13
@@ -99,23 +99,79 @@ void main() {
|
||||
expect(row.id, event['id']);
|
||||
});
|
||||
|
||||
test('adding to an existing line keeps that line\'s price', () async {
|
||||
test(
|
||||
'a drink at a new price goes on a new line, with that price',
|
||||
() async {
|
||||
final tab = await openTab('Jan');
|
||||
await service.addProductToTab(tabId: tab.id, product: _cola);
|
||||
await service.addProductToTab(
|
||||
tabId: tab.id,
|
||||
product: _cola.copyWith(priceInCents: 300),
|
||||
);
|
||||
|
||||
final events = await outbox();
|
||||
expect(events.map((event) => event['unitPriceInCents']), [250, 300]);
|
||||
expect(events.map((event) => event['productId']), ['prod-1', 'prod-1']);
|
||||
// A different line, so the server doesn't put it on the old one either
|
||||
expect(events[0]['lineId'], isNot(events[1]['lineId']));
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'+ on a line at an old price sends the new price, on a new line',
|
||||
() async {
|
||||
final tab = await openTab('Jan');
|
||||
await service.addProductToTab(tabId: tab.id, product: _cola);
|
||||
final oldLine = await lineIdOf(tab.id);
|
||||
await (database.update(database.products)
|
||||
..where((row) => row.id.equals('prod-1')))
|
||||
.write(const ProductsCompanion(priceInCents: Value(300)));
|
||||
|
||||
await service.adjustTabItemQuantity(tabItemId: oldLine, delta: 1);
|
||||
|
||||
final added = (await outbox()).last;
|
||||
expect(added['type'], 'line_added');
|
||||
expect(added['unitPriceInCents'], 300);
|
||||
expect(added['quantity'], 1);
|
||||
expect(added['lineId'], isNot(oldLine));
|
||||
},
|
||||
);
|
||||
|
||||
test('a line without a product sends no productId', () async {
|
||||
final tab = await openTab('Jan');
|
||||
await service.addProductToTab(tabId: tab.id, product: _cola);
|
||||
await service.addProductToTab(
|
||||
tabId: tab.id,
|
||||
product: const Product(
|
||||
id: 'prod-1',
|
||||
name: 'Cola',
|
||||
category: 'Drinks',
|
||||
stockQuantity: 100,
|
||||
lowStockThreshold: 10,
|
||||
priceInCents: 300,
|
||||
),
|
||||
// As taken over from the tablet's own tabs: the line has no product
|
||||
await database
|
||||
.into(database.tabItems)
|
||||
.insert(
|
||||
TabItemsCompanion.insert(
|
||||
id: 'seed:${tab.id}:0',
|
||||
tabId: tab.id,
|
||||
productId: '',
|
||||
productName: 'Cola',
|
||||
quantity: 1,
|
||||
unitPriceInCents: 250,
|
||||
createdAt: DateTime.now(),
|
||||
),
|
||||
);
|
||||
|
||||
await service.adjustTabItemQuantity(
|
||||
tabItemId: 'seed:${tab.id}:0',
|
||||
delta: -1,
|
||||
);
|
||||
|
||||
final event = (await outbox()).last;
|
||||
expect(event['type'], 'line_removed');
|
||||
expect(event.containsKey('productId'), isFalse);
|
||||
expect(event['productName'], 'Cola');
|
||||
});
|
||||
|
||||
test('a drink at the same price goes on the same line', () async {
|
||||
final tab = await openTab('Jan');
|
||||
await service.addProductToTab(tabId: tab.id, product: _cola);
|
||||
await service.addProductToTab(tabId: tab.id, product: _cola);
|
||||
|
||||
final events = await outbox();
|
||||
expect(events.map((event) => event['unitPriceInCents']), [250, 250]);
|
||||
expect(events[0]['lineId'], events[1]['lineId']);
|
||||
});
|
||||
|
||||
test('changing a quantity writes the difference', () async {
|
||||
|
||||
Reference in New Issue
Block a user