mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-09-21 17:04:00 +00:00
- The registry is a Suite, created around the environment factory it runs its tests with, so the plugin's env.lua reads as: build environments, hand the test files a suite of them. The suite returned there becomes `...` in each test file, which is now said where it happens. - pass and fail are the primitives every other check goes through. eq and deep_eq assert rather than compare, failing with both values in the detail. - Stubs are extended through extend_requires, extend_script, extend_game and extend_defines, a recursive merge which raises when a value already exists, rather than by mutating the tables. The strict labels carry the factorio class names. - The stubs record registered metatables and can save and load the script data the way factorio does: functions are refused and only registered metatables survive. env.save_load() uses it, and a new on_load test shows role methods and held roles surviving the round trip, which only passes because the module registers its metatable. - The names helper moved out of the shared framework, it is role specific. - Tests are named after the function or method they cover, on both sides: the lua tests read as "role:assign applies locally and is sent", and the javascript files wrap their tests in the class they exercise with subtests per method. module.test.js is control.test.js, after the file it covers. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
111 lines
3.3 KiB
JavaScript
111 lines
3.3 KiB
JavaScript
"use strict";
|
|
const t = require("tap");
|
|
const messages = require("../dist/node/messages");
|
|
const { testMatrix, testRoundTripJsonSerialisable } = require("../../test/common");
|
|
|
|
const fullMeta = new messages.RoleMetaRecord(
|
|
7, 3, 1, "Mod", "[Mod]", new messages.RoleColor(1, 2, 3), 3600000, true, 12345, false,
|
|
);
|
|
|
|
t.test("class RoleColor", subtest => {
|
|
testRoundTripJsonSerialisable(messages.RoleColor, testMatrix(
|
|
[0, 255], // r
|
|
[0, 128], // g
|
|
[0, 1], // b
|
|
));
|
|
subtest.pass("round trips");
|
|
subtest.end();
|
|
});
|
|
|
|
t.test("class RoleMetaRecord", subtest => {
|
|
testRoundTripJsonSerialisable(messages.RoleMetaRecord, testMatrix(
|
|
[7], // id
|
|
[3], // order
|
|
[0, 1], // priority
|
|
["", "Mod"], // shortHand
|
|
["", "[Mod]"], // tag
|
|
[null, new messages.RoleColor(1, 2, 3)], // color
|
|
[null, 3600000], // autoAssignOnlineTimeMs
|
|
[false, true], // blockAutoAssign
|
|
[0, 12345], // updatedAtMs
|
|
[false, true], // isDeleted
|
|
));
|
|
subtest.pass("round trips");
|
|
subtest.end();
|
|
});
|
|
|
|
t.test("class RoleRecord", subtest => {
|
|
testRoundTripJsonSerialisable(messages.RoleRecord, testMatrix(
|
|
[7], // id
|
|
["Moderator"], // name
|
|
[[], ["a.b", "c.d"]], // permissions
|
|
[new messages.RoleMetaRecord(7, 3), fullMeta], // meta
|
|
[false, true], // isDefault
|
|
[0, 12345], // updatedAtMs
|
|
[false, true], // isDeleted
|
|
));
|
|
subtest.pass("round trips");
|
|
subtest.end();
|
|
});
|
|
|
|
t.test("class AssignmentRecord", subtest => {
|
|
testRoundTripJsonSerialisable(messages.AssignmentRecord, testMatrix(
|
|
["alice"], // name
|
|
[new Set(), new Set([5, 6])], // roleIds
|
|
[0, 12345], // updatedAtMs
|
|
[false, true], // isDeleted
|
|
));
|
|
subtest.pass("round trips");
|
|
subtest.end();
|
|
});
|
|
|
|
const sampleRecord = new messages.RoleRecord(7, "Moderator", ["a.b"], fullMeta, true, 12345);
|
|
const sampleAssignment = new messages.AssignmentRecord("alice", new Set([5]), 12345);
|
|
|
|
t.test("class RoleUpdatedEvent", subtest => {
|
|
testRoundTripJsonSerialisable(messages.RoleUpdatedEvent, testMatrix(
|
|
[[], [sampleRecord]], // updates
|
|
));
|
|
subtest.pass("round trips");
|
|
subtest.end();
|
|
});
|
|
|
|
t.test("class AssignmentUpdatedEvent", subtest => {
|
|
testRoundTripJsonSerialisable(messages.AssignmentUpdatedEvent, testMatrix(
|
|
[[], [sampleAssignment]], // updates
|
|
));
|
|
subtest.pass("round trips");
|
|
subtest.end();
|
|
});
|
|
|
|
t.test("class RoleMetaUpdateRequest", subtest => {
|
|
testRoundTripJsonSerialisable(messages.RoleMetaUpdateRequest, testMatrix(
|
|
[new messages.RoleMetaRecord(7, 3), fullMeta], // meta
|
|
));
|
|
subtest.pass("round trips");
|
|
subtest.end();
|
|
});
|
|
|
|
t.test("class AssignmentUpdateRequest", subtest => {
|
|
testRoundTripJsonSerialisable(messages.AssignmentUpdateRequest, testMatrix(
|
|
["alice"], // name
|
|
[[], [5]], // assign
|
|
[[], [6]], // unassign
|
|
));
|
|
subtest.pass("round trips");
|
|
subtest.end();
|
|
});
|
|
|
|
t.test("encodeRolesForLua sends each permission name once", subtest => {
|
|
const meta = id => new messages.RoleMetaRecord(id, id);
|
|
const encoded = messages.encodeRolesForLua([
|
|
new messages.RoleRecord(1, "A", ["p.one", "p.two"], meta(1)),
|
|
new messages.RoleRecord(2, "B", ["p.two", "p.three"], meta(2)),
|
|
]);
|
|
|
|
subtest.strictSame(encoded.permission_names, ["p.one", "p.two", "p.three"], "names are deduplicated");
|
|
subtest.strictSame(encoded.roles[0].permissions, [0, 1], "indexes are zero based");
|
|
subtest.strictSame(encoded.roles[1].permissions, [1, 2], "shared names reuse their index");
|
|
subtest.end();
|
|
});
|