Add the exp_reports plugin and move the scenario onto it

Reports were the last legacy control module, kept in the lua state of
each instance. They are now an exp_reports plugin which stores them on
the controller: a report is immutable and holds the reported player, who
made it, the reason, the instance name and when it was made, and the only
operations are get, list, create and delete.

In game nothing is stored. The lua module sends each request over ipc,
the instance plugin asks the controller and hands the answer back with
rcon, and the module prints it to whoever asked if they are still online.
Answers are dropped if the instance stopped meanwhile. The module raises
on_player_reported with the count and reporters of every report against
the player, which report_jail and discord_alerts use, and the commands
and player list button call into it.

The web ui gets a /reports page: a table with search on the player,
reporter and reason, a filter on the instance, delete per row and a
create form which reports in the name of the web user.

New reports are posted to two optional webhooks configured on the
controller, a Discord channel hook as an embed and a generic JSON hook.
Failures are logged rather than failing the report.

Tests cover the messages, the controller against a real Controller, the
instance plugin against a real Instance, and the lua module through the
shared harness.
This commit is contained in:
bbassie committed 2026-09-06 16:44:23 +00:00
1 parent 142d296a02
commit bad98c5013
35 files changed
+1707 -350

No files matched your search

+193
View File
@@ -0,0 +1,193 @@
"use strict";
const t = require("tap");
const lib = require("@clusterio/lib");
const { Controller, InstanceRecord } = require("@clusterio/controller");
const { ControllerPlugin } = require("../dist/node/controller");
const messages = require("../dist/node/messages");
const { plugin: pluginDeclaration } = require("../dist/node/index");
// The controller validates message classes against the link registry, and the
// plugin's config fields must be defined before a ControllerConfig can set them
for (const Message of pluginDeclaration.messages) {
lib.Link.register(Message);
}
lib.addPluginConfigFields([pluginDeclaration]);
const logger = { child: () => logger, info: () => {}, warn: () => {}, error: () => {}, verbose: () => {} };
// Silence the singleton logger to avoid polluting the test output
lib.logger.silent = true;
t.after(() => {
lib.logger.silent = false;
});
const fromInstance = lib.Address.fromShorthand({ instanceId: 1 });
const fromUnknownInstance = lib.Address.fromShorthand({ instanceId: 9 });
const fromControl = lib.Address.fromShorthand({ controlId: 7 });
/** Build the plugin around a real controller, which is side effect free while not started. */
async function startPlugin(t2, { config = {} } = {}) {
const controllerConfig = new lib.ControllerConfig("controller", {
"controller.database_directory": t2.testdir(),
...config,
});
const controller = new Controller(logger, [], controllerConfig);
const instanceConfig = new lib.InstanceConfig("controller");
instanceConfig.set("instance.id", 1);
instanceConfig.set("instance.name", "EXP");
controller.instances.records.set(new InstanceRecord(instanceConfig, "running"));
controller.wsServer.controlConnections.set(7, { user: { name: "admin" } });
// Spies which record and then defer to the real behaviour
const state = { broadcasts: [], posts: [], warnings: [] };
const broadcast = controller.subscriptions.broadcast.bind(controller.subscriptions);
controller.subscriptions.broadcast = event => {
state.broadcasts.push(event);
broadcast(event);
};
const plugin = new ControllerPlugin({ name: "exp_reports" }, controller, undefined, logger);
plugin.logger = { ...logger, warn: message => state.warnings.push(message) };
plugin.postWebhook = async (url, body) => { state.posts.push({ url, body }); };
await plugin.init();
return { plugin, controller, state };
}
t.test("class ControllerPlugin", t2 => {
t2.test(".handleReportCreateRequest() from an instance records the instance and the reporter", async t3 => {
const { plugin } = await startPlugin(t3);
const report = await plugin.handleReportCreateRequest(
new messages.ReportCreateRequest("bob", " griefing ", "alice"), fromInstance,
);
t3.strictSame(report.playerName, "bob");
t3.strictSame(report.byPlayerName, "alice", "the reporter comes from the request");
t3.strictSame(report.reason, "griefing", "the reason is trimmed");
t3.strictSame(report.instanceName, "EXP", "the instance is named");
t3.ok(report.updatedAtMs > 0, "the report is timestamped");
t3.strictSame(plugin.listReports(), [report], "the report is stored");
const unknown = await plugin.handleReportCreateRequest(
new messages.ReportCreateRequest("carol", "spam", "alice"), fromUnknownInstance,
);
t3.strictSame(unknown.instanceName, "9", "an unknown instance is named by its id");
});
t2.test(".handleReportCreateRequest() from the web ui uses the user of the connection", async t3 => {
const { plugin } = await startPlugin(t3);
const report = await plugin.handleReportCreateRequest(
new messages.ReportCreateRequest("bob", "griefing", "someone-else"), fromControl,
);
t3.strictSame(report.byPlayerName, "admin", "the reporter is the connected user");
t3.strictSame(report.instanceName, "", "there is no instance");
});
t2.test(".handleReportCreateRequest() rejects reports which can not be stored", async t3 => {
const { plugin } = await startPlugin(t3);
await plugin.handleReportCreateRequest(new messages.ReportCreateRequest("bob", "griefing", "alice"), fromInstance);
await t3.rejects(
plugin.handleReportCreateRequest(new messages.ReportCreateRequest("bob", "again", "alice"), fromInstance),
{ message: "alice has already reported bob" },
"a player can only report another once",
);
await t3.rejects(
plugin.handleReportCreateRequest(new messages.ReportCreateRequest("bob", " ", "carol"), fromInstance),
{ message: "A report needs a reason" },
"a reason is required",
);
await t3.rejects(
plugin.handleReportCreateRequest(new messages.ReportCreateRequest("bob", "spam", ""), fromInstance),
{ message: "A report needs the name of the player making it" },
"an instance must name the reporter",
);
t3.strictSame(plugin.listReports().length, 1, "nothing else was stored");
});
t2.test(".handleReportListRequest() and .handleReportGetRequest() find reports", async t3 => {
const { plugin } = await startPlugin(t3);
const first = await plugin.handleReportCreateRequest(new messages.ReportCreateRequest("bob", "griefing", "alice"), fromInstance);
await plugin.handleReportCreateRequest(new messages.ReportCreateRequest("carol", "spam", "alice"), fromInstance);
t3.strictSame((await plugin.handleReportListRequest(new messages.ReportListRequest())).length, 2, "everything is listed");
t3.strictSame(
await plugin.handleReportListRequest(new messages.ReportListRequest("bob")), [first],
"a player's reports are listed",
);
t3.strictSame(await plugin.handleReportGetRequest(new messages.ReportGetRequest(first.id)), first);
await t3.rejects(
plugin.handleReportGetRequest(new messages.ReportGetRequest(123)),
{ message: "Report with ID 123 does not exist" },
);
});
t2.test(".handleReportDeleteRequest() removes the report and broadcasts the deletion", async t3 => {
const { plugin, state } = await startPlugin(t3);
const report = await plugin.handleReportCreateRequest(new messages.ReportCreateRequest("bob", "griefing", "alice"), fromInstance);
state.broadcasts.length = 0;
await plugin.handleReportDeleteRequest(new messages.ReportDeleteRequest(report.id));
t3.strictSame(plugin.listReports(), [], "the report is gone");
t3.ok(
state.broadcasts.some(event => event instanceof messages.ReportUpdatedEvent && event.updates[0].isDeleted),
"subscribers are told it was deleted",
);
await t3.rejects(
plugin.handleReportDeleteRequest(new messages.ReportDeleteRequest(report.id)),
{ message: `Report with ID ${report.id} does not exist` },
);
});
t2.test(".handleReportSubscription() replays only newer records", async t3 => {
const { plugin } = await startPlugin(t3);
const report = await plugin.handleReportCreateRequest(new messages.ReportCreateRequest("bob", "griefing", "alice"), fromInstance);
const all = await plugin.handleReportSubscription({ lastRequestTimeMs: 0 });
t3.strictSame(all.updates, [report], "everything is replayed from the start");
const none = await plugin.handleReportSubscription({ lastRequestTimeMs: report.updatedAtMs });
t3.strictSame(none, null, "nothing is replayed when up to date");
});
t2.test(".sendWebhooks() posts new reports to the configured hooks", async t3 => {
const { plugin, state } = await startPlugin(t3, { config: {
"exp_reports.discord_webhook_url": "https://discord.example/hook",
"exp_reports.json_webhook_url": "https://json.example/hook",
} });
const report = await plugin.handleReportCreateRequest(new messages.ReportCreateRequest("bob", "griefing", "alice"), fromInstance);
t3.strictSame(state.posts.map(post => post.url), ["https://discord.example/hook", "https://json.example/hook"]);
const embed = state.posts[0].body.embeds[0];
t3.strictSame(embed.fields.map(field => field.value), ["bob", "alice", "EXP", "griefing"], "the embed names the report");
t3.strictSame(state.posts[1].body, { type: "report_created", report: report.toJSON() }, "the json hook gets the record");
state.posts.length = 0;
await plugin.handleReportDeleteRequest(new messages.ReportDeleteRequest(report.id));
t3.strictSame(state.posts, [], "deletions are not posted");
});
t2.test(".sendWebhooks() does nothing without hooks", async t3 => {
const { plugin, state } = await startPlugin(t3);
await plugin.handleReportCreateRequest(new messages.ReportCreateRequest("bob", "griefing", "alice"), fromInstance);
t3.strictSame(state.posts, []);
});
t2.test(".postWebhook() logs rather than throws when the hook fails", async t3 => {
const { plugin, state } = await startPlugin(t3);
plugin.postWebhook = ControllerPlugin.prototype.postWebhook;
const realFetch = globalThis.fetch;
globalThis.fetch = async () => { throw new Error("connection refused"); };
t3.teardown(() => { globalThis.fetch = realFetch; });
await plugin.postWebhook("https://down.example/hook", {});
t3.strictSame(state.warnings, ["Webhook https://down.example/hook failed: connection refused"]);
globalThis.fetch = async () => ({ ok: false, status: 404 });
await plugin.postWebhook("https://down.example/hook", {});
t3.strictSame(state.warnings[1], "Webhook https://down.example/hook responded with 404");
});
t2.end();
});
+142
View File
@@ -0,0 +1,142 @@
"use strict";
const t = require("tap");
const lib = require("@clusterio/lib");
const { Instance } = require("@clusterio/host");
const { InstancePlugin } = require("../dist/node/instance");
const { plugin: pluginDeclaration } = require("../dist/node/index");
const messages = require("../dist/node/messages");
// The instance validates message classes against the link registry
for (const Message of pluginDeclaration.messages) {
lib.Link.register(Message);
}
class TestConnector extends lib.BaseConnector {
constructor() {
super(lib.Address.fromShorthand({ instanceId: 1 }), lib.Address.fromShorthand({ hostId: 1 }));
this.valid = true;
this.connected = true;
this.hasSession = true;
}
send() {}
}
const report = (id, playerName, byPlayerName) => new messages.ReportRecord(id, playerName, byPlayerName, "griefing", "EXP", 1000);
/** Build a plugin around a real running instance with spies on what leaves it. */
async function startPlugin(t2, { reports = [report(1, "bob", "alice"), report(2, "bob", "carol")] } = {}) {
const instanceConfig = new lib.InstanceConfig("host");
instanceConfig.set("instance.id", 1);
instanceConfig.set("instance.name", "test");
const instance = new Instance(
{ assignGamePort: () => 1 }, new TestConnector(), t2.testdir(), "factorioDir", instanceConfig
);
// Spies which record the messages and commands leaving the instance
const state = { sent: [], rcons: [], failNext: null };
instance.server = {
handle: () => {},
sendRcon: async command => {
state.rcons.push(command);
return "";
},
};
instance.sendTo = async (dst, request) => {
state.sent.push(request);
if (state.failNext) {
const error = state.failNext;
state.failNext = null;
throw error;
}
if (request instanceof messages.ReportCreateRequest) {
return report(3, request.playerName, request.byPlayerName);
}
if (request instanceof messages.ReportListRequest) {
return reports.filter(other => request.playerName === undefined || other.playerName === request.playerName);
}
return undefined;
};
instance.notifyStatus("running");
state.sent.length = 0;
const plugin = new InstancePlugin({ name: "exp_reports" }, instance, {});
await plugin.init();
return { plugin, instance, state };
}
/** The lua receiver and payload of a recorded rcon command. */
function decodeRcon(command) {
const match = command.match(/^\/sc exp_reports\.(\w+)\(helpers\.json_to_table\[=\[(.*)\]=\]\)$/s);
return { receiver: match[1], payload: JSON.parse(match[2]) };
}
t.test("class InstancePlugin", t2 => {
t2.test(".handleCreateIPC() creates the report and hands it to lua with the others against the player", async t3 => {
const { plugin, state } = await startPlugin(t3);
await plugin.handleCreateIPC({ player_name: "bob", by_player_name: "dave", reason: "griefing" });
const create = state.sent.find(request => request instanceof messages.ReportCreateRequest);
t3.strictSame([create.playerName, create.byPlayerName, create.reason], ["bob", "dave", "griefing"]);
t3.ok(state.sent.some(request => request instanceof messages.ReportListRequest && request.playerName === "bob"),
"the reports against the player are requested");
const { receiver, payload } = decodeRcon(state.rcons[0]);
t3.strictSame(receiver, "receive_created");
t3.strictSame(payload.report.by_player_name, "dave", "the new report is sent");
t3.strictSame(payload.reports.map(other => other.by_player_name), ["alice", "carol"], "along with the existing ones");
});
t2.test(".handleCreateIPC() prints a refusal to the reporter", async t3 => {
const { plugin, state } = await startPlugin(t3);
state.failNext = new lib.RequestError("dave has already reported bob");
await plugin.handleCreateIPC({ player_name: "bob", by_player_name: "dave", reason: "griefing" });
const { receiver, payload } = decodeRcon(state.rcons[0]);
t3.strictSame(receiver, "receive_error");
t3.strictSame(payload, { caller: "dave", message: "dave has already reported bob" });
});
t2.test(".handleListIPC() lists the reports for the caller", async t3 => {
const { plugin, state } = await startPlugin(t3);
await plugin.handleListIPC({ caller: "admin", player_name: "bob" });
await plugin.handleListIPC({ caller: "admin", player_name: undefined });
const forPlayer = decodeRcon(state.rcons[0]);
t3.strictSame(forPlayer.receiver, "receive_list");
t3.strictSame([forPlayer.payload.caller, forPlayer.payload.player_name], ["admin", "bob"]);
t3.strictSame(forPlayer.payload.reports.length, 2);
const forAll = decodeRcon(state.rcons[1]);
t3.strictSame(forAll.payload.player_name, undefined, "no player when listing everyone");
});
t2.test(".handleDeleteIPC() deletes only the matching reports", async t3 => {
const { plugin, state } = await startPlugin(t3);
await plugin.handleDeleteIPC({ caller: "admin", player_name: "bob", by_player_name: "carol" });
const deletes = state.sent.filter(request => request instanceof messages.ReportDeleteRequest);
t3.strictSame(deletes.map(request => request.id), [2], "only carol's report is deleted");
const { receiver, payload } = decodeRcon(state.rcons[0]);
t3.strictSame(receiver, "receive_deleted");
t3.strictSame(payload, { caller: "admin", player_name: "bob", by_player_name: "carol", count: 1 });
state.sent.length = 0;
await plugin.handleDeleteIPC({ caller: "admin", player_name: "bob", by_player_name: undefined });
t3.strictSame(
state.sent.filter(request => request instanceof messages.ReportDeleteRequest).length, 2,
"every report is deleted without a reporter",
);
});
t2.test(".luaSend() drops answers once the instance has stopped", async t3 => {
const { plugin, instance, state } = await startPlugin(t3);
instance.notifyStatus("stopped");
await plugin.handleListIPC({ caller: "admin", player_name: undefined });
t3.strictSame(state.rcons, [], "nothing is sent to a stopped instance");
});
t2.end();
});
+62
View File
@@ -0,0 +1,62 @@
"use strict";
const t = require("tap");
const messages = require("../dist/node/messages");
const { testMatrix, testRoundTripJsonSerialisable } = require("../../test/common");
const sampleReport = new messages.ReportRecord(7, "bob", "alice", "griefing", "EXP", 12345);
t.test("class ReportRecord", t2 => {
testRoundTripJsonSerialisable(t2, messages.ReportRecord, testMatrix(
[7], // id
["bob"], // playerName
["alice"], // byPlayerName
["griefing"], // reason
["", "EXP"], // instanceName
[0, 12345], // updatedAtMs
[false, true], // isDeleted
));
t2.end();
});
t.test("class ReportUpdatedEvent", t2 => {
testRoundTripJsonSerialisable(t2, messages.ReportUpdatedEvent, testMatrix(
[[], [sampleReport]], // updates
));
t2.end();
});
t.test("class ReportListRequest", t2 => {
testRoundTripJsonSerialisable(t2, messages.ReportListRequest, testMatrix(
[undefined, "bob"], // playerName
));
t2.end();
});
t.test("class ReportGetRequest", t2 => {
testRoundTripJsonSerialisable(t2, messages.ReportGetRequest, testMatrix(
[7], // id
));
t2.end();
});
t.test("class ReportCreateRequest", t2 => {
testRoundTripJsonSerialisable(t2, messages.ReportCreateRequest, testMatrix(
["bob"], // playerName
["griefing"], // reason
["", "alice"], // byPlayerName
));
t2.end();
});
t.test("class ReportDeleteRequest", t2 => {
testRoundTripJsonSerialisable(t2, messages.ReportDeleteRequest, testMatrix(
[7], // id
));
t2.end();
});
+14
View File
@@ -0,0 +1,14 @@
"use strict";
const path = require("node:path");
const t = require("tap");
const { reportLuaTests } = require("../../test/lua/runner");
const envFile = path.join(__dirname, "module", "env.lua");
// Each file runs in its own lua state, and each test in a fresh environment
t.test("control.lua", t2 => {
for (const file of ["requests.lua", "receivers.lua"]) {
t2.test(file, t3 => reportLuaTests(t3, envFile, path.join(__dirname, "module", file)));
}
t2.end();
});
+59
View File
@@ -0,0 +1,59 @@
--[[-- 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
--- A stubbed player which also carries the admin flag the module reads
--- @class ExpReports.TestPlayer : Stubs.Player
--- @field admin boolean
--- 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 add_player fun(name: string, is_connected: boolean?, is_admin: boolean?): ExpReports.TestPlayer
--- @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
-- The module reads player.admin, which the strict stub raises on unless it is set
local add_player = env.add_player
function env.add_player(name, is_connected, is_admin)
local player = add_player(name, is_connected) --[[@as ExpReports.TestPlayer]]
player.admin = is_admin == true
return player
end
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)
+102
View File
@@ -0,0 +1,102 @@
local Suite = ... --- @type Suite<ExpReports.TestEnv>
Suite.test("receive_created() tells everyone and raises on_player_reported", function(env)
env.add_player("alice", true, true)
local bob = env.add_player("bob")
env.add_player("carol")
local report = env.report("bob", "alice")
env.Reports.receive_created{ report = report, reports = { report, env.report("bob", "carol") } }
Suite.eq(env.printed, {
{ to = "alice", { "exp-reports.created-admin", "bob", "alice", "griefing" } },
{ to = "bob", { "exp-reports.created", "bob", "griefing" } },
{ to = "carol", { "exp-reports.created", "bob", "griefing" } },
}, "admins see who reported, everyone else only the reason")
Suite.eq(env.events, {
{
name = env.Reports.on_player_reported,
tick = 1,
player_index = bob.index,
by_player_name = "alice",
reason = "griefing",
report_count = 2,
by_player_names = { "alice", "carol" },
},
}, "the event carries every report against the player")
end)
Suite.test("receive_created() raises nothing when the reported player has left", function(env)
env.add_player("alice")
env.add_player("bob", false)
local report = env.report("bob", "alice")
env.Reports.receive_created{ report = report, reports = { report } }
Suite.eq(env.printed, { { to = "alice", { "exp-reports.created", "bob", "griefing" } } }, "the report is still announced")
Suite.empty(env.events, "there is nobody to act on")
end)
Suite.test("receive_list() prints the reports against a player to the caller", function(env)
env.add_player("alice")
env.Reports.receive_list{
caller = "alice",
player_name = "bob",
reports = { env.report("bob", "carol", "spam"), env.report("bob", "dave", "griefing") },
}
Suite.eq(env.printed, {
{ to = "alice", { "exp-reports.list-title", "bob", 2 } },
{ to = "alice", { "exp-reports.list-entry", "carol", "spam" } },
{ to = "alice", { "exp-reports.list-entry", "dave", "griefing" } },
}, "the title is followed by one line per report")
end)
Suite.test("receive_list() prints how many reports each player has", function(env)
env.add_player("alice")
env.Reports.receive_list{
caller = "alice",
reports = { env.report("dave", "alice"), env.report("bob", "carol"), env.report("dave", "carol") },
}
Suite.eq(env.printed, {
{ to = "alice", { "exp-reports.list-all-title" } },
{ to = "alice", { "exp-reports.list-all-entry", "bob", 1 } },
{ to = "alice", { "exp-reports.list-all-entry", "dave", 2 } },
}, "players are listed by name with their count")
end)
Suite.test("receive_list() says when nobody is reported", function(env)
env.add_player("alice")
env.Reports.receive_list{ caller = "alice", reports = {} }
Suite.eq(env.printed, { { to = "alice", { "exp-reports.list-all-none" } } }, "the caller is told there are none")
end)
Suite.test("receive_list() prints nothing once the caller has left", function(env)
env.add_player("alice", false)
env.Reports.receive_list{ caller = "alice", reports = { env.report("bob", "carol") } }
Suite.empty(env.printed, "nothing is printed")
end)
Suite.test("receive_deleted() announces the deletion and raises on_reports_deleted", function(env)
env.add_player("alice")
local bob = env.add_player("bob")
env.Reports.receive_deleted{ caller = "alice", player_name = "bob", count = 2 }
Suite.eq(env.printed, { { "exp-reports.deleted", "bob", 2, "alice" } }, "everyone is told")
Suite.eq(env.events, {
{ name = env.Reports.on_reports_deleted, tick = 1, player_index = bob.index, by_player_name = "alice", count = 2 },
}, "the event names who deleted how many")
end)
Suite.test("receive_deleted() tells the caller when there was nothing to delete", function(env)
env.add_player("alice")
env.add_player("bob")
env.Reports.receive_deleted{ caller = "alice", player_name = "bob", count = 0 }
Suite.eq(env.printed, { { to = "alice", { "exp-reports.deleted-none", "bob" } } }, "only the caller is told")
Suite.empty(env.events, "nothing was deleted")
end)
Suite.test("receive_error() prints the refusal to the caller while they are online", function(env)
env.add_player("alice")
env.add_player("bob", false)
env.Reports.receive_error{ caller = "alice", message = "alice has already reported bob" }
env.Reports.receive_error{ caller = "bob", message = "gone" }
Suite.eq(env.printed, { { to = "alice", "alice has already reported bob" } }, "the offline player is skipped")
end)
return Suite.run()
+34
View File
@@ -0,0 +1,34 @@
local Suite = ... --- @type Suite<ExpReports.TestEnv>
Suite.test("create_report() sends the report to the controller", function(env)
local alice = env.add_player("alice")
local bob = env.add_player("bob")
env.Reports.create_report(alice, bob, "griefing")
Suite.eq(env.sent, {
{ channel = "exp_reports:create", data = { player_name = "bob", by_player_name = "alice", reason = "griefing" } },
}, "the report names both players")
end)
Suite.test("list_reports() sends the caller and the player", function(env)
local alice = env.add_player("alice")
local bob = env.add_player("bob")
env.Reports.list_reports(alice, bob)
env.Reports.list_reports(alice)
Suite.eq(env.sent, {
{ channel = "exp_reports:list", data = { caller = "alice", player_name = "bob" } },
{ channel = "exp_reports:list", data = { caller = "alice" } },
}, "the player is left out when listing everyone")
end)
Suite.test("delete_reports() sends the caller, the player and the reporter", function(env)
local alice = env.add_player("alice")
local bob = env.add_player("bob")
env.Reports.delete_reports(alice, bob, "carol")
env.Reports.delete_reports(alice, bob)
Suite.eq(env.sent, {
{ channel = "exp_reports:delete", data = { caller = "alice", player_name = "bob", by_player_name = "carol" } },
{ channel = "exp_reports:delete", data = { caller = "alice", player_name = "bob" } },
}, "the reporter is left out when deleting every report")
end)
return Suite.run()