Skip to content
This repository was archived by the owner on Aug 8, 2022. It is now read-only.

Commit 7a75df7

Browse files
committed
test and Product change to emit event [model_emits_allocated_event]
1 parent 9bd4a60 commit 7a75df7

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/allocation/domain/model.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ def allocate(self, line: OrderLine) -> str:
1717
batch = next(b for b in sorted(self.batches) if b.can_allocate(line))
1818
batch.allocate(line)
1919
self.version_number += 1
20+
self.events.append(
21+
events.Allocated(
22+
orderid=line.orderid,
23+
sku=line.sku,
24+
qty=line.qty,
25+
batchref=batch.reference,
26+
)
27+
)
2028
return batch.reference
2129
except StopIteration:
2230
self.events.append(events.OutOfStock(line.sku))

tests/unit/test_product.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ def test_returns_allocated_batch_ref():
4343
assert allocation == in_stock_batch.reference
4444

4545

46+
def test_outputs_allocated_event():
47+
batch = Batch("batchref", "RETRO-LAMPSHADE", 100, eta=None)
48+
line = OrderLine("oref", "RETRO-LAMPSHADE", 10)
49+
product = Product(sku="RETRO-LAMPSHADE", batches=[batch])
50+
product.allocate(line)
51+
expected = events.Allocated(
52+
orderid="oref", sku="RETRO-LAMPSHADE", qty=10, batchref=batch.reference
53+
)
54+
assert product.events[-1] == expected
55+
56+
4657
def test_records_out_of_stock_event_if_cannot_allocate():
4758
batch = Batch("batch1", "SMALL-FORK", 10, eta=today)
4859
product = Product(sku="SMALL-FORK", batches=[batch])

0 commit comments

Comments
 (0)