Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

fix(dashboard): count goal streaks against defaults when settings JSON is malformed

Khuram Niaz2a74fbe7bc90
diff --git a/__tests__/dailyGoals.actions.spec.ts b/__tests__/dailyGoals.actions.spec.ts
index c26d6f7..720ec39 100644
--- a/__tests__/dailyGoals.actions.spec.ts
+++ b/__tests__/dailyGoals.actions.spec.ts
@@ -323,6 +323,22 @@ describe("getGoalStreaks", () => {
});
});
+ it("counts against defaults when the settings JSON is malformed", async () => {
+ (prisma.userSettings.findUnique as any).mockResolvedValue({
+ settings: '{"ai":',
+ });
+ (prisma.job.groupBy as any).mockResolvedValue([
+ { appliedDate: new Date(2026, 9, 5, 9), _count: { _all: 5 } },
+ ]);
+ (prisma.activity.findMany as any).mockResolvedValue([
+ { startTime: new Date(2026, 9, 5, 10), duration: 240 },
+ ]);
+ expect(await getGoalStreaks()).toEqual({
+ success: true,
+ data: { current: 1, best: 1 },
+ });
+ });
+
it("returns a failure when not signed in", async () => {
(getCurrentUser as any).mockResolvedValue(null);
expect(await getGoalStreaks()).toEqual({
diff --git a/src/actions/dailyGoals.actions.ts b/src/actions/dailyGoals.actions.ts
index 33ef4da..4e1d957 100644
--- a/src/actions/dailyGoals.actions.ts
+++ b/src/actions/dailyGoals.actions.ts
@@ -55,6 +55,18 @@ async function loadStoredTargets(userId: string): Promise<{
return { settings, targets: parseStoredTargets(settings?.goals?.targets) };
}
+// Corrupt settings JSON must not hide values or streaks; targets use defaults
+async function loadTargetsOrDefaults(
+ userId: string,
+): Promise<GoalTargetsByMonth> {
+ try {
+ return (await loadStoredTargets(userId)).targets;
+ } catch (error) {
+ if (error instanceof SyntaxError) return {};
+ throw error;
+ }
+}
+
async function computeStreaks(
userId: string,
targets: GoalTargetsByMonth,
@@ -73,7 +85,7 @@ export async function getGoalStreaks(): Promise<
> {
try {
const user = await requireUser();
- const { targets } = await loadStoredTargets(user.id);
+ const targets = await loadTargetsOrDefaults(user.id);
return { success: true, data: await computeStreaks(user.id, targets) };
} catch (error) {
const { message } = handleError(error, "Failed to load goal streaks.");
@@ -94,13 +106,9 @@ export async function getDailyGoalValues(
return { success: false, message: "Invalid month." };
}
const { start, end } = monthBounds(month);
- const [values, { targets }] = await Promise.all([
+ const [values, targets] = await Promise.all([
loadGoalValues(user.id, start, end),
- // Corrupt settings JSON must not hide the values; targets use defaults
- loadStoredTargets(user.id).catch((error) => {
- if (error instanceof SyntaxError) return { targets: {} };
- throw error;
- }),
+ loadTargetsOrDefaults(user.id),
]);
return { success: true, data: { values, targets } };
} catch (error) {