Files
Hornwitser e453a80155 Refactor User and Role into data classes (#531)
Use the JSON data class pattern for User, Role, and PlayerStats and move
them into lib/src/data.  This means that User is purely data now and
can't reference role objects directly.  To make it possible easily check
permissions attached to roles and store data only visible on the
controller on user objects a ControllerUser type is introduced which is
linked with the UserManager and can therefore reference role objects
directly.

Resolves #525.
2023-12-02 01:41:43 +01:00

29 lines
923 B
TypeScript

"use strict";
const assert = require("assert").strict;
const lib = require("@clusterio/lib");
describe("lib/data/Role", function() {
describe("class Role", function() {
it("should round trip serialize", function() {
let orig = lib.Role.fromJSON({ id: 11, name: "Role", description: "My Role", permissions: ["test"] });
let copy = lib.Role.fromJSON(orig.toJSON());
assert.deepEqual(copy, orig);
});
describe(".grantDefaultRoles()", function() {
it("should only grant permissions with grantByDefault", function() {
let role = lib.Role.fromJSON({ id: 11, name: "Role", description: "My Role" });
role.grantDefaultPermissions();
assert(role.permissions.size > 0, "No permissions were granted");
for (let permission of role.permissions) {
assert(
lib.permissions.get(permission).grantByDefault === true,
"Non-default permission granted"
);
}
});
});
});
});