Skip to content

Commit e34840f

Browse files
committed
test and Product change to emit event [model_emits_allocated_event]
1 parent 8fd9276 commit e34840f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/allocation/domain/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
@@ -42,6 +42,17 @@ def test_returns_allocated_batch_ref():
4242
assert allocation == in_stock_batch.reference
4343

4444

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

0 commit comments

Comments
 (0)