Files
factorio-scenario-ExpCluster/exp_roles/test/seed.test.js
T
bbassieandClaude Fable 5 e79822b26e Add a test suite for the roles plugin
Run with `pnpm --filter @expcluster/roles test`, using tap as the runner.

The lua module is exercised for real: each test file runs in its own lua
state, created on first use by the helper, with the factorio surface and the
clusterio modules stubbed. The environment is passed to the chunk as an
argument so no globals are involved. Covers lookups and comparisons, the
permission checks, assignment with confirmation, rejection and local only
roles, jail suppression, the sync entry points, and the holder listings,
including a player holding a role in both the synced and the local list.

The javascript side covers the message records round tripping through their
schemas, the indexed permission encoding, and the seed: every permission it
grants must be defined by exp_scenario, and every parent must exist and have
its permissions carried into its children.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-20 22:02:51 +00:00

41 lines
1.5 KiB
JavaScript

"use strict";
const t = require("tap");
const lib = require("@clusterio/lib");
const { seedRoles, flattenSeedPermissions } = require("../dist/node/seed");
// Importing this defines the exp_scenario permissions the seed grants
require("@expcluster/scenario/dist/node/permissions");
t.test("every seed permission is defined", subtest => {
for (const role of seedRoles) {
for (const permission of flattenSeedPermissions(role)) {
subtest.ok(lib.permissions.has(permission), `${role.name} grants defined permission ${permission}`);
}
}
subtest.end();
});
t.test("parents exist and their permissions are inherited", subtest => {
const byName = new Map(seedRoles.map(role => [role.name, role]));
for (const role of seedRoles) {
if (role.parent === undefined) {
continue;
}
const parent = byName.get(role.parent);
subtest.ok(parent, `${role.name} has parent ${role.parent}`);
const flattened = flattenSeedPermissions(role);
for (const permission of flattenSeedPermissions(parent)) {
subtest.ok(flattened.has(permission), `${role.name} inherits ${permission}`);
}
}
subtest.end();
});
t.test("seed role names are unique with one default and one admin", subtest => {
const names = seedRoles.map(role => role.name);
subtest.strictSame(names.length, new Set(names).size, "names are unique");
subtest.strictSame(seedRoles.filter(role => role.isDefault).length, 1, "one default role");
subtest.strictSame(seedRoles.filter(role => role.isAdmin).length, 1, "one admin role");
subtest.end();
});