Skip to content

Commit 5b48287

Browse files
committed
Merge branch 'develop'
2 parents 6ffd417 + 82de8de commit 5b48287

28 files changed

+1069
-304
lines changed

.specs/Classes/Data/MLDB.spec.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ loadfile(".specs/AddonLoader.lua")(nil, nil, addon).LoadArray {
2424
"Classes/Utils/Item.lua",
2525
[[Utils\Utils.lua]],
2626
[[Classes\Data\Player.lua]],
27+
[[Classes\Services\CommsRestrictions.lua]],
2728
[[Classes\Services\Comms.lua]],
2829
[[Classes\Data\MLDB.lua]]
2930
}

.specs/Classes/Data/Player.spec.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ describe("#Player", function()
128128
return orig_GetPlayerInfoByGUID(guid)
129129
end
130130
end)
131+
_G.IsInGuild = spy.new(function() return true end)
131132
end)
132133

133134
it("should handle non-ascii names", function()

.specs/Classes/Services/Comms.spec.lua

Lines changed: 87 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ local addon = {
44
Getdb = function(self) return self.db end,
55
realmName = "Realm1",
66
db = { global = { log = {}, cache = {}, }, },
7-
defaults = { global = { logMaxEntries = 2000, }, },
7+
defaults = { global = { logMaxEntries = 2000, },
8+
},
9+
IsRestricted = function() return false end,
810
}
911
loadfile(".specs/AddonLoader.lua")(nil, nil, addon).LoadArray {
1012
[[Libs\LibStub\LibStub.lua]],
@@ -24,6 +26,7 @@ loadfile(".specs/AddonLoader.lua")(nil, nil, addon).LoadArray {
2426
"Classes/Utils/Item.lua",
2527
[[Utils\Utils.lua]],
2628
[[Classes\Data\Player.lua]],
29+
[[Classes\Services\CommsRestrictions.lua]],
2730
[[Classes\Services\Comms.lua]],
2831
}
2932
local Player = addon.Require "Data.Player"
@@ -448,44 +451,91 @@ describe("#Services #Comms", function()
448451
assert.spy(s).returned_with(data)
449452
end)
450453

451-
-- TODO: Figure out why this needs to be last for tests to complete
452-
describe("safemode", function()
453-
local receiverSpy
454-
local EHstub
455-
setup(function()
456-
receiverSpy = spy.new(function() error("from spy") end)
457-
local EH = addon.Require "Services.ErrorHandler"
458-
EHstub = stub(EH, "ThrowSilentError")
459-
addon.Getdb = spy.new(function() return { safemode = true, } end)
460-
_G.IsInRaidVal = true
461-
end)
454+
-- -- TODO: Figure out why this needs to be last for tests to complete
455+
-- describe("safemode", function()
456+
-- local EH = addon.Require "Services.ErrorHandler"
457+
-- local receiverSpy
458+
-- local EHstub
459+
-- setup(function()
460+
-- receiverSpy = spy.new(function() error("from spy") end)
461+
-- EHstub = stub(EH, "ThrowSilentError")
462+
-- addon.Getdb = spy.new(function() return { safemode = true, } end)
463+
-- _G.IsInRaidVal = true
464+
-- end)
465+
466+
-- teardown(function()
467+
-- -- just to be sure
468+
-- receiverSpy:revert()
469+
-- EHstub:revert()
470+
-- addon.Getdb:revert()
471+
-- _G.IsInRaidVal = false
472+
-- end)
473+
-- it("works with no errors", function()
474+
-- -- stub(addon, "Log")
475+
-- Comms:Subscribe(addon.PREFIXES.MAIN, "test", receiverSpy)
476+
-- Comms:Send { command = "test", }
477+
-- WoWAPI_FireUpdate(GetTime() + 10)
478+
-- -- Msg succesfully received
479+
-- assert.spy(receiverSpy).was_called(1)
480+
-- assert.spy(receiverSpy).was_called_with({}, "Sender-Realm1", "test", "RAID")
481+
-- -- even though receiver threw error
482+
-- assert.stub(EHstub).was_called(1)
483+
-- -- which doesn't break execution
484+
-- Comms:Send { command = "test", }
485+
-- WoWAPI_FireUpdate(GetTime() + 10)
486+
-- assert.spy(receiverSpy).was_called(2)
487+
-- assert.spy(receiverSpy).was_called_with({}, "Sender-Realm1", "test", "RAID")
488+
-- assert.stub(EHstub).was_called(2)
489+
-- end)
490+
491+
-- it("catches errors in receiver", function()
492+
493+
-- end)
494+
-- end)
495+
end)
462496

463-
teardown(function()
464-
-- just to be sure
465-
receiverSpy:revert()
466-
EHstub:revert()
467-
addon.Getdb:revert()
468-
end)
469-
it("works with no errors", function()
470-
stub(addon, "Log")
471-
Comms:Subscribe(addon.PREFIXES.MAIN, "test", receiverSpy)
472-
Comms:Send { command = "test", }
473-
WoWAPI_FireUpdate(GetTime() + 10)
474-
-- Msg succesfully received
475-
assert.spy(receiverSpy).was_called(1)
476-
assert.spy(receiverSpy).was_called_with({}, "Sender-Realm1", "test", "RAID")
477-
-- even though receiver threw error
478-
assert.stub(EHstub).was_called(1)
479-
-- which doesn't break execution
480-
Comms:Send { command = "test", }
481-
WoWAPI_FireUpdate(GetTime() + 10)
482-
assert.spy(receiverSpy).was_called(2)
483-
assert.spy(receiverSpy).was_called_with({}, "Sender-Realm1", "test", "RAID")
484-
assert.stub(EHstub).was_called(2)
485-
end)
486497

487-
it("catches errors in receiver", function()
498+
describe("#Services #Comms #Restricted", function()
499+
---@type Services.Comms
500+
local Comms = addon.Require("Services.Comms")
501+
addon.player = Player:Get("Player1")
502+
Comms:RegisterPrefix(addon.PREFIXES.MAIN)
503+
local onReceiveSpy, _sub
504+
local t = {
505+
receiver = function(data, sender, ...)
506+
-- print("RECEIVER:", dist, sender, unpack(data),...);
507+
return unpack(data)
508+
end,
509+
}
510+
setup(function()
511+
_sub = Comms:Subscribe(addon.PREFIXES.MAIN, "test", function(...) t.receiver(...) end)
512+
end)
513+
514+
teardown(function()
515+
_sub:unsubscribe()
516+
end)
488517

489-
end)
518+
before_each(function()
519+
-- Make wow_api think we're in a raid
520+
_G.IsInRaidVal = true
521+
onReceiveSpy = spy.on(t, "receiver")
522+
end)
523+
it("should not send comms in restricted mode", function()
524+
Comms:Send {
525+
prefix = addon.PREFIXES.MAIN,
526+
command = "test",
527+
data = "test",
528+
}
529+
WoWAPI_FireUpdate(GetTime() + 10)
530+
assert.spy(onReceiveSpy).was_called(1)
531+
local CommsRestrictions = addon.Require "Services.CommsRestrictions"
532+
local m = stub(CommsRestrictions, "IsRestricted", function() return true end)
533+
Comms:Send {
534+
prefix = addon.PREFIXES.MAIN,
535+
command = "test",
536+
data = "test",
537+
}
538+
WoWAPI_FireUpdate(GetTime() + 10)
539+
assert.spy(onReceiveSpy).was_called(1)
490540
end)
491541
end)

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,5 @@
211211
"string": "disable",
212212
"table": "disable",
213213
"utf8": "disable"
214-
}
214+
},
215215
}

Classes/Data/Player.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,10 @@ end
221221
--- @param name string
222222
--- @return string|nil guid #GUID of Player if found otherwise nil
223223
function private:GetGUIDFromPlayerNameByGuild(name)
224+
if not IsInGuild() then return end
224225
for i = 1, GetNumGuildMembers() do
225226
local name2, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, guid = GetGuildRosterInfo(i)
226-
if Ambiguate(name2, "none") == name then return guid end
227+
if name2 and Ambiguate(name2, "none") == name then return guid end
227228
end
228229
end
229230

0 commit comments

Comments
 (0)