fix: resolve type errors across test suite

This commit is contained in:
2026-02-26 12:49:04 -06:00
parent 827b018f25
commit 51eb36f4a6
26 changed files with 2847 additions and 0 deletions
+92
View File
@@ -0,0 +1,92 @@
import { describe, test, expect } from "bun:test";
/**
* Tests for the PermissionNodes type definitions and structure.
* We import the permission nodes and validate the shape of the data.
*/
import { PERMISSION_NODES } from "../../src/types/PermissionNodes";
import type {
PermissionNode,
PermissionCategory,
} from "../../src/types/PermissionNodes";
describe("PermissionNodes", () => {
test("PERMISSION_NODES is defined and is an object", () => {
expect(PERMISSION_NODES).toBeDefined();
expect(typeof PERMISSION_NODES).toBe("object");
});
test("has required top-level categories", () => {
expect(PERMISSION_NODES).toHaveProperty("global");
expect(PERMISSION_NODES).toHaveProperty("company");
expect(PERMISSION_NODES).toHaveProperty("credential");
});
test("each category has name, description, and permissions", () => {
for (const [key, category] of Object.entries(PERMISSION_NODES)) {
const cat = category as PermissionCategory;
expect(cat).toHaveProperty("name");
expect(typeof cat.name).toBe("string");
expect(cat).toHaveProperty("description");
expect(typeof cat.description).toBe("string");
expect(cat).toHaveProperty("permissions");
expect(Array.isArray(cat.permissions)).toBe(true);
}
});
test("each permission node has required fields", () => {
for (const [_key, category] of Object.entries(PERMISSION_NODES)) {
const cat = category as PermissionCategory;
for (const perm of cat.permissions) {
expect(perm).toHaveProperty("node");
expect(typeof perm.node).toBe("string");
expect(perm.node.length).toBeGreaterThan(0);
expect(perm).toHaveProperty("description");
expect(typeof perm.description).toBe("string");
expect(perm).toHaveProperty("usedIn");
expect(Array.isArray(perm.usedIn)).toBe(true);
}
}
});
test("global category contains the wildcard * node", () => {
const globalPerms = (PERMISSION_NODES.global as PermissionCategory)
.permissions;
const wildcard = globalPerms.find((p) => p.node === "*");
expect(wildcard).toBeDefined();
expect(wildcard!.description).toContain("Full access");
});
test("all permission nodes are non-empty strings", () => {
for (const [_key, category] of Object.entries(PERMISSION_NODES)) {
const cat = category as PermissionCategory;
for (const perm of cat.permissions) {
expect(typeof perm.node).toBe("string");
expect(perm.node.length).toBeGreaterThan(0);
}
}
});
test("dependencies reference existing permission nodes", () => {
// Collect all nodes
const allNodes = new Set<string>();
for (const [_key, category] of Object.entries(PERMISSION_NODES)) {
const cat = category as PermissionCategory;
for (const perm of cat.permissions) {
allNodes.add(perm.node);
}
}
// Check all dependencies point to real nodes
for (const [_key, category] of Object.entries(PERMISSION_NODES)) {
const cat = category as PermissionCategory;
for (const perm of cat.permissions) {
if (perm.dependencies) {
for (const dep of perm.dependencies) {
expect(allNodes.has(dep)).toBe(true);
}
}
}
}
});
});