Skip to content

Make profile achievements reflect learner progress - #11

Merged
prathamkashyap merged 1 commit into
mainfrom
fix/profile-achievements
Oct 4, 2026
Merged

prathamkashyap merged 1 commit into
mainfrom
fix/profile-achievements

Conversation

@prathamkashyap

Copy link
Copy Markdown
Owner

Fixes a production truthfulness bug: a brand-new account was being shown achievements it had not earned.

The bug

src/pages/Profile.tsx rendered two achievements as literal JSX:

First Quiz Completed — "You completed your first diagnostic assessment."
3 Day Streak         — "You studied for 3 consecutive days."

So a fresh production account displayed both, while the streak card directly above read 0 days /
longest 0
and the dashboard read 0 quizzes taken. Real streak figures beside fabricated
achievements is the worst version of this bug: it looks like seeded demo data.

Meanwhile the backend already had genuine achievement logic — progressService.js creates a real
first_quiz achievement and persists it — and UserProgress.achievements was simply never read by
the frontend. Nothing exposed it.

Option B: milestones are now real achievements

updateStudyStreak computed genuine streaks and fired a notification at 3/7/14/30/50/100 days, but
persisted no achievement. So wiring the page to progress.achievements alone would have shown
first_quiz and never a streak — a permanently half-empty section called "Recent Achievements". A
milestone now does both, via one idempotent helper:

const awardAchievement = async (progress, achievement, { session } = {}) => {
  if (!progress) return false;
  const existing = progress.achievements ?? [];
  if (existing.some((a) => a.id === achievement.id)) return false;
  progress.achievements = [...existing, achievement];
  await saveDoc(progress, session);
  return true;
};

Idempotent by id, returning whether this call awarded it so the notification fires only on the
transition. first_quiz was refactored onto the same helper, so both paths share one contract.
Streak arithmetic, lastStudyDate, the early return for a same-day repeat, and the existing
notification behaviour are all untouched.

A learner with no progress document — studied three days but never sat an assessment — gets a
tracked streak and no achievement, because there is nothing to attach one to. That case is covered.

Exposed additively, no new endpoint

UserProgress was already imported in authController.js, so achievements are attached in the one
place all three auth paths funnel through:

const userWithAchievements = async (user) => { … }

signup, login and GET /auth/me all return it. Every field toSafeJSON() produced is passed
through unchanged, so this is purely additive — no new route, no changed shape for existing clients.
A missing progress document yields [], which is the truthful answer rather than an error.

Empty state with an unlock hint

No achievements yet
Complete your first assessment to unlock your first achievement. Study on three consecutive days to
unlock a streak milestone.

Motivating, and a hint rather than a claim. Once anything is earned, only earned items are listed —
achievements are never displayed because they exist in the catalogue.

On the wording question

You asked to rename "First Quiz Completed" → "First Assessment Completed" only if the domain term
is now "assessment". Having read the backend: the persisted achievement is titled "First Steps"
and its description already reads "Completed your first assessment." The hard-coded string was the
only place still saying "quiz", and it is deleted. So there was nothing to rename — the real copy was
already consistent, and renaming the stored title would have desynced it from the existing
notification ("You've earned the 'First Steps' achievement"). A test asserts the rendered page never
says "quiz".

Two emoji removed as a side effect

The notification titles in this same function carried 🏆 and 🔥, and notifications are user-facing
via NotificationBell.tsx. Since I was editing the function and the standing goal is no emoji in the
product, both are gone ("Achievement unlocked", "3 day streak"). Flagging it because it is slightly
wider than the literal brief.

Tests — 16 new

attemptProcessing.test.js (+5, backend): milestone persists streak_3 with title, description and
timestamp; nothing before the milestone; same-day repeat and a replayed day do not duplicate; a 4-day
streak does not re-award the 3-day award; a learner with no progress document neither crashes nor
gains one. Existing first-assessment coverage (first_quiz absent before, present after, stable on
replay) already held.

profileAchievements.test.tsx (+10, frontend): nothing earned → empty state and hint, and neither
hard-coded entry present; a missing achievements field reads as none earned; real achievements
render with titles and descriptions; newest first; an achievement with no description renders;
assessment vocabulary only; and a real 3-day streak shows figures agreeing with its achievement,
while a zero streak shows no streak achievement.

Verification

Check Before After
Backend unit 937 / 36 suites 942 / 36
Backend integration 101 passed, 13 skipped unchanged
Frontend 277 / 23 files 287 / 24
Playwright E2E 26 passed, 2 skipped unchanged
typecheck / build / lint 0 / 0 / 0 0 / 0 / 0

Two of my own test bugs were caught before commit: an ambiguous getByText("3") (both streak figures
render 3), and the notification-title assertion following the emoji change.

Needs a manual check on production: sign up a fresh account, complete nothing, and confirm
Profile shows "No achievements yet" rather than two achievements.

@prathamkashyap
prathamkashyap merged commit f4cdc0c into main Oct 4, 2026
3 checks passed
@prathamkashyap
prathamkashyap deleted the fix/profile-achievements branch October 4, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant