test(integrations): cover the health field on the status routes

This commit is contained in:
Marc-André Bombeck committed 2026-10-15 11:15:06 +02:00
1 parent 8162afc0e1
commit f2646bc186
4 files changed
+49

No files matched your search

@@ -5,6 +5,9 @@ vi.mock("@/lib/api-handler", () => ({
requireAuth: vi.fn(async () => ({ user: { id: "u1" } })),
}));
vi.mock("@/lib/integrations/connection-health-load", () => ({
loadConnectionHealth: vi.fn().mockResolvedValue({}),
}));
vi.mock("@/lib/db", () => ({
prisma: {
user: { findUnique: vi.fn() },
@@ -444,3 +447,40 @@ describe("/api/integrations/status — what a provider withholds by contract", (
).toEqual([]);
});
});
describe("/api/integrations/status — the unified connection health", () => {
beforeEach(() => {
vi.clearAllMocks();
for (const key of Object.keys(perIntegrationLedger)) {
delete perIntegrationLedger[key];
}
});
it("puts each provider's resolved health on its own entry, null where not connected", async () => {
const { loadConnectionHealth } =
await import("@/lib/integrations/connection-health-load");
const ouraHealth = { state: "limited", reason: "permission_limited" };
vi.mocked(loadConnectionHealth).mockResolvedValueOnce({
withings: null,
whoop: null,
fitbit: null,
"google-health": null,
polar: null,
oura: ouraHealth,
strava: null,
nightscout: null,
"apple-health": null,
} as never);
userFind.mockResolvedValue({ ouraAccessTokenEncrypted: "tok" });
const entries = (await fetchEntries()) as Array<
Entry & { health?: unknown }
>;
expect(entries.find((e) => e.integration === "oura")?.health).toEqual(
ouraHealth,
);
for (const entry of entries.filter((e) => e.integration !== "oura")) {
expect(entry.health).toBeNull();
}
});
});
@@ -5,6 +5,9 @@ vi.mock("@/lib/api-handler", () => ({
requireAuth: vi.fn(async () => ({ user: { id: "u1" } })),
}));
vi.mock("@/lib/integrations/connection-health-load", () => ({
loadOneConnectionHealth: vi.fn().mockResolvedValue(null),
}));
vi.mock("@/lib/db", () => ({
prisma: { user: { findUnique: vi.fn() } },
}));
@@ -5,6 +5,9 @@ vi.mock("@/lib/api-handler", () => ({
requireAuth: vi.fn(async () => ({ user: { id: "u1" } })),
}));
vi.mock("@/lib/integrations/connection-health-load", () => ({
loadOneConnectionHealth: vi.fn().mockResolvedValue(null),
}));
vi.mock("@/lib/db", () => ({
prisma: { user: { findUnique: vi.fn() } },
}));
@@ -5,6 +5,9 @@ vi.mock("@/lib/api-handler", () => ({
requireAuth: vi.fn(async () => ({ user: { id: "u1" } })),
}));
vi.mock("@/lib/integrations/connection-health-load", () => ({
loadOneConnectionHealth: vi.fn().mockResolvedValue(null),
}));
vi.mock("@/lib/db", () => ({
prisma: {
user: { findUnique: vi.fn() },