Diff

spec/util_pubsub_spec.lua @ 8647:638ff2ad98e6

util.pubsub: Add simple test covering publishing and retrieving an item
author Kim Alvefur <zash@zash.se>
date Wed, 21 Mar 2018 17:03:13 +0100
parent 8564:fd41dc4a78e9
child 8817:9a3066a580ad
line wrap: on
line diff
--- a/spec/util_pubsub_spec.lua	Wed Mar 21 23:20:59 2018 +0100
+++ b/spec/util_pubsub_spec.lua	Wed Mar 21 17:03:13 2018 +0100
@@ -28,4 +28,28 @@
 			end);
 		end);
 	end);
+
+	describe("simple publishing", function ()
+		local broadcaster = spy.new(function () end);
+		local service = pubsub.new({ broadcaster = broadcaster; });
+
+		it("creates a node", function ()
+			assert.truthy(service:create("node", true));
+		end);
+
+		it("publishes an item", function ()
+			assert.truthy(service:publish("node", true, "1", "item 1"));
+		end);
+
+		it("called the broadcaster", function ()
+			assert.spy(broadcaster).was_called();
+		end);
+
+		it("should return one item", function ()
+			local ok, ret = service:get_items("node", true);
+			assert.truthy(ok);
+			assert.same({ "1", ["1"] = "item 1" }, ret);
+		end);
+
+	end);
 end);