mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
test(integrations): cover the health field on the status routes
This commit is contained in:
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() },
|
||||
|
||||
Reference in new issue
Block a user