Skip to content

Commit

Permalink
test: fix create event test
Browse files Browse the repository at this point in the history
  • Loading branch information
edpyt committed May 2, 2024
1 parent 226374d commit 7c5f9c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions tests/integration/dinners/test_events.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import nats
import pytest
import orjson
from src.application.dinners.events.menu_create_handler import MenuCreateHandler
from src.domain.host.vo.host_id import HostId
from src.domain.menu.menu import Menu


@pytest.mark.skip("Bug with nats client")
async def test_create_event(menu_create_handler: MenuCreateHandler, nats_conn: nats.NATS) -> None:
sub = await nats_conn.subscribe("menu")
menu = Menu.create(
Expand All @@ -16,8 +15,9 @@ async def test_create_event(menu_create_handler: MenuCreateHandler, nats_conn: n
event = menu.events[-1]
menu.clear_domain_events()

await menu_create_handler.handle(event)
await menu_create_handler.handle(event) # NATS publish message
msg = await sub.next_msg()
data = orjson.loads(orjson.loads(msg.data)["data"])

# TODO: add asserts
assert msg
assert data["menu"]["id"]["value"] == str(menu.id.value)
10 changes: 5 additions & 5 deletions tests/integration/fixtures/events.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Generator
from typing import AsyncGenerator, Generator

import nats
import pytest
Expand All @@ -16,20 +16,20 @@ async def create_nats_container() -> Generator[NatsContainer, None, None]:
yield nats_container


@pytest.fixture(name="nats_conn", scope="session")
async def connect_nats(nats_container: NatsContainer) -> nats.NATS:
@pytest.fixture(name="nats_conn")
async def connect_nats(nats_container: NatsContainer) -> AsyncGenerator[nats.NATS, None]:
conn_url = nats_container.nats_uri()
nats_conn = await nats.connect(conn_url)
yield nats_conn
await nats_conn.close()


@pytest.fixture(name="message_broker", scope="session")
@pytest.fixture(name="message_broker")
async def create_nats_message_broker(nats_conn: nats.NATS) -> MessageBroker:
return MessageBrokerImpl(nats_conn)


@pytest.fixture(name="event_bus", scope="session")
@pytest.fixture(name="event_bus")
def create_event_bus(message_broker: MessageBroker) -> EventBus:
return EventBusImpl(message_broker)

Expand Down

0 comments on commit 7c5f9c3

Please sign in to comment.