mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 22:26:13 +00:00
fix(insights): scope generation guard to prompt fields, clear cache on restore
This commit is contained in:
1 parent
666a85d311
commit
3aff2c16db
104 files changed
+8082
-651
No files matched your search
@@ -3,6 +3,13 @@ import { renderToStaticMarkup } from "react-dom/server";
|
||||
import de from "../../../../messages/de.json";
|
||||
import en from "../../../../messages/en.json";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
mutationOptions: [] as Array<{
|
||||
onSuccess?: (data: { summary: Record<string, number> }) => void;
|
||||
}>,
|
||||
toastSuccess: vi.fn(),
|
||||
}));
|
||||
|
||||
/**
|
||||
* v1.4.15 phase-C5 — `/admin/backups` empty state.
|
||||
*
|
||||
@@ -18,6 +25,13 @@ vi.mock("next/navigation", () => ({
|
||||
usePathname: () => "/admin/backups",
|
||||
}));
|
||||
|
||||
vi.mock("sonner", () => ({
|
||||
toast: {
|
||||
success: mocks.toastSuccess,
|
||||
error: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@tanstack/react-query", () => ({
|
||||
useQuery: () => ({
|
||||
data: { rows: [], retentionDays: 30 },
|
||||
@@ -25,14 +39,21 @@ vi.mock("@tanstack/react-query", () => ({
|
||||
isError: false,
|
||||
}),
|
||||
useQueryClient: () => ({ invalidateQueries: vi.fn() }),
|
||||
useMutation: () => ({
|
||||
mutate: vi.fn(),
|
||||
mutateAsync: vi.fn(),
|
||||
isPending: false,
|
||||
isError: false,
|
||||
error: null,
|
||||
variables: undefined,
|
||||
}),
|
||||
useMutation: (options: unknown) => {
|
||||
mocks.mutationOptions.push(
|
||||
options as {
|
||||
onSuccess?: (data: { summary: Record<string, number> }) => void;
|
||||
},
|
||||
);
|
||||
return {
|
||||
mutate: vi.fn(),
|
||||
mutateAsync: vi.fn(),
|
||||
isPending: false,
|
||||
isError: false,
|
||||
error: null,
|
||||
variables: undefined,
|
||||
};
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/hooks/use-auth", () => ({
|
||||
@@ -107,3 +128,27 @@ describe("BackupsSection — empty state", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("BackupsSection — upload outcome", () => {
|
||||
it("includes health profile fact revisions in the restored record total", () => {
|
||||
mocks.toastSuccess.mockClear();
|
||||
const firstMutation = mocks.mutationOptions.length;
|
||||
render();
|
||||
const uploadOutcome = mocks.mutationOptions[firstMutation + 1]?.onSuccess;
|
||||
expect(uploadOutcome).toBeTypeOf("function");
|
||||
|
||||
uploadOutcome!({
|
||||
summary: {
|
||||
measurements: 1,
|
||||
medications: 2,
|
||||
intakeEvents: 3,
|
||||
moodEntries: 4,
|
||||
healthProfileFactRevisions: 5,
|
||||
},
|
||||
});
|
||||
|
||||
expect(mocks.toastSuccess).toHaveBeenCalledWith(
|
||||
expect.stringContaining("15"),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -244,6 +244,7 @@ export function BackupsSection() {
|
||||
// nothing rather than break the count.
|
||||
nutrientDays?: number;
|
||||
healthProfile?: number;
|
||||
healthProfileFactRevisions?: number;
|
||||
customMetrics?: number;
|
||||
customMetricEntries?: number;
|
||||
intradayProfiles?: number;
|
||||
@@ -272,6 +273,7 @@ export function BackupsSection() {
|
||||
// held — a smaller version of the same defect, on the reporting side.
|
||||
(data.summary.nutrientDays ?? 0) +
|
||||
(data.summary.healthProfile ?? 0) +
|
||||
(data.summary.healthProfileFactRevisions ?? 0) +
|
||||
(data.summary.customMetrics ?? 0) +
|
||||
(data.summary.customMetricEntries ?? 0) +
|
||||
(data.summary.intradayProfiles ?? 0);
|
||||
|
||||
Reference in new issue
Block a user