Files
beacon-web/tests/api/analytics-client.test.ts
T
n30nex e01c090c8e feat(stats): add hourly traffic and region-aware scope analytics (#53)
Adds the Traffic and Scopes analytics tabs. Includes the hourly traffic work from #52, which this PR contains in full.

Closes #50. Closes #51.
2026-09-20 11:41:43 -04:00

21 lines
1.1 KiB
TypeScript

import { afterEach, expect, it, vi } from "vitest";
import { getStatsObservations, getStatsScopes } from "../../src/api/client";
afterEach(() => vi.unstubAllGlobals());
it("forwards region and cancellation to both aggregate endpoints, omitting an empty global filter", async () => {
const fetcher = vi.fn<typeof fetch>(async () => ({ ok: true, json: async () => [] }) as Response);
vi.stubGlobal("fetch", fetcher);
const controller = new AbortController();
await getStatsScopes(["YVR", "YOW"], controller.signal);
expect(new URL(fetcher.mock.calls[0]![0] as string).searchParams.get("iatas")).toBe("YVR,YOW");
expect(fetcher.mock.calls[0]![1]).toEqual({ signal: controller.signal });
await getStatsScopes([]);
expect(new URL(fetcher.mock.calls[1]![0] as string).searchParams.has("iatas")).toBe(false);
await getStatsObservations(["YOW"], 1234, controller.signal);
const url = new URL(fetcher.mock.calls[2]![0] as string);
expect(url.pathname).toContain("/stats/observations");
expect(url.searchParams.get("since")).toBe("1234");
expect(url.searchParams.get("iatas")).toBe("YOW");
});