Annotate

spec/util_pubsub_spec.lua @ 9260:0fc6ffc57dc0

mod_vcard_legacy: Announce feature on bare JID per XEP
author Kim Alvefur <zash@zash.se>
date Sat, 01 Sep 2018 22:06:25 +0200
parent 9209:69e17edf8796
child 9451:db82b096b842
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8564
fd41dc4a78e9 util_pubsub_spec: Move util.pubsub import into a setup block
Kim Alvefur <zash@zash.se>
parents: 8558
diff changeset
1 local pubsub;
fd41dc4a78e9 util_pubsub_spec: Move util.pubsub import into a setup block
Kim Alvefur <zash@zash.se>
parents: 8558
diff changeset
2 setup(function ()
fd41dc4a78e9 util_pubsub_spec: Move util.pubsub import into a setup block
Kim Alvefur <zash@zash.se>
parents: 8558
diff changeset
3 pubsub = require "util.pubsub";
fd41dc4a78e9 util_pubsub_spec: Move util.pubsub import into a setup block
Kim Alvefur <zash@zash.se>
parents: 8558
diff changeset
4 end);
fd41dc4a78e9 util_pubsub_spec: Move util.pubsub import into a setup block
Kim Alvefur <zash@zash.se>
parents: 8558
diff changeset
5
9176
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
6 --[[TODO:
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
7 Retract
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
8 Purge
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
9 auto-create/auto-subscribe
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
10 Item store/node store
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
11 resize on max_items change
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
12 service creation config provides alternative node_defaults
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
13 get subscriptions
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
14 ]]
1068f9b82e2b util.pubsub tests: Add TODO
Matthew Wild <mwild1@gmail.com>
parents: 9175
diff changeset
15
8558
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 describe("util.pubsub", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 describe("simple node creation and deletion", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 -- Roughly a port of scansion/scripts/pubsub_createdelete.scs
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 local service = pubsub.new();
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 describe("#create", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 it("creates a new node", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 assert.truthy(service:create("princely_musings", true));
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 it("fails to create the same node again", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 assert.falsy(service:create("princely_musings", true));
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 describe("#delete", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 it("deletes the node", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 assert.truthy(service:delete("princely_musings", true));
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 it("can't delete an already deleted node", function ()
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 assert.falsy(service:delete("princely_musings", true));
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 end);
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 end);
8647
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
41
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
42 describe("simple publishing", function ()
9173
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
43 local notified;
9178
f226b7b5486b util.pubsub: Silence warnings in tests [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9176
diff changeset
44 local broadcaster = spy.new(function (notif_type, node_name, subscribers, item) -- luacheck: ignore 212
9173
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
45 notified = subscribers;
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
46 end);
8817
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
47 local service = pubsub.new({
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
48 broadcaster = broadcaster;
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
49 });
8647
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
50
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
51 it("creates a node", function ()
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
52 assert.truthy(service:create("node", true));
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
53 end);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
54
8817
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
55 it("lets someone subscribe", function ()
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
56 assert.truthy(service:add_subscription("node", true, "someone"));
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
57 end);
9a3066a580ad spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents: 8647
diff changeset
58
8647
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
59 it("publishes an item", function ()
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
60 assert.truthy(service:publish("node", true, "1", "item 1"));
9173
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
61 assert.truthy(notified["someone"]);
8647
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
62 end);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
63
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
64 it("called the broadcaster", function ()
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
65 assert.spy(broadcaster).was_called();
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
66 end);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
67
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
68 it("should return one item", function ()
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
69 local ok, ret = service:get_items("node", true);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
70 assert.truthy(ok);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
71 assert.same({ "1", ["1"] = "item 1" }, ret);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
72 end);
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
73
9173
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
74 it("lets someone unsubscribe", function ()
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
75 assert.truthy(service:remove_subscription("node", true, "someone"));
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
76 end);
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
77
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
78 it("does not send notifications after subscription is removed", function ()
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
79 assert.truthy(service:publish("node", true, "1", "item 1"));
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
80 assert.is_nil(notified["someone"]);
c53663e13b51 util.pubsub tests: Extend publishing tests to check for correct notification behaviour on subscribe/unsubscribe
Matthew Wild <mwild1@gmail.com>
parents: 9171
diff changeset
81 end);
8647
638ff2ad98e6 util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents: 8564
diff changeset
82 end);
9004
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
83
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
84 describe("#issue1082", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
85 local service = pubsub.new();
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
86
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
87 it("creates a node with max_items = 1", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
88 assert.truthy(service:create("node", true, { max_items = 1 }));
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
89 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
90
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
91 it("changes max_items to 2", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
92 assert.truthy(service:set_node_config("node", true, { max_items = 2 }));
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
93 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
94
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
95 it("publishes one item", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
96 assert.truthy(service:publish("node", true, "1", "item 1"));
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
97 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
98
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
99 it("should return one item", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
100 local ok, ret = service:get_items("node", true);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
101 assert.truthy(ok);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
102 assert.same({ "1", ["1"] = "item 1" }, ret);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
103 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
104
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
105 it("publishes another item", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
106 assert.truthy(service:publish("node", true, "2", "item 2"));
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
107 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
108
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
109 it("should return two items", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
110 local ok, ret = service:get_items("node", true);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
111 assert.truthy(ok);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
112 assert.same({
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
113 "2",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
114 "1",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
115 ["1"] = "item 1",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
116 ["2"] = "item 2",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
117 }, ret);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
118 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
119
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
120 it("publishes yet another item", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
121 assert.truthy(service:publish("node", true, "3", "item 3"));
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
122 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
123
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
124 it("should still return only two items", function ()
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
125 local ok, ret = service:get_items("node", true);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
126 assert.truthy(ok);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
127 assert.same({
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
128 "3",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
129 "2",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
130 ["2"] = "item 2",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
131 ["3"] = "item 3",
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
132 }, ret);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
133 end);
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
134
50a0f405e6c9 util_pubsub_spec: Add test for #1082
Kim Alvefur <zash@zash.se>
parents: 8817
diff changeset
135 end);
9169
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
136
9174
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
137 describe("node config", function ()
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
138 local service;
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
139 before_each(function ()
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
140 service = pubsub.new();
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
141 service:create("test", true);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
142 end);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
143 it("access is forbidden for unaffiliated entities", function ()
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
144 local ok, err = service:get_node_config("test", "stranger");
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
145 assert.is_falsy(ok);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
146 assert.equals("forbidden", err);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
147 end);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
148 it("returns an error for nodes that do not exist", function ()
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
149 local ok, err = service:get_node_config("nonexistent", true);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
150 assert.is_falsy(ok);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
151 assert.equals("item-not-found", err);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
152 end);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
153 end);
160032d55ff1 util.pubsub tests: Add initial node config tests
Matthew Wild <mwild1@gmail.com>
parents: 9173
diff changeset
154
9169
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
155 describe("access model", function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
156 describe("open", function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
157 local service;
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
158 before_each(function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
159 service = pubsub.new();
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
160 -- Do not supply any config, 'open' should be default
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
161 service:create("test", true);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
162 end);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
163 it("should be the default", function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
164 local ok, config = service:get_node_config("test", true);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
165 assert.equal("open", config.access_model);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
166 end);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
167 it("should allow anyone to subscribe", function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
168 local ok = service:add_subscription("test", "stranger", "stranger");
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
169 assert.is_true(ok);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
170 end);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
171 it("should still reject outcast-affiliated entities", function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
172 assert(service:set_affiliation("test", true, "enemy", "outcast"));
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
173 local ok, err = service:add_subscription("test", "enemy", "enemy");
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
174 assert.is_falsy(ok);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
175 assert.equal("forbidden", err);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
176 end);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
177 end);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
178 describe("whitelist", function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
179 local service;
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
180 before_each(function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
181 service = assert(pubsub.new());
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
182 assert.is_true(service:create("test", true, { access_model = "whitelist" }));
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
183 end);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
184 it("should be present in the configuration", function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
185 local ok, config = service:get_node_config("test", true);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
186 assert.equal("whitelist", config.access_model);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
187 end);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
188 it("should not allow anyone to subscribe", function ()
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
189 local ok, err = service:add_subscription("test", "stranger", "stranger");
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
190 assert.is_false(ok);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
191 assert.equals("forbidden", err);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
192 end);
9171
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
193 end);
9175
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
194 describe("change", function ()
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
195 local service;
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
196 before_each(function ()
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
197 service = pubsub.new();
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
198 service:create("test", true, { access_model = "open" });
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
199 end);
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
200 it("affects existing subscriptions", function ()
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
201 do
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
202 local ok = service:add_subscription("test", "stranger", "stranger");
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
203 assert.is_true(ok);
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
204 end
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
205 do
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
206 local ok, sub = service:get_subscription("test", "stranger", "stranger");
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
207 assert.is_true(ok);
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
208 assert.is_true(sub);
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
209 end
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
210 assert(service:set_node_config("test", true, { access_model = "whitelist" }));
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
211 do
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
212 local ok, sub = service:get_subscription("test", "stranger", "stranger");
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
213 assert.is_true(ok);
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
214 assert.is_nil(sub);
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
215 end
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
216 end);
43b6f67aba05 util.pubsub tests: Add tests to confirm new access model is enforced on config change
Matthew Wild <mwild1@gmail.com>
parents: 9174
diff changeset
217 end);
9171
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
218 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
219
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
220 describe("publish model", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
221 describe("publishers", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
222 local service;
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
223 before_each(function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
224 service = pubsub.new();
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
225 -- Do not supply any config, 'publishers' should be default
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
226 service:create("test", true);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
227 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
228 it("should be the default", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
229 local ok, config = service:get_node_config("test", true);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
230 assert.equal("publishers", config.publish_model);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
231 end);
9169
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
232 it("should not allow anyone to publish", function ()
9171
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
233 assert.is_true(service:add_subscription("test", "stranger", "stranger"));
9169
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
234 local ok, err = service:publish("test", "stranger", "item1", "foo");
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
235 assert.is_falsy(ok);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
236 assert.equals("forbidden", err);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
237 end);
9171
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
238 it("should allow publishers to publish", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
239 assert(service:set_affiliation("test", true, "mypublisher", "publisher"));
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
240 local ok, err = service:publish("test", "mypublisher", "item1", "foo");
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
241 assert.is_true(ok);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
242 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
243 it("should allow owners to publish", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
244 assert(service:set_affiliation("test", true, "myowner", "owner"));
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
245 local ok = service:publish("test", "myowner", "item1", "foo");
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
246 assert.is_true(ok);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
247 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
248 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
249 describe("open", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
250 local service;
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
251 before_each(function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
252 service = pubsub.new();
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
253 service:create("test", true, { publish_model = "open" });
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
254 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
255 it("should allow anyone to publish", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
256 local ok = service:publish("test", "stranger", "item1", "foo");
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
257 assert.is_true(ok);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
258 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
259 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
260 describe("subscribers", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
261 local service;
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
262 before_each(function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
263 service = pubsub.new();
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
264 service:create("test", true, { publish_model = "subscribers" });
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
265 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
266 it("should not allow non-subscribers to publish", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
267 local ok, err = service:publish("test", "stranger", "item1", "foo");
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
268 assert.is_falsy(ok);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
269 assert.equals("forbidden", err);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
270 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
271 it("should allow subscribers to publish without an affiliation", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
272 assert.is_true(service:add_subscription("test", "stranger", "stranger"));
9209
69e17edf8796 util.pubsub tests: Fix whitespace
Kim Alvefur <zash@zash.se>
parents: 9208
diff changeset
273 local ok = service:publish("test", "stranger", "item1", "foo");
9171
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
274 assert.is_true(ok);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
275 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
276 it("should allow publishers to publish without a subscription", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
277 assert(service:set_affiliation("test", true, "mypublisher", "publisher"));
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
278 local ok, err = service:publish("test", "mypublisher", "item1", "foo");
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
279 assert.is_true(ok);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
280 end);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
281 it("should allow owners to publish without a subscription", function ()
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
282 assert(service:set_affiliation("test", true, "myowner", "owner"));
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
283 local ok = service:publish("test", "myowner", "item1", "foo");
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
284 assert.is_true(ok);
5f03fe90704f util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
Matthew Wild <mwild1@gmail.com>
parents: 9169
diff changeset
285 end);
9169
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
286 end);
3ec013185c15 util.pubsub tests: Add some initial access model tests (open and whitelist)
Matthew Wild <mwild1@gmail.com>
parents: 9159
diff changeset
287 end);
9206
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
288
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
289 describe("item API", function ()
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
290 local service;
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
291 before_each(function ()
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
292 service = pubsub.new();
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
293 service:create("test", true, { publish_model = "subscribers" });
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
294 end);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
295 describe("get_last_item()", function ()
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
296 it("succeeds with nil on empty nodes", function ()
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
297 local ok, id, item = service:get_last_item("test", true);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
298 assert.is_true(ok);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
299 assert.is_nil(id);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
300 assert.is_nil(item);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
301 end);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
302 it("succeeds and returns the last item", function ()
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
303 service:publish("test", true, "one", "hello world");
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
304 service:publish("test", true, "two", "hello again");
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
305 service:publish("test", true, "three", "hey");
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
306 service:publish("test", true, "one", "bye");
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
307 local ok, id, item = service:get_last_item("test", true);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
308 assert.is_true(ok);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
309 assert.equal("one", id);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
310 assert.equal("bye", item);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
311 end);
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
312 end);
9208
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
313 describe("get_items()", function ()
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
314 it("fails on non-existent nodes", function ()
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
315 local ok, err = service:get_items("no-node", true);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
316 assert.is_falsy(ok);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
317 assert.equal("item-not-found", err);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
318 end);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
319 it("returns no items on an empty node", function ()
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
320 local ok, items = service:get_items("test", true);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
321 assert.is_true(ok);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
322 assert.equal(0, #items);
9209
69e17edf8796 util.pubsub tests: Fix whitespace
Kim Alvefur <zash@zash.se>
parents: 9208
diff changeset
323 assert.is_nil(next(items));
9208
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
324 end);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
325 it("returns no items on an empty node", function ()
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
326 local ok, items = service:get_items("test", true);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
327 assert.is_true(ok);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
328 assert.equal(0, #items);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
329 assert.is_nil((next(items)));
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
330 end);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
331 it("returns all published items", function ()
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
332 service:publish("test", true, "one", "hello world");
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
333 service:publish("test", true, "two", "hello again");
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
334 service:publish("test", true, "three", "hey");
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
335 service:publish("test", true, "one", "bye");
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
336 local ok, items = service:get_items("test", true);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
337 assert.is_true(ok);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
338 assert.same({ "one", "three", "two", two = "hello again", three = "hey", one = "bye" }, items);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
339 end);
d3bb59ec0173 util.pubsub tests: Add tests for get_items()
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
340 end);
9206
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9178
diff changeset
341 end);
8558
5de663cef508 util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
342 end);