Software /
code /
prosody
Annotate
spec/util_pubsub_spec.lua @ 8862:900dff5ef498
util.dataforms: Add initial tests
This covers basic form generation, that the fields have the correct
attributes, children and text content.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 02 Jun 2018 19:47:09 +0200 |
parent | 8817:9a3066a580ad |
child | 9004:50a0f405e6c9 |
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 |
8558
5de663cef508
util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 describe("util.pubsub", function () |
5de663cef508
util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 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
|
8 -- 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
|
9 local service = pubsub.new(); |
5de663cef508
util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 |
5de663cef508
util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 describe("#create", function () |
5de663cef508
util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 it("creates a new node", function () |
5de663cef508
util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 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
|
14 end); |
5de663cef508
util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 |
5de663cef508
util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 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
|
17 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
|
18 end); |
5de663cef508
util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 end); |
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("#delete", function () |
5de663cef508
util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 it("deletes the node", function () |
5de663cef508
util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 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
|
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("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
|
27 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
|
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 end); |
8647
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
31 |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
32 describe("simple publishing", function () |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
33 local broadcaster = spy.new(function () end); |
8817
9a3066a580ad
spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents:
8647
diff
changeset
|
34 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
|
35 broadcaster = broadcaster; |
9a3066a580ad
spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents:
8647
diff
changeset
|
36 capabilities = { |
9a3066a580ad
spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents:
8647
diff
changeset
|
37 none = { |
9a3066a580ad
spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents:
8647
diff
changeset
|
38 subscribe = true; |
9a3066a580ad
spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents:
8647
diff
changeset
|
39 be_subscribed = true; |
9a3066a580ad
spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents:
8647
diff
changeset
|
40 }; |
9a3066a580ad
spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents:
8647
diff
changeset
|
41 } |
9a3066a580ad
spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents:
8647
diff
changeset
|
42 }); |
8647
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
43 |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
44 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
|
45 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
|
46 end); |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
47 |
8817
9a3066a580ad
spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents:
8647
diff
changeset
|
48 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
|
49 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
|
50 end); |
9a3066a580ad
spec/util_pubsub: Test whether someone can subscribe to a node
Kim Alvefur <zash@zash.se>
parents:
8647
diff
changeset
|
51 |
8647
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
52 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
|
53 assert.truthy(service:publish("node", true, "1", "item 1")); |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
54 end); |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
55 |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
56 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
|
57 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
|
58 end); |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
59 |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
60 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
|
61 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
|
62 assert.truthy(ok); |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
63 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
|
64 end); |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
65 |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
66 end); |
8558
5de663cef508
util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 end); |