From 8c69bdf87b0afd78c4384b07b538f17b7773f299 Mon Sep 17 00:00:00 2001 From: SX <50966843+S-S-X@users.noreply.github.com> Date: Mon, 1 Jan 2024 18:55:04 +0200 Subject: [PATCH] Some more tests --- spec/plugin_acl_spec.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/plugin_acl_spec.lua b/spec/plugin_acl_spec.lua index 0bb7eb6..cace4ca 100644 --- a/spec/plugin_acl_spec.lua +++ b/spec/plugin_acl_spec.lua @@ -32,6 +32,7 @@ describe("ACL", function() beerchat.channels["acl-read-role"] = { owner = "SX", color = beerchat.default_channel_color } beerchat.channels["acl-update-role"] = { owner = "SX", color = beerchat.default_channel_color } beerchat.channels["acl-delete-role"] = { owner = "SX", color = beerchat.default_channel_color } + beerchat.channels["acl-chat"] = { owner = "SX", color = beerchat.default_channel_color } end) before_each(function() @@ -112,4 +113,27 @@ describe("ACL", function() assert.spy(minetest.chat_send_player).called_with("SX", M("emoved.+elete")) end) + it("read role allows reading messages", function() + beerchat.set_player_channel("SX", "acl-chat") + beerchat.set_player_channel("Sam", "acl-chat") + SX:send_chat_message("/channel_acl #acl-chat Sam read") + spy.on(minetest, "chat_send_player") + SX:send_chat_message("Test message") + -- Channel message allowed and delivered + assert.spy(minetest.chat_send_player).called_with("Sam", M("Test message")) + assert.spy(minetest.chat_send_player).called_with("SX", M("Test message")) + end) + + it("read role disallows sending messages", function() + beerchat.set_player_channel("SX", "acl-chat") + beerchat.set_player_channel("Sam", "acl-chat") + SX:send_chat_message("/channel_acl #acl-chat Sam read") + spy.on(minetest, "chat_send_player") + Sam:send_chat_message("Test message") + -- Channel message disallowed and player informed + assert.spy(minetest.chat_send_player).not_called_with("SX", ANY) + assert.spy(minetest.chat_send_player).not_called_with("Sam", M("Test message")) + assert.spy(minetest.chat_send_player).called_with("Sam", ANY) + end) + end)