Software /
code /
prosody
Comparison
spec/util_pubsub_spec.lua @ 9173:c53663e13b51
util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 12 Aug 2018 11:34:05 +0100 |
parent | 9171:5f03fe90704f |
child | 9174:160032d55ff1 |
comparison
equal
deleted
inserted
replaced
9172:822e9c5ff4a4 | 9173:c53663e13b51 |
---|---|
28 end); | 28 end); |
29 end); | 29 end); |
30 end); | 30 end); |
31 | 31 |
32 describe("simple publishing", function () | 32 describe("simple publishing", function () |
33 local broadcaster = spy.new(function () end); | 33 local notified; |
34 local broadcaster = spy.new(function (notif_type, node_name, subscribers, item) | |
35 notified = subscribers; | |
36 end); | |
34 local service = pubsub.new({ | 37 local service = pubsub.new({ |
35 broadcaster = broadcaster; | 38 broadcaster = broadcaster; |
36 }); | 39 }); |
37 | 40 |
38 it("creates a node", function () | 41 it("creates a node", function () |
43 assert.truthy(service:add_subscription("node", true, "someone")); | 46 assert.truthy(service:add_subscription("node", true, "someone")); |
44 end); | 47 end); |
45 | 48 |
46 it("publishes an item", function () | 49 it("publishes an item", function () |
47 assert.truthy(service:publish("node", true, "1", "item 1")); | 50 assert.truthy(service:publish("node", true, "1", "item 1")); |
51 assert.truthy(notified["someone"]); | |
48 end); | 52 end); |
49 | 53 |
50 it("called the broadcaster", function () | 54 it("called the broadcaster", function () |
51 assert.spy(broadcaster).was_called(); | 55 assert.spy(broadcaster).was_called(); |
52 end); | 56 end); |
55 local ok, ret = service:get_items("node", true); | 59 local ok, ret = service:get_items("node", true); |
56 assert.truthy(ok); | 60 assert.truthy(ok); |
57 assert.same({ "1", ["1"] = "item 1" }, ret); | 61 assert.same({ "1", ["1"] = "item 1" }, ret); |
58 end); | 62 end); |
59 | 63 |
64 it("lets someone unsubscribe", function () | |
65 assert.truthy(service:remove_subscription("node", true, "someone")); | |
66 end); | |
67 | |
68 it("does not send notifications after subscription is removed", function () | |
69 assert.truthy(service:publish("node", true, "1", "item 1")); | |
70 assert.is_nil(notified["someone"]); | |
71 end); | |
60 end); | 72 end); |
61 | 73 |
62 describe("#issue1082", function () | 74 describe("#issue1082", function () |
63 local service = pubsub.new(); | 75 local service = pubsub.new(); |
64 | 76 |