87 lines
3.6 KiB
JavaScript
87 lines
3.6 KiB
JavaScript
import { readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const authenticatedRequestMock = vi.hoisted(() => vi.fn());
|
|
|
|
vi.mock("@/components/session/authenticatedRequest.vue", () => ({
|
|
authenticatedRequest: authenticatedRequestMock,
|
|
}));
|
|
|
|
import { Bird } from "@/components/session/token/superUser/modules/bird/Bird.vue";
|
|
import { Config } from "@/components/session/token/superUser/modules/bird/Config.vue";
|
|
|
|
const root = process.cwd();
|
|
const pageSource = readFileSync(
|
|
join(root, "src/views/dashboards/superUserDashboard/configuration/ConfigurationBird.vue"),
|
|
"utf8"
|
|
);
|
|
|
|
describe("Bird module contract", () => {
|
|
beforeEach(() => {
|
|
authenticatedRequestMock.mockReset();
|
|
authenticatedRequestMock.mockResolvedValue({ data: { data: {} } });
|
|
});
|
|
|
|
it("uses the end-user read-only health endpoint for configuration health", async () => {
|
|
await Bird.functions.getHealth();
|
|
|
|
expect(authenticatedRequestMock).toHaveBeenCalledOnce();
|
|
expect(authenticatedRequestMock).toHaveBeenCalledWith("/bird/health", "GET");
|
|
});
|
|
|
|
it("writes the canonical workspaceId while retaining the legacy workplaceId adapter", async () => {
|
|
await Config.keys.workspaceId.set("workspace-canonical");
|
|
await Config.keys.workplaceId.get();
|
|
|
|
expect(authenticatedRequestMock).toHaveBeenNthCalledWith(1, "/bird/config", "POST", {
|
|
variable: "workspaceId",
|
|
value: "workspace-canonical",
|
|
});
|
|
expect(authenticatedRequestMock).toHaveBeenNthCalledWith(2, "/bird/config?variable=workplaceId", "GET");
|
|
});
|
|
|
|
it("exposes protected gateway and channel configuration through typed config keys", async () => {
|
|
await Config.keys.allowed_channel_ids_json.set('["channel-1"]');
|
|
await Config.keys.control_plane_enabled.set(true);
|
|
await Config.keys.webhook_signing_key.set("rotated-secret");
|
|
await Config.keys.participantId.set("participant-1");
|
|
|
|
expect(authenticatedRequestMock).toHaveBeenNthCalledWith(1, "/bird/config", "POST", {
|
|
variable: "allowed_channel_ids_json",
|
|
value: '["channel-1"]',
|
|
});
|
|
expect(authenticatedRequestMock).toHaveBeenNthCalledWith(2, "/bird/config", "POST", {
|
|
variable: "control_plane_enabled",
|
|
value: true,
|
|
});
|
|
expect(authenticatedRequestMock).toHaveBeenNthCalledWith(3, "/bird/config", "POST", {
|
|
variable: "webhook_signing_key",
|
|
value: "rotated-secret",
|
|
});
|
|
expect(authenticatedRequestMock).toHaveBeenNthCalledWith(4, "/bird/config", "POST", {
|
|
variable: "participantId",
|
|
value: "participant-1",
|
|
});
|
|
});
|
|
|
|
it("does not place a fixed-number call from the configuration page", () => {
|
|
expect(pageSource).toContain("getHealth");
|
|
expect(pageSource).not.toContain("getControlPlaneStatus");
|
|
expect(pageSource).toContain('getModuleConfigValue("workspaceId") || getModuleConfigValue("workplaceId")');
|
|
expect(pageSource).toContain("config.keys.workspaceId.set");
|
|
expect(pageSource).toContain("BIRD_SECRET_VARIABLES.has(value.variable)");
|
|
expect(pageSource).toContain("isModuleSecretSet('api_key')");
|
|
expect(pageSource).not.toContain("testOutboundVoiceCall");
|
|
expect(pageSource).not.toContain("console.");
|
|
});
|
|
|
|
it("renders health, disabled, channel, and read-only states through i18n keys", () => {
|
|
expect(pageSource).toContain("configuration.bird.health_title");
|
|
expect(pageSource).toContain("configuration.bird.read_only_health");
|
|
expect(pageSource).toContain("configuration.bird.state.");
|
|
expect(pageSource).toContain("normalizedChannels");
|
|
expect(pageSource).toContain('data-testid="bird-health-state"');
|
|
});
|
|
});
|