Skip to content

Commit dc20429

Browse files
committed
test and Product change to emit event [model_emits_allocated_event]
1 parent 1f92ca2 commit dc20429

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/allocation/model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def allocate(self, line: OrderLine) -> str:
2020
)
2121
batch.allocate(line)
2222
self.version_number += 1
23+
self.events.append(events.Allocated(
24+
orderid=line.orderid, sku=line.sku, qty=line.qty,
25+
batchref=batch.reference,
26+
))
2327
return batch.reference
2428
except StopIteration:
2529
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
@@ -41,6 +41,17 @@ def test_returns_allocated_batch_ref():
4141
assert allocation == in_stock_batch.reference
4242

4343

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

0 commit comments

Comments
 (0)