tests/integration/pubsub.lua

1
local harness = require "harness";
2
local verse = harness.verse;
3
local service = "pubsub."..harness.domain;
4
 
5
return {
6
	{ "creates a node, subscribes, publishes and receives the event", function (t)
7
		local node_name = "verse-test-"..os.time();
8
		-- alice is a server admin in the test config, so may create nodes
9
		t.client("alice", function (c)
10
			local node = c.pubsub(service, node_name);
11
			node:hook(t.cb(function (event)
12
				assert(event.from == service, "unexpected event source: "..tostring(event.from));
13
				assert(event.item.tags[1].name == "payload", "unexpected payload");
14
				assert(event.item.tags[1]:get_text() == "hello", "unexpected payload text");
15
				node:delete(nil, t.cb(function (reply)
16
					assert(reply.attr.type == "result", "node delete failed");
17
					t.done();
18
				end));
19
			end));
20
			node:create(nil, t.cb(function (reply)
21
				assert(reply.attr.type == "result", "node create failed: "..tostring(select(2, reply:get_error())));
22
				node:subscribe(nil, nil, t.cb(function (reply)
23
					assert(reply.attr.type == "result", "subscribe failed: "..tostring(select(2, reply:get_error())));
24
					node:publish(nil, nil, verse.stanza("payload", { xmlns = "urn:example:payload" }):text("hello"), t.cb(function (reply)
25
						assert(reply.attr.type == "result", "publish failed: "..tostring(select(2, reply:get_error())));
26
					end));
27
				end));
28
			end));
29
		end, { plugins = { "pubsub" } });
30
	end };
31
};