mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 23:33:29 +00:00
fix(integrations): a provider with no history is "unknown"
The ledger's synthetic "no row" snapshot returned `state: "connected"`, so the field's default meant the opposite of its name: every account that had never connected a provider published `connected` on the status envelope. Settings survived it by never reading `state`; the setup flow's connect step did read it, and told brand-new accounts their wearable was connected. The snapshot now reads `unknown`. `syncHealth.verdict` is unchanged and stays the only liveness truth; the managed-record projection maps `unknown` onto `disconnected` the way it already maps a missing connection.
This commit is contained in:
1 parent
274923a060
commit
0bdbf009f6
8 files changed
+126
-23
No files matched your search
@@ -60,6 +60,7 @@ const whoopFind = prisma.whoopConnection.findUnique as ReturnType<typeof vi.fn>;
|
||||
|
||||
type Entry = {
|
||||
integration: string;
|
||||
state?: string;
|
||||
connected?: boolean;
|
||||
configured?: boolean;
|
||||
available?: boolean;
|
||||
@@ -344,3 +345,41 @@ describe("/api/integrations/status — the freshness read failed", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* v1.38.19 (wave B / I5) — the never-connected provider on the wire.
|
||||
*
|
||||
* The ledger's synthetic "no row" snapshot reads `unknown`, and the envelope
|
||||
* publishes it verbatim. A client that reads `state` must see a value that
|
||||
* cannot be mistaken for a live connection, while `syncHealth.verdict` keeps
|
||||
* saying `disconnected` for the same entry.
|
||||
*/
|
||||
describe("/api/integrations/status — a provider with no ledger row", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
for (const key of Object.keys(perIntegrationLedger)) {
|
||||
delete perIntegrationLedger[key];
|
||||
}
|
||||
polarAvailable.mockResolvedValue(true);
|
||||
ouraAvailable.mockResolvedValue(false);
|
||||
});
|
||||
|
||||
it("publishes state unknown beside connected false and a disconnected verdict", async () => {
|
||||
perIntegrationLedger.whoop = {
|
||||
state: "unknown",
|
||||
lastSuccessAt: null,
|
||||
lastAttemptAt: null,
|
||||
lastError: null,
|
||||
failingSince: null,
|
||||
};
|
||||
userFind.mockResolvedValue({});
|
||||
whoopFind.mockResolvedValue(null);
|
||||
|
||||
const whoop = (await fetchEntries()).find(
|
||||
(e) => e.integration === "whoop",
|
||||
)!;
|
||||
expect(whoop.state).toBe("unknown");
|
||||
expect(whoop.connected).toBe(false);
|
||||
expect(whoop.syncHealth?.verdict).toBe("disconnected");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user