feat(integrations): unify OAuth returns and the status envelope

The WHOOP and Fitbit OAuth callbacks redirect back with
`?whoop=connected|error` / `?fitbit=connected|error`, but the settings page
only read that param for Withings, Polar and Oura — a user returning from a
WHOOP or Fitbit round-trip landed on a silently unchanged page with no toast.
Extend the generic return handler to all four OAuth providers, add the
matching connected/failed/error i18n keys across every locale, and invalidate
both the per-card key and the consolidated envelope on a successful return.

Polar and Oura already write the shared IntegrationKey ledger but each fired
its own `/api/<provider>/status` round-trip from the card, so the page issued
one consolidated request plus three per-card ones. Fold Polar and Oura into
`/api/integrations/status` and let the cards read a passed view-model instead
of fetching, retiring the extra round-trips. The per-provider status routes
stay for the iOS and test callers.
This commit is contained in:
Marc-André Bombeck committed 2026-06-15 01:34:30 +02:00
1 parent 38a2c7127e
commit 9430e89889
15 files changed
+583 -42

No files matched your search

@@ -23,7 +23,13 @@ vi.mock("@tanstack/react-query", () => ({
import { I18nProvider } from "@/lib/i18n/context";
import { OAuthProviderCard } from "../oauth-provider-card";
function render({ credentials = false }: { credentials?: boolean } = {}) {
function render({
credentials = false,
viewModel,
}: {
credentials?: boolean;
viewModel?: Parameters<typeof OAuthProviderCard>[0]["viewModel"];
} = {}) {
return renderToStaticMarkup(
<I18nProvider initialLocale="en">
<OAuthProviderCard
@@ -33,6 +39,7 @@ function render({ credentials = false }: { credentials?: boolean } = {}) {
icon={Watch}
dataHref="/insights/sleep"
credentials={credentials}
viewModel={viewModel}
/>
</I18nProvider>,
);
@@ -74,6 +81,25 @@ describe("OAuthProviderCard — parked + test + data-link parity", () => {
expect(html).toContain('href="/insights/sleep"');
});
it("reads off the passed view-model instead of the per-card fetch (04-M2)", () => {
// The per-card useQuery mock returns null; the card must render the
// connected state from the supplied envelope view-model alone, proving the
// /api/<provider>/status round-trip is no longer the source.
statusPayload = null;
const html = render({
viewModel: {
connected: true,
configured: true,
available: true,
state: "connected",
lastSuccessAt: "2026-06-01T00:00:00.000Z",
lastError: null,
},
});
expect(html).toContain('data-testid="polar-data-link"');
expect(html).toContain("Test connection");
});
it("does not render the data link or test button when disconnected", () => {
statusPayload = {
connected: false,