tests/integration/muc.lua

1
local harness = require "harness";
2
local room_jid = "room@conference."..harness.domain;
3
 
4
return {
5
	{ "joins a room, exchanges messages and leaves", function (t)
6
		t.client("alice", function (alice)
7
			local room = alice:join_room(room_jid, "alice");
8
			alice:hook("groupchat/joined", t.cb(function (joined)
9
				assert(joined == room, "joined a different room");
10
				assert(room.occupants["alice"], "own occupant missing");
11
				t.client("bob", function (bob)
12
					local bob_room = bob:join_room(room_jid, "bob");
13
					bob_room:hook("message", t.cb(function (event)
14
						if not event.body then return; end
15
						assert(event.nick == "alice", "unexpected nick: "..tostring(event.nick));
16
						assert(event.body == "hi room", "unexpected body: "..tostring(event.body));
17
						local left;
18
						room:hook("occupant-left", function (o) left = o.nick; end);
19
						bob_room:leave();
20
						room:hook("occupant-left", t.cb(function ()
21
							assert(left == "bob", "unexpected occupant left: "..tostring(left));
22
							t.done();
23
						end));
24
					end));
25
					bob:hook("groupchat/joined", t.cb(function ()
26
						assert(bob_room.occupants["alice"], "alice not visible to bob");
27
						room:send_message("hi room");
28
					end));
29
				end, { plugins = { "groupchat" } });
30
			end));
31
		end, { plugins = { "groupchat" } });
32
	end };
33
 
34
	{ "sees subject changes", function (t)
35
		t.client("alice", function (alice)
36
			local room = alice:join_room(room_jid, "alice");
37
			room:hook("subject-changed", t.cb(function (change)
38
				assert(change.to == "Testing", "unexpected subject: "..tostring(change.to));
39
				t.done();
40
			end));
41
			alice:hook("groupchat/joined", function ()
42
				room:set_subject("Testing");
43
			end);
44
		end, { plugins = { "groupchat" } });
45
	end };
46
};