Files
factorio-clusterio/test/lib/users.js
T
Hornwitser 5dcaca4d0b Migrate to ECMAScript Modules
Migrate the usage of CommonJS specific code and imports to ESM.  Roughly
summarised this:
- Changes all require() calls to import statement or expressions.
- Changes usage of module.exports to export statements.
- Replaces require.resolve with import.meta.resolve.
- Replaces conditional imports with conditional subpath imports.
- Replaces module === require.main with import.meta.main.
- Adds the full filename with extention to all relative imports.
- Changes all usage of __dirname and __filename to their import.meta
  equivalents.
- Sets "type": "module" in package.json files.
- Removes usage of "use strict".
- Adds .ts an an alias of .js for the webpack build.

Due to differences in how require and import resolves files the plugin
entrypoints will have to include the filename and extension after this
migration in order to work.
2026-09-11 22:43:57 +02:00

47 lines
1.6 KiB
JavaScript

import assert from "node:assert/strict";
import * as lib from "@clusterio/lib";
describe("lib/users", function() {
describe("definePermission()", function() {
it("should validate the types of its arguments", function() {
assert.throws(
() => lib.definePermission({ name: 123, title: "Test", description: "A test" }),
new Error("Expected name to be a non-empty string")
);
assert.throws(
() => lib.definePermission({ name: "test", title: 123, description: "A test" }),
new Error("Expected title to be a non-empty string")
);
assert.throws(
() => lib.definePermission({ name: "test", title: "Test", description: 123 }),
new Error("Expected description to be a non-empty string")
);
assert.throws(
() => lib.definePermission({
name: "test", title: "Test", description: "A test", grantByDefault: 1,
}),
new Error("Expected grantByDefault to be a boolean")
);
});
it("should define a permission", function() {
lib.definePermission({ name: "test", title: "Test", description: "A test" });
assert(lib.permissions.has("test"), "Permission was not defined");
let test = lib.permissions.get("test");
assert.equal(test.name, "test");
assert.equal(test.title, "Test");
assert.equal(test.description, "A test");
assert.equal(test.grantByDefault, false);
});
it("should throw on already defined permission", function() {
assert.throws(
() => lib.definePermission({ name: "test", title: "Test", description: "A test" }),
new Error("Permission 'test' is already defined")
);
});
});
});