Software /
code /
prosody
Annotate
spec/util_pubsub_spec.lua @ 8816:0f9d5cfa84f9
util.pubsub: Also check for affiliation set on bare JID
This fixes eg publishing from a full JID when the affiliation has been
set on the bare JID, as would be common in XMPP.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 22 May 2018 01:32:44 +0200 |
parent | 8647:638ff2ad98e6 |
child | 8817:9a3066a580ad |
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); |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
34 local service = pubsub.new({ broadcaster = broadcaster; }); |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
35 |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
36 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
|
37 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
|
38 end); |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
39 |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
40 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
|
41 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
|
42 end); |
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("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
|
45 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
|
46 end); |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
47 |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
48 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
|
49 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
|
50 assert.truthy(ok); |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
51 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
|
52 end); |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
53 |
638ff2ad98e6
util.pubsub: Add simple test covering publishing and retrieving an item
Kim Alvefur <zash@zash.se>
parents:
8564
diff
changeset
|
54 end); |
8558
5de663cef508
util_pubsub_spec: Beginnings of tests for util.pubsub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 end); |