# HG changeset patch # User Kim Alvefur # Date 1577321534 -3600 # Node ID d960c703e6b3c346f0f292ad013896e6af2e1bb3 # Parent cfeb0077c9e97144a862c606c77589a3acc826d0 util.pubsub: Cover subscription filter in a partial test I'm not sure I understand spies well enough to test that the arguments and return values are as expected. Better than nothing at least. diff -r cfeb0077c9e9 -r d960c703e6b3 spec/util_pubsub_spec.lua --- a/spec/util_pubsub_spec.lua Sat Dec 28 06:18:58 2019 +0100 +++ b/spec/util_pubsub_spec.lua Thu Dec 26 01:52:14 2019 +0100 @@ -483,4 +483,30 @@ end); + describe("subscriber filter", function () + it("works", function () + local filter = spy.new(function (subs) + return {["modified"] = true}; + end); + local broadcaster = spy.new(function (notif_type, node_name, subscribers, item) -- luacheck: ignore 212 + end); + local service = pubsub.new({ + subscriber_filter = filter; + broadcaster = broadcaster; + }); + + local ok = service:create("node", true); + assert.truthy(ok); + + local ok = service:add_subscription("node", true, "someone"); + assert.truthy(ok); + + local ok = service:publish("node", true, "1", "item"); + assert.truthy(ok); + -- TODO how to match table arguments? + assert.spy(filter).was_called(); + assert.spy(broadcaster).was_called(); + end); + end); + end);