|
| 1 | +from unittest import mock |
1 | 2 | import pytest |
2 | 3 | from allocation.adapters import repository |
| 4 | +from allocation.domain.model import OutOfStock |
3 | 5 | from allocation.service_layer import services, unit_of_work |
4 | 6 |
|
5 | 7 |
|
@@ -32,7 +34,7 @@ def rollback(self): |
32 | 34 | def test_add_batch_for_new_product(): |
33 | 35 | uow = FakeUnitOfWork() |
34 | 36 | services.add_batch("b1", "CRUNCHY-ARMCHAIR", 100, None, uow) |
35 | | - assert uow.products.get('CRUNCHY-ARMCHAIR') is not None |
| 37 | + assert uow.products.get("CRUNCHY-ARMCHAIR") is not None |
36 | 38 | assert uow.committed |
37 | 39 |
|
38 | 40 |
|
@@ -63,3 +65,16 @@ def test_allocate_commits(): |
63 | 65 | services.add_batch("b1", "OMINOUS-MIRROR", 100, None, uow) |
64 | 66 | services.allocate("o1", "OMINOUS-MIRROR", 10, uow) |
65 | 67 | assert uow.committed |
| 68 | + |
| 69 | + |
| 70 | +def test_sends_email_on_out_of_stock_error(): |
| 71 | + uow = FakeUnitOfWork() |
| 72 | + services.add_batch("b1", "POPULAR-CURTAINS", 9, None, uow) |
| 73 | + |
| 74 | + with mock.patch("allocation.adapters.email.send_mail") as mock_send_mail: |
| 75 | + with pytest.raises(OutOfStock): |
| 76 | + services.allocate("o1", "POPULAR-CURTAINS", 10, uow) |
| 77 | + assert mock_send_mail.call_args == mock.call( |
| 78 | + "stock@made.com", |
| 79 | + f"Out of stock for POPULAR-CURTAINS", |
| 80 | + ) |
0 commit comments