add tests
This commit is contained in:
+32
-21
@@ -87,21 +87,28 @@ async def test_pagination_has_no_duplicates(client: AsyncClient):
|
||||
chat = await create_chat(client, alice)
|
||||
|
||||
created = [
|
||||
(await _message(client, alice, chat, f"message-{index}")).json() for index in range(5)
|
||||
(await _message(client, alice, chat, f"message-{index}")).json()
|
||||
for index in range(5)
|
||||
]
|
||||
|
||||
page1 = (await client.get(
|
||||
f"/api/v1/chats/{chat['id']}/messages?limit=2",
|
||||
headers=bearer(alice),
|
||||
)).json()
|
||||
page2 = (await client.get(
|
||||
f"/api/v1/chats/{chat['id']}/messages?limit=2&cursor={quote(page1['next_cursor'], safe='')}",
|
||||
headers=bearer(alice),
|
||||
)).json()
|
||||
page3 = (await client.get(
|
||||
f"/api/v1/chats/{chat['id']}/messages?limit=2&cursor={quote(page2['next_cursor'], safe='')}",
|
||||
headers=bearer(alice),
|
||||
)).json()
|
||||
page1 = (
|
||||
await client.get(
|
||||
f"/api/v1/chats/{chat['id']}/messages?limit=2",
|
||||
headers=bearer(alice),
|
||||
)
|
||||
).json()
|
||||
page2 = (
|
||||
await client.get(
|
||||
f"/api/v1/chats/{chat['id']}/messages?limit=2&cursor={quote(page1['next_cursor'], safe='')}",
|
||||
headers=bearer(alice),
|
||||
)
|
||||
).json()
|
||||
page3 = (
|
||||
await client.get(
|
||||
f"/api/v1/chats/{chat['id']}/messages?limit=2&cursor={quote(page2['next_cursor'], safe='')}",
|
||||
headers=bearer(alice),
|
||||
)
|
||||
).json()
|
||||
|
||||
ids = [item["id"] for page in (page1, page2, page3) for item in page["items"]]
|
||||
assert ids == [item["id"] for item in created]
|
||||
@@ -122,10 +129,12 @@ async def test_cursor_cannot_be_used_for_another_chat(client: AsyncClient):
|
||||
await _message(client, alice, chat_b, "b1")
|
||||
await _message(client, alice, chat_b, "b2")
|
||||
|
||||
page = (await client.get(
|
||||
f"/api/v1/chats/{chat_a['id']}/messages?limit=1",
|
||||
headers=bearer(alice),
|
||||
)).json()
|
||||
page = (
|
||||
await client.get(
|
||||
f"/api/v1/chats/{chat_a['id']}/messages?limit=1",
|
||||
headers=bearer(alice),
|
||||
)
|
||||
).json()
|
||||
|
||||
response = await client.get(
|
||||
f"/api/v1/chats/{chat_b['id']}/messages?limit=1&cursor={quote(page['next_cursor'], safe='')}",
|
||||
@@ -205,11 +214,13 @@ async def test_messages_survive_new_login(client: AsyncClient):
|
||||
async def test_history_order_is_created_at_then_id(client: AsyncClient):
|
||||
alice = await create_user(client)
|
||||
chat = await create_chat(client, alice)
|
||||
created = [_message(client, alice, chat, f"m{i}").json() for i in range(10)]
|
||||
created = [(await _message(client, alice, chat, f"m{i}")).json() for i in range(10)]
|
||||
|
||||
listed = (await client.get(
|
||||
f"/api/v1/chats/{chat['id']}/messages?limit=100", headers=bearer(alice)
|
||||
)).json()["items"]
|
||||
listed = (
|
||||
await client.get(
|
||||
f"/api/v1/chats/{chat['id']}/messages?limit=100", headers=bearer(alice)
|
||||
)
|
||||
).json()["items"]
|
||||
|
||||
assert [m["id"] for m in listed] == [m["id"] for m in created]
|
||||
keys = [(m["created_at"], m["id"]) for m in listed]
|
||||
|
||||
Reference in New Issue
Block a user