56 lines
2.0 KiB
TypeScript
56 lines
2.0 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
|
|
import { aircallAdapter, aircallTelephonyProvider } from "./adapter.js";
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
describe("Aircall adapters", () => {
|
|
it("registers an OAuth Apps Engine adapter without a refresh-token contract", () => {
|
|
expect(aircallAdapter).toMatchObject({ key: "aircall", connectionType: "oauth2" });
|
|
expect(aircallAdapter.refreshToken).toBeUndefined();
|
|
});
|
|
|
|
it("exposes the provider-neutral telephony operations", () => {
|
|
expect(aircallTelephonyProvider.key).toBe("aircall");
|
|
expect(aircallTelephonyProvider).toMatchObject({
|
|
connect: expect.any(Function),
|
|
disconnect: expect.any(Function),
|
|
listUsers: expect.any(Function),
|
|
listProviderUsers: expect.any(Function),
|
|
probe: expect.any(Function),
|
|
listUserNumbers: expect.any(Function),
|
|
startCall: expect.any(Function),
|
|
triggerOutboundCall: expect.any(Function),
|
|
createWebhook: expect.any(Function),
|
|
subscribeToWebhooks: expect.any(Function),
|
|
deleteWebhook: expect.any(Function),
|
|
validateWebhook: expect.any(Function),
|
|
parseWebhookEvent: expect.any(Function),
|
|
normalizeWebhook: expect.any(Function),
|
|
getRecordingUrl: expect.any(Function),
|
|
});
|
|
});
|
|
|
|
it("probes V1 ping and maps a valid permanent bearer token to active", async () => {
|
|
const fetchMock = vi.fn().mockResolvedValue(new Response(null, { status: 204 }));
|
|
vi.stubGlobal("fetch", fetchMock);
|
|
|
|
await expect(aircallAdapter.validateConnection({ accessToken: "permanent-token" })).resolves.toEqual({
|
|
ok: true,
|
|
health: "active",
|
|
messageKey: "telephony.health.active",
|
|
});
|
|
expect(new URL(String(fetchMock.mock.calls[0]?.[0])).pathname).toBe("/v1/ping");
|
|
});
|
|
|
|
it("maps a missing token to a Klartext-ready broken state", async () => {
|
|
await expect(aircallAdapter.healthCheck({ accessToken: null })).resolves.toEqual({
|
|
ok: false,
|
|
health: "broken",
|
|
messageKey: "telephony.health.tokenInvalid",
|
|
});
|
|
});
|
|
});
|