mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-09-21 17:04:00 +00:00
Address review on the stubs and controller tests
- The controller tests run against a real Controller, which is side effect free while not started, with real users through its UserManager. The only fakes left are two spies which record broadcasts and permission pushes on their way through. Since any user update also applies auto assignment, the leave event is observed directly rather than through a role change. - raise_event fills in the name and tick of the event the way factorio does, rather than wrapping the payload, and game.players finds players by index as well as by name through a metatable. - names is generic over anything with a name property, so it lives on the suite; the save and load helper no longer calls on_load, the test calls the handler itself as it does for the other handlers. - Sent messages and events are compared whole with deep_eq, which pins the event shape, the tick, and that the unassign key is absent rather than empty. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
7adcdde9dc
commit
e6552a39be
@@ -24,7 +24,7 @@ test("initialise applies triggers and raises empty events", function(env)
|
||||
setup(env)
|
||||
deep_eq(env.admin_state, { alice = true, carol = false }, "triggers run for connected players")
|
||||
check(#env.events == 2, "the event is raised once per connected player")
|
||||
check(#env.events[1].data.assigned == 0 and #env.events[1].data.unassigned == 0, "the events are empty")
|
||||
check(#env.events[1].assigned == 0 and #env.events[1].unassigned == 0, "the events are empty")
|
||||
check(#env.printed == 0 and #env.sent == 0 and #env.sounds == 0, "initialise is silent and sends nothing")
|
||||
end)
|
||||
|
||||
@@ -49,16 +49,23 @@ test("receive_assignment_updates applies controller changes", function(env)
|
||||
env.reset_log()
|
||||
env.Roles.receive_assignment_updates{ env.assignment("carol", { 5 }) }
|
||||
check(env.R("Moderator"):has_player(players.carol), "the assignment applies")
|
||||
check(#env.events == 1, "the event is raised")
|
||||
eq(env.events[1].data.assigned, { 5 }, "the event carries the role id")
|
||||
check(env.events[1].data.by_player_index == 0, "controller changes have no by player")
|
||||
deep_eq(env.events, {
|
||||
{
|
||||
name = env.Roles.events.on_player_roles_changed,
|
||||
tick = 1,
|
||||
player_index = 3,
|
||||
by_player_index = 0,
|
||||
assigned = { 5 },
|
||||
unassigned = {},
|
||||
},
|
||||
}, "the event carries the change with no by player")
|
||||
check(#env.printed == 1 and env.printed[1][4] == "<server>", "the change is announced by the server")
|
||||
check(env.admin_state.carol == true, "triggers follow the assignment")
|
||||
|
||||
env.reset_log()
|
||||
env.Roles.receive_assignment_updates{ { name = "carol", role_ids = {}, is_deleted = true } }
|
||||
check(not env.R("Moderator"):has_player(players.carol), "a removal applies")
|
||||
eq(env.events[1].data.unassigned, { 5 }, "the removal raises the event")
|
||||
eq(env.events[1].unassigned, { 5 }, "the removal raises the event")
|
||||
check(env.admin_state.carol == false, "triggers follow the removal")
|
||||
end)
|
||||
|
||||
@@ -77,7 +84,7 @@ test("receive_role_updates applies to the holders", function(env)
|
||||
}
|
||||
check(env.R("Regular"):has_permission("exp_scenario.command.jail"), "the permission change applies")
|
||||
check(#env.events == 2, "a role change raises for every connected player")
|
||||
check(#env.events[1].data.assigned == 0, "role change events are empty")
|
||||
check(#env.events[1].assigned == 0, "role change events are empty")
|
||||
|
||||
env.Roles.receive_role_updates{
|
||||
{ id = 6, name = "Regular", permissions = {}, meta = { id = 0, order = 3 }, is_deleted = true },
|
||||
@@ -92,7 +99,7 @@ test("receive_role_updates moves the default role", function(env)
|
||||
{ id = 8, name = "Guest", permissions = {}, meta = { id = 0, order = 7 }, is_default = true },
|
||||
}
|
||||
check(env.Roles.get_default_role() == env.R("Guest"), "the new default role is known")
|
||||
eq(env.names(env.Roles.get_player_roles(players.carol)), { "Guest" }, "players pick up the new default")
|
||||
eq(Suite.names(env.Roles.get_player_roles(players.carol)), { "Guest" }, "players pick up the new default")
|
||||
end)
|
||||
|
||||
test("set_emit_events gates what is sent", function(env)
|
||||
@@ -108,6 +115,7 @@ test("on_load restores the state after a save and load", function(env)
|
||||
local players = setup(env)
|
||||
env.R("Jail"):assign(players.carol, { silent = true, local_only = true })
|
||||
env.save_load()
|
||||
env.Roles.on_load()
|
||||
|
||||
check(env.R("Moderator"):is_higher_than(env.R("Regular")), "role methods survive through the registered metatable")
|
||||
check(env.R("Moderator"):has_player(players.alice), "synced roles survive")
|
||||
|
||||
Reference in New Issue
Block a user