fix(strava): clear the backfill markers when the connection is removed

Disconnecting Strava, or deleting its credentials, cleared the tokens
and the athlete but kept stravaBackfillCompletedAt and
stravaBackfillResumeBefore. A later connection inherited them: a
completed marker kept its history from being read, and a resume point
started its first walk below the previous account's oldest activity.
Both paths now clear one shared set of columns.
This commit is contained in:
Marc-André Bombeck committed 2026-10-20 11:02:50 +02:00
1 parent 742705eadd
commit bd00845be3
5 files changed
+95 -13

No files matched your search

@@ -27,7 +27,10 @@ const { storeMock, clearMock } = vi.hoisted(() => ({
storeMock: vi.fn(),
clearMock: vi.fn(),
}));
vi.mock("@/lib/strava/credentials", () => ({
vi.mock("@/lib/strava/credentials", async (importOriginal) => ({
STRAVA_DISCONNECTED: (
await importOriginal<typeof import("@/lib/strava/credentials")>()
).STRAVA_DISCONNECTED,
storeStravaClientCredentials: storeMock,
clearStravaClientCredentials: clearMock,
}));
@@ -80,14 +83,18 @@ describe("DELETE /api/strava/credentials", () => {
expect(markDisconnected).toHaveBeenCalledWith("u1", "strava");
});
it("clears the athlete id alongside both tokens", async () => {
it("clears the athlete id and the backfill state alongside both tokens", async () => {
await del();
// The backfill markers belong to the account that was connected; a later
// connection must start its own history walk from the newest activity.
expect(userUpdate).toHaveBeenCalledWith(
expect.objectContaining({
data: {
stravaAccessTokenEncrypted: null,
stravaRefreshTokenEncrypted: null,
stravaAthleteId: null,
stravaBackfillCompletedAt: null,
stravaBackfillResumeBefore: null,
},
}),
);
+2 -5
View File
@@ -12,6 +12,7 @@ import { markDisconnected } from "@/lib/integrations/status";
import {
storeStravaClientCredentials,
clearStravaClientCredentials,
STRAVA_DISCONNECTED,
} from "@/lib/strava/credentials";
import { stravaCredentialsSchema } from "@/lib/validations/strava";
import { NextRequest } from "next/server";
@@ -98,11 +99,7 @@ export const DELETE = apiHandler(async () => {
await prisma.user.update({
where: { id: user.id },
data: {
stravaAccessTokenEncrypted: null,
stravaRefreshTokenEncrypted: null,
stravaAthleteId: null,
},
data: STRAVA_DISCONNECTED,
});
await clearStravaClientCredentials(user.id);