import uuid

import pytest

from ..factory import Event


@pytest.mark.asyncio
async def test_sanity_single_event(factory):
    data = {"value": uuid.uuid4().hex}
    event = Event(eventType="singleEvent", data=data)
    stream = uuid.uuid4().hex

    await factory.publish([event], stream)
    [event] = await factory.fetchall(stream)

    assert event["data"] == data


@pytest.mark.asyncio
async def test_sanity_multiple_events(factory):
    source_events = [
        Event(eventId=str(uuid.uuid4()), eventType="singleEvent", data={"value": i})
        for i in range(73)
    ]
    source_extract = [(e.eventId, e.data["value"]) for e in source_events]
    stream = uuid.uuid4().hex

    await factory.publish(source_events, stream)
    events = await factory.fetchall(stream)
    extracts = [(e["eventId"], e["data"]["value"]) for e in events]

    assert len(events) == 73
    assert extracts == source_extract

import uuid

import pytest

from ..factory import Event


@pytest.mark.asyncio
async def test_sanity_single_event(factory):
    data = {"value": uuid.uuid4().hex}
    event = Event(eventType="singleEvent", data=data)
    stream = uuid.uuid4().hex

    await factory.publish([event], stream)
    [event] = await factory.fetchall(stream)

    assert event["data"] == data


@pytest.mark.asyncio
async def test_sanity_multiple_events(factory):
    source_events = [
        Event(eventId=str(uuid.uuid4()), eventType="singleEvent", data={"value": i})
        for i in range(73)
    ]
    source_extract = [(e.eventId, e.data["value"]) for e in source_events]
    stream = uuid.uuid4().hex

    await factory.publish(source_events, stream)
    events = await factory.fetchall(stream)
    extracts = [(e["eventId"], e["data"]["value"]) for e in events]

    assert len(events) == 73
    assert extracts == source_extract
