Files
movim-rs/tests/e2e/e2e_muc.py
T
2026-10-24 14:03:52 +07:00

71 lines
3.3 KiB
Python

import uuid
"""MUC end-to-end test."""
import asyncio, json, time
from e2e import Client
async def main():
alice = Client("alice@localhost", "alicepass")
bob = Client("bob@localhost", "bobpass")
await alice.login()
await bob.login()
for c in (alice, bob):
await c.call("Chat", "ajaxInit")
await c.call("Rooms", "ajaxHttpGet")
room = f"test{int(time.time())}@conference.localhost"
form = {
"jid": {"value": room},
"name": {"value": "Test room"},
"nick": {"value": "alice"},
"type": {"value": "groupchat"},
"autojoin": {"value": True},
"pinned": {"value": False},
"notify": {"value": "always"},
}
await alice.call("RoomsUtils", "ajaxAddCreate", [form])
await alice.recv_until(lambda m: m.get("func") == "Rooms.setRoom" and "connected" in m["p"][1] and room.split("@")[0] in m["p"][1], timeout=20)
print("room created and joined:", room)
# Invite Bob
await alice.call("RoomsUtils", "ajaxInvite", [{"to": {"value": room}, "invite": {"value": "bob@localhost"}}])
m = await bob.recv_until(lambda m: m.get("func") == "Chat.appendMessagesWrapper" and "invitation" in json.dumps(m), timeout=10)
print("bob got the invitation")
# Bob joins and adds the bookmark
await bob.call("RoomsUtils", "ajaxAddConfirm", [{
"jid": {"value": room}, "name": {"value": "Test room"}, "nick": {"value": "bob"},
"autojoin": {"value": True}, "pinned": {"value": True}, "notify": {"value": "on-mention"},
}])
await bob.recv_until(lambda m: m.get("func") == "Rooms.setRoom" and "connected" in m["p"][1], timeout=20)
print("bob joined")
# Alice sends a message, Bob opens the room
await alice.call("Chat", "ajaxGetRoom", [room])
await alice.recv_until(lambda m: m.get("func") == "Chat.setSpecificElements")
r = alice.ajax("Chat", "ajaxHttpDaemonSendMessage", [str(uuid.uuid4()), room, "Hello bob in the room", True], daemon=True)
m = await alice.recv_until(lambda m: m.get("func") == "Chat.appendMessagesWrapper" and "Hello bob in the room" in json.dumps(m))
msg = list(list(m["p"][0].values())[0].values())[0]
print("alice sees her reflected MUC message, mine =", msg.get("mine"), "stanzaid =", msg.get("stanzaid"))
m = await bob.recv_until(lambda m: m.get("func") == "Chat.appendMessagesWrapper" and "Hello bob in the room" in json.dumps(m))
print("bob receives the MUC message")
m = await bob.recv_until(lambda m: m.get("func") == "Notif.desktop", seen=True, timeout=5)
print("bob notified (mention)")
# Bob opens the room: history from the DB
await bob.call("Chat", "ajaxGetRoom", [room])
m = await bob.recv_until(lambda m: m.get("func") == "Chat.appendMessagesWrapper" and "Hello bob in the room" in json.dumps(m))
await bob.call("Chat", "ajaxHttpGetPresences", [room])
m = await bob.recv_until(lambda m: m.get("func") == "MovimTpl.fill" and m["p"][0].endswith("-nav"))
print("bob sees the members:", "alice" in m["p"][1] and "bob" in m["p"][1])
# Reaction in the MUC
r = bob.ajax("Chat", "ajaxHttpDaemonSendReaction", [msg["mid"] if msg.get("mid") else 0, "❤️"], daemon=True)
# Subject
await alice.call("RoomsUtils", "ajaxSetSubject", [room, {"subject": {"value": "Our subject"}}])
print("ALL OK")
asyncio.run(main())