refactor: share teams allowlist matching helpers
Co-authored-by: thewilloftheshadow <thewilloftheshadow@users.noreply.github.com>
This commit is contained in:
@@ -2,8 +2,10 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
buildChannelKeyCandidates,
|
||||
normalizeChannelSlug,
|
||||
resolveChannelEntryMatch,
|
||||
resolveChannelEntryMatchWithFallback,
|
||||
resolveNestedAllowlistDecision,
|
||||
} from "./channel-config.js";
|
||||
|
||||
describe("buildChannelKeyCandidates", () => {
|
||||
@@ -12,6 +14,14 @@ describe("buildChannelKeyCandidates", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("normalizeChannelSlug", () => {
|
||||
it("normalizes names into slugs", () => {
|
||||
expect(normalizeChannelSlug("My Team")).toBe("my-team");
|
||||
expect(normalizeChannelSlug("#General Chat")).toBe("general-chat");
|
||||
expect(normalizeChannelSlug(" Dev__Chat ")).toBe("dev-chat");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveChannelEntryMatch", () => {
|
||||
it("returns matched entry and wildcard metadata", () => {
|
||||
const entries = { a: { allow: true }, "*": { allow: false } };
|
||||
@@ -66,4 +76,59 @@ describe("resolveChannelEntryMatchWithFallback", () => {
|
||||
expect(match.matchSource).toBe("wildcard");
|
||||
expect(match.matchKey).toBe("*");
|
||||
});
|
||||
|
||||
it("matches normalized keys when normalizeKey is provided", () => {
|
||||
const entries = { "My Team": { allow: true } };
|
||||
const match = resolveChannelEntryMatchWithFallback({
|
||||
entries,
|
||||
keys: ["my-team"],
|
||||
normalizeKey: normalizeChannelSlug,
|
||||
});
|
||||
expect(match.entry).toBe(entries["My Team"]);
|
||||
expect(match.matchSource).toBe("direct");
|
||||
expect(match.matchKey).toBe("My Team");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveNestedAllowlistDecision", () => {
|
||||
it("allows when outer allowlist is disabled", () => {
|
||||
expect(
|
||||
resolveNestedAllowlistDecision({
|
||||
outerConfigured: false,
|
||||
outerMatched: false,
|
||||
innerConfigured: false,
|
||||
innerMatched: false,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("blocks when outer allowlist is configured but missing match", () => {
|
||||
expect(
|
||||
resolveNestedAllowlistDecision({
|
||||
outerConfigured: true,
|
||||
outerMatched: false,
|
||||
innerConfigured: false,
|
||||
innerMatched: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("requires inner match when inner allowlist is configured", () => {
|
||||
expect(
|
||||
resolveNestedAllowlistDecision({
|
||||
outerConfigured: true,
|
||||
outerMatched: true,
|
||||
innerConfigured: true,
|
||||
innerMatched: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
expect(
|
||||
resolveNestedAllowlistDecision({
|
||||
outerConfigured: true,
|
||||
outerMatched: true,
|
||||
innerConfigured: true,
|
||||
innerMatched: true,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user