|
| 1 | +from modules.catalog.application.command import CreateListingDraftCommand |
| 2 | +from seedwork.domain.value_objects import Money |
| 3 | + |
| 4 | + |
| 5 | +def test_empty_catalog_list(api_client): |
| 6 | + response = api_client.get("/catalog") |
| 7 | + assert response.status_code == 200 |
| 8 | + assert response.json() == {"data": []} |
| 9 | + |
| 10 | + |
| 11 | +def test_catalog_list_with_one_item(api, api_client): |
| 12 | + # arrange |
| 13 | + catalog_module = api.container.catalog_module() |
| 14 | + with catalog_module.unit_of_work(): |
| 15 | + command_result = catalog_module.execute_command( |
| 16 | + CreateListingDraftCommand( |
| 17 | + title="Foo", description="Bar", ask_price=Money(10), seller_id="abcd" |
| 18 | + ) |
| 19 | + ) |
| 20 | + |
| 21 | + # act |
| 22 | + response = api_client.get("/catalog") |
| 23 | + |
| 24 | + # assert |
| 25 | + assert response.status_code == 200 |
| 26 | + response_data = response.json()["data"] |
| 27 | + assert len(response_data) == 1 |
| 28 | + assert response.json() == { |
| 29 | + "data": [ |
| 30 | + { |
| 31 | + "id": str(command_result.result), |
| 32 | + "title": "Foo", |
| 33 | + "description": "Bar", |
| 34 | + "ask_price_amount": 10.0, |
| 35 | + "ask_price_currency": "USD", |
| 36 | + } |
| 37 | + ] |
| 38 | + } |
| 39 | + |
| 40 | + |
| 41 | +def test_catalog_list_with_two_items(api, api_client): |
| 42 | + # arrange |
| 43 | + catalog_module = api.container.catalog_module() |
| 44 | + with catalog_module.unit_of_work(): |
| 45 | + catalog_module.execute_command( |
| 46 | + CreateListingDraftCommand( |
| 47 | + title="Foo #1", description="Bar", ask_price=Money(10), seller_id="abcd" |
| 48 | + ) |
| 49 | + ) |
| 50 | + catalog_module.execute_command( |
| 51 | + CreateListingDraftCommand( |
| 52 | + title="Foo #2", description="Bar", ask_price=Money(10), seller_id="abcd" |
| 53 | + ) |
| 54 | + ) |
| 55 | + |
| 56 | + # act |
| 57 | + response = api_client.get("/catalog") |
| 58 | + |
| 59 | + # assert |
| 60 | + assert response.status_code == 200 |
| 61 | + response_data = response.json()["data"] |
| 62 | + assert len(response_data) == 2 |
0 commit comments