Files
factorio-expcluster/exp_reports/test/module/env.lua
T
bbassieandClaude Opus 5.5 9ddb7b362b Move the report commands into exp_reports
The create-report, get-reports and clear-reports commands now live in the
plugin's own module next to the functions they call, with their locale.
The permissions keep their exp_scenario.command names because the command
authority derives them from the command name.

The Discord report alert in exp_scenario is gone since exp_reports posts to
its own webhook. The shared add_player stub takes an options table with
connected and admin defaulting to true and false, replacing the copy in
the exp_reports test environment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 23:22:18 +00:00

47 lines
1.7 KiB
Lua

--[[-- Test environment for module/control.lua
Extends the shared stubs with a fresh copy of the reports module, a stub of
the exp_util functions it uses, and helpers to build the payloads the
instance plugin sends.
Run as a chunk by test/lua/runner.js, receiving the shared folder. The suite
returned here becomes `...` in each test file.
]]
local shared_root = ... --- @type string
local source = assert(debug.getinfo(1, "S")).source:gsub("\\", "/")
local plugin_root = assert(source:match("^@(.*)/test/module/env%.lua$"))
local Framework = assert(loadfile(shared_root .. "/framework.lua"))() --- @type Framework
--- The environment given to each test: the stubs extended with a fresh copy
--- of the reports module and the fixture helpers
--- @class ExpReports.TestEnv : Stubs
--- @field Reports ExpReports A fresh copy of the reports module
--- @field report fun(player_name: string, by_player_name: string, reason: string?): ExpReports.Report A report as the controller sends it
return Framework.suite(function(env)
--- @cast env ExpReports.TestEnv
env.extend_requires{
["modules/exp_util"] = {
format_player_name_locale = function(name) return name end,
color = { orange_red = "orange_red" },
},
}
env.Reports = assert(loadfile(plugin_root .. "/module/control.lua"))() --- @type ExpReports
local next_id = 0
function env.report(player_name, by_player_name, reason)
next_id = next_id + 1
return {
id = next_id,
player_name = player_name,
by_player_name = by_player_name,
reason = reason or "griefing",
instance_name = "test",
updated_at_ms = 1000,
}
end
return env
end)