mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 07:32:44 +00:00
refactor(zalouser): extract policy and message helpers
This commit is contained in:
49
extensions/zalouser/src/group-policy.test.ts
Normal file
49
extensions/zalouser/src/group-policy.test.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildZalouserGroupCandidates,
|
||||
findZalouserGroupEntry,
|
||||
isZalouserGroupEntryAllowed,
|
||||
normalizeZalouserGroupSlug,
|
||||
} from "./group-policy.js";
|
||||
|
||||
describe("zalouser group policy helpers", () => {
|
||||
it("normalizes group slug names", () => {
|
||||
expect(normalizeZalouserGroupSlug(" Team Alpha ")).toBe("team-alpha");
|
||||
expect(normalizeZalouserGroupSlug("#Roadmap Updates")).toBe("roadmap-updates");
|
||||
});
|
||||
|
||||
it("builds ordered candidates with optional aliases", () => {
|
||||
expect(
|
||||
buildZalouserGroupCandidates({
|
||||
groupId: "123",
|
||||
groupChannel: "chan-1",
|
||||
groupName: "Team Alpha",
|
||||
includeGroupIdAlias: true,
|
||||
}),
|
||||
).toEqual(["123", "group:123", "chan-1", "Team Alpha", "team-alpha", "*"]);
|
||||
});
|
||||
|
||||
it("finds the first matching group entry", () => {
|
||||
const groups = {
|
||||
"group:123": { allow: true },
|
||||
"team-alpha": { requireMention: false },
|
||||
"*": { requireMention: true },
|
||||
};
|
||||
const entry = findZalouserGroupEntry(
|
||||
groups,
|
||||
buildZalouserGroupCandidates({
|
||||
groupId: "123",
|
||||
groupName: "Team Alpha",
|
||||
includeGroupIdAlias: true,
|
||||
}),
|
||||
);
|
||||
expect(entry).toEqual({ allow: true });
|
||||
});
|
||||
|
||||
it("evaluates allow/enable flags", () => {
|
||||
expect(isZalouserGroupEntryAllowed({ allow: true, enabled: true })).toBe(true);
|
||||
expect(isZalouserGroupEntryAllowed({ allow: false })).toBe(false);
|
||||
expect(isZalouserGroupEntryAllowed({ enabled: false })).toBe(false);
|
||||
expect(isZalouserGroupEntryAllowed(undefined)).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user