mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-10 05:12:14 +00:00
fix(coach): bind the delete journal to the account and record it was sent for
A tab outlives a logout, another login and a switch into a managed profile. A delete re-sent in another scope met a 404 that read as "already gone" and dropped the entry, or tripped the record fence and toasted a failure for a row the person could not see. Entries now carry their owner, only the current owner's are re-sent, and a session end clears the journal with the rest of the session state.
This commit is contained in:
1 parent
c40b21de3d
commit
587ea35d34
6 files changed
+282
-48
No files matched your search
@@ -29,6 +29,12 @@ vi.mock("@/lib/day/last-day", () => ({
|
||||
clearLastDay: () => clearLastDay(),
|
||||
}));
|
||||
|
||||
// Coach deletes the ending session could not confirm belong to its account.
|
||||
const clearCoachDeleteJournal = vi.fn();
|
||||
vi.mock("@/lib/ai/coach/delete-journal", () => ({
|
||||
clearCoachDeleteJournal: () => clearCoachDeleteJournal(),
|
||||
}));
|
||||
|
||||
// `use-auth` pulls in the typed fetch wrapper, the router, and the i18n
|
||||
// context at module load. None of them matter for the pure session-end
|
||||
// helper, so stub them so the import is side-effect free in the test env.
|
||||
@@ -48,6 +54,7 @@ import { clearCachesForSessionEnd } from "../use-auth";
|
||||
afterEach(() => {
|
||||
clearOfflineCachesForSessionEnd.mockClear();
|
||||
clearLastDay.mockClear();
|
||||
clearCoachDeleteJournal.mockClear();
|
||||
});
|
||||
|
||||
describe("clearCachesForSessionEnd — cross-user in-memory wipe", () => {
|
||||
@@ -80,4 +87,9 @@ describe("clearCachesForSessionEnd — cross-user in-memory wipe", () => {
|
||||
clearCachesForSessionEnd(new QueryClient());
|
||||
expect(clearLastDay).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("clears the Coach delete journal", () => {
|
||||
clearCachesForSessionEnd(new QueryClient());
|
||||
expect(clearCoachDeleteJournal).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
@@ -28,6 +28,7 @@ import type { ModuleAccessState } from "@/lib/sharing/module-disclosure";
|
||||
import type { OnboardingStateDto } from "@/lib/onboarding/needs";
|
||||
import type { TourProgress } from "@/lib/onboarding/tour-progress";
|
||||
import { clearLastDay } from "@/lib/day/last-day";
|
||||
import { clearCoachDeleteJournal } from "@/lib/ai/coach/delete-journal";
|
||||
import { clearOfflineCachesForSessionEnd } from "@/lib/pwa/query-persister";
|
||||
import {
|
||||
setRecordScope,
|
||||
@@ -624,6 +625,9 @@ export function clearCachesForSessionEnd(queryClient: QueryClient): void {
|
||||
clearWasAuthenticated();
|
||||
// The day the layer last showed is a date of this account's record.
|
||||
clearLastDay();
|
||||
// Coach deletes this session could not confirm belong to its account; the
|
||||
// next one must not re-send them against its own record.
|
||||
clearCoachDeleteJournal();
|
||||
void clearOfflineCachesForSessionEnd();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user