|
| 1 | +import { describe, it } from "vitest"; |
| 2 | +import { whatsappAccessControlTesting } from "../../../../extensions/whatsapp/api.js"; |
| 3 | +import { resolveZaloRuntimeGroupPolicy } from "../../../../extensions/zalo/api.js"; |
| 4 | +import { |
| 5 | + expectResolvedGroupPolicyCase, |
| 6 | + installChannelRuntimeGroupPolicyFallbackSuite, |
| 7 | +} from "../../../../test/helpers/channels/group-policy-contract-suites.js"; |
| 8 | +import { resolveOpenProviderRuntimeGroupPolicy } from "../../../config/runtime-group-policy.js"; |
| 9 | + |
| 10 | +type ResolvedGroupPolicy = ReturnType<typeof resolveOpenProviderRuntimeGroupPolicy>; |
| 11 | + |
| 12 | +function expectResolvedDiscordGroupPolicyCase(params: { |
| 13 | + providerConfigPresent: Parameters< |
| 14 | + typeof resolveOpenProviderRuntimeGroupPolicy |
| 15 | + >[0]["providerConfigPresent"]; |
| 16 | + groupPolicy: Parameters<typeof resolveOpenProviderRuntimeGroupPolicy>[0]["groupPolicy"]; |
| 17 | + expected: Pick<ResolvedGroupPolicy, "groupPolicy" | "providerMissingFallbackApplied">; |
| 18 | +}) { |
| 19 | + expectResolvedGroupPolicyCase(resolveOpenProviderRuntimeGroupPolicy(params), params.expected); |
| 20 | +} |
| 21 | + |
| 22 | +describe("channel runtime group policy fallback contract", () => { |
| 23 | + describe("slack", () => { |
| 24 | + installChannelRuntimeGroupPolicyFallbackSuite({ |
| 25 | + resolve: resolveOpenProviderRuntimeGroupPolicy, |
| 26 | + configuredLabel: "keeps open default when channels.slack is configured", |
| 27 | + defaultGroupPolicyUnderTest: "open", |
| 28 | + missingConfigLabel: "fails closed when channels.slack is missing and no defaults are set", |
| 29 | + missingDefaultLabel: "ignores explicit global defaults when provider config is missing", |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + describe("telegram", () => { |
| 34 | + installChannelRuntimeGroupPolicyFallbackSuite({ |
| 35 | + resolve: resolveOpenProviderRuntimeGroupPolicy, |
| 36 | + configuredLabel: "keeps open fallback when channels.telegram is configured", |
| 37 | + defaultGroupPolicyUnderTest: "disabled", |
| 38 | + missingConfigLabel: "fails closed when channels.telegram is missing and no defaults are set", |
| 39 | + missingDefaultLabel: "ignores explicit defaults when provider config is missing", |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + describe("whatsapp", () => { |
| 44 | + installChannelRuntimeGroupPolicyFallbackSuite({ |
| 45 | + resolve: whatsappAccessControlTesting.resolveWhatsAppRuntimeGroupPolicy, |
| 46 | + configuredLabel: "keeps open fallback when channels.whatsapp is configured", |
| 47 | + defaultGroupPolicyUnderTest: "disabled", |
| 48 | + missingConfigLabel: "fails closed when channels.whatsapp is missing and no defaults are set", |
| 49 | + missingDefaultLabel: "ignores explicit global defaults when provider config is missing", |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + describe("imessage", () => { |
| 54 | + installChannelRuntimeGroupPolicyFallbackSuite({ |
| 55 | + resolve: resolveOpenProviderRuntimeGroupPolicy, |
| 56 | + configuredLabel: "keeps open fallback when channels.imessage is configured", |
| 57 | + defaultGroupPolicyUnderTest: "disabled", |
| 58 | + missingConfigLabel: "fails closed when channels.imessage is missing and no defaults are set", |
| 59 | + missingDefaultLabel: "ignores explicit global defaults when provider config is missing", |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + describe("discord", () => { |
| 64 | + installChannelRuntimeGroupPolicyFallbackSuite({ |
| 65 | + resolve: resolveOpenProviderRuntimeGroupPolicy, |
| 66 | + configuredLabel: "keeps open default when channels.discord is configured", |
| 67 | + defaultGroupPolicyUnderTest: "open", |
| 68 | + missingConfigLabel: "fails closed when channels.discord is missing and no defaults are set", |
| 69 | + missingDefaultLabel: "ignores explicit global defaults when provider config is missing", |
| 70 | + }); |
| 71 | + |
| 72 | + it.each([ |
| 73 | + { |
| 74 | + providerConfigPresent: false, |
| 75 | + groupPolicy: "disabled", |
| 76 | + expected: { |
| 77 | + groupPolicy: "disabled", |
| 78 | + providerMissingFallbackApplied: false, |
| 79 | + }, |
| 80 | + }, |
| 81 | + ] as const)("respects explicit provider policy %#", (testCase) => { |
| 82 | + expectResolvedDiscordGroupPolicyCase(testCase); |
| 83 | + }); |
| 84 | + }); |
| 85 | + |
| 86 | + describe("zalo", () => { |
| 87 | + installChannelRuntimeGroupPolicyFallbackSuite({ |
| 88 | + resolve: resolveZaloRuntimeGroupPolicy, |
| 89 | + configuredLabel: "keeps open fallback when channels.zalo is configured", |
| 90 | + defaultGroupPolicyUnderTest: "open", |
| 91 | + missingConfigLabel: "fails closed when channels.zalo is missing and no defaults are set", |
| 92 | + missingDefaultLabel: "ignores explicit global defaults when provider config is missing", |
| 93 | + }); |
| 94 | + }); |
| 95 | +}); |
0 commit comments