feat: add delete post tests
This commit is contained in:
parent
b0be06580a
commit
01764c155e
4 changed files with 111 additions and 11 deletions
|
|
@ -98,6 +98,38 @@
|
|||
"28c96b6e80681c18a690e0e0dc6ca4e72b9d291d1d2576bc8949a07bb4bee225",
|
||||
true,
|
||||
""
|
||||
],
|
||||
"delete_post01": [
|
||||
"EVENT",
|
||||
{
|
||||
"kind": 5,
|
||||
"content": "deleted",
|
||||
"tags": [
|
||||
[
|
||||
"e",
|
||||
"05741bda9079cdf66f3be977a4d31287366470d1337b1aeb09506da4fbf7cd85"
|
||||
],
|
||||
[
|
||||
"e",
|
||||
"mock-id",
|
||||
""
|
||||
],
|
||||
[
|
||||
"e",
|
||||
"bb34749ffd3eb0e393e54cc90b61a7dd5f34108d4931467861d20281c0b7daea"
|
||||
]
|
||||
],
|
||||
"created_at": 1675427798,
|
||||
"pubkey": "0b29ecc73ba400e5b4bd1e4cb0d8f524e9958345749197ca21c8da38d0622816",
|
||||
"id": "2751f2ee0f894268c61300c5b1a1a434f49a33a467a6f4516f10a82a1848f093",
|
||||
"sig": "8e972ba7f1ce9d11ba5d49fdd48db4a92ea999790eb604e6a7f01868a26a70a8e96e1f9e104d8f77a5aa7f29e94119e33117b4cc8a5ff9e50ec8c23eeccd94e9"
|
||||
}
|
||||
],
|
||||
"delete_post01_response": [
|
||||
"ok",
|
||||
"2751f2ee0f894268c61300c5b1a1a434f49a33a467a6f4516f10a82a1848f093",
|
||||
true,
|
||||
""
|
||||
]
|
||||
},
|
||||
"bob": {
|
||||
|
|
@ -254,6 +286,19 @@
|
|||
],
|
||||
"limit": 400
|
||||
}
|
||||
],
|
||||
"subscribe_to_delete_from_alice": [
|
||||
"REQ",
|
||||
"notifications:delete",
|
||||
{
|
||||
"kinds": [
|
||||
5
|
||||
],
|
||||
"authors": [
|
||||
"0b29ecc73ba400e5b4bd1e4cb0d8f524e9958345749197ca21c8da38d0622816"
|
||||
],
|
||||
"limit": 400
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import asyncio
|
||||
from json import dumps
|
||||
from json import dumps, loads
|
||||
|
||||
import pytest
|
||||
from fastapi import WebSocket
|
||||
|
|
@ -56,6 +56,9 @@ async def test_alice_and_bob():
|
|||
|
||||
await alice_writes_to_bob(ws_alice, ws_bob)
|
||||
|
||||
await alice_deletes_post01__bob_is_notified(ws_alice, ws_bob)
|
||||
|
||||
|
||||
def init_clients():
|
||||
client_manager = NostrClientManager()
|
||||
|
||||
|
|
@ -230,7 +233,7 @@ async def bob_writes_to_alice(ws_alice: MockWebSocket, ws_bob: MockWebSocket):
|
|||
), "Alice: Wrong direct message received"
|
||||
|
||||
|
||||
async def alice_writes_to_bob(ws_alice, ws_bob):
|
||||
async def alice_writes_to_bob(ws_alice: MockWebSocket, ws_bob: MockWebSocket):
|
||||
ws_alice.sent_messages.clear()
|
||||
ws_bob.sent_messages.clear()
|
||||
|
||||
|
|
@ -262,3 +265,46 @@ async def alice_writes_to_bob(ws_alice, ws_bob):
|
|||
assert ws_bob.sent_messages[1] == dumps(
|
||||
["EOSE", "notifications:d685447c43c7c18dbbea61923cf0b63e1ab46bed"]
|
||||
), "Bob: Received all stored events"
|
||||
|
||||
async def alice_deletes_post01__bob_is_notified(ws_alice: MockWebSocket, ws_bob:MockWebSocket):
|
||||
ws_bob.sent_messages.clear()
|
||||
await ws_bob.wire_mock_data(bob["request_posts_alice"])
|
||||
await asyncio.sleep(0.1)
|
||||
assert (
|
||||
len(ws_bob.sent_messages) == 3
|
||||
), "Bob: Expected two posts from Alice plus and EOSE"
|
||||
|
||||
ws_alice.sent_messages.clear()
|
||||
ws_bob.sent_messages.clear()
|
||||
|
||||
await ws_bob.wire_mock_data(bob["subscribe_to_delete_from_alice"])
|
||||
await asyncio.sleep(0.1)
|
||||
await ws_alice.wire_mock_data(alice["delete_post01"])
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
assert (
|
||||
len(ws_alice.sent_messages) == 1
|
||||
), "Alice: Expected confirmation for delete post01"
|
||||
assert ws_alice.sent_messages[0] == dumps(
|
||||
alice["delete_post01_response"]
|
||||
), "Alice: Wrong confirmation for delete post01"
|
||||
|
||||
assert len(ws_bob.sent_messages) == 2, "Bob: Expects 2 messages for delete post01"
|
||||
assert ws_bob.sent_messages[0] == dumps(
|
||||
["EOSE", "notifications:delete"]
|
||||
), "Bob: Expect no delete notification on subscribe"
|
||||
assert loads(ws_bob.sent_messages[1]) == [
|
||||
"EVENT",
|
||||
"notifications:delete",
|
||||
alice["delete_post01"][1],
|
||||
], "Bob: Expect delete notification later on"
|
||||
|
||||
ws_bob.sent_messages.clear()
|
||||
await ws_bob.wire_mock_data(bob["request_posts_alice"])
|
||||
await asyncio.sleep(0.1)
|
||||
assert (
|
||||
len(ws_bob.sent_messages) == 2
|
||||
), "Bob: Expected one posts from Alice plus and EOSE"
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue