feat: on-demand topic tests with shared question bank
Adds a /topic-test route where learners can take a 5-question test on any eligible topic at any time. Questions come from a shared, admin-curated question_bank — no LLM calls on the user path. Points feed the existing leaderboard with a 10pt/topic/week cap (per ISO week) so the bank can't be farmed, and repeats from a thin bank yield 0 points. - New PB collections: question_bank, on_demand_attempts (+ migrations and setup-pb-collections.mjs entries). - db.js: un-deprecates getQuizBank/setQuizBank against question_bank so the existing admin TestManager panel becomes functional again; adds saveOnDemandAttempt, getOnDemandPointsThisWeek, getUserSeenQuestionIds, getAllOnDemandAttempts, isoWeekKey. - testService.js: getEligibleTopicsForOnDemand, startOnDemandTest (unseen- first draw), finishOnDemandTest (cap enforcement + leaderboard upsert). - New TopicTest page, route, and nav entry; weekly test flow untouched. - Leaderboard folds on-demand 100%s into perfect-score count and merges on-demand attempts into the recent activity feed. - Spec: docs/on-demand-tests-spec.md with ADRs and extension points. - Tests: 5 new vitest cases covering eligibility, draw fallback, scoring, partial cap, and exhausted cap (85/85 total). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -56,7 +56,9 @@ const COLLECTIONS = [
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'quiz_banks',
|
||||
// Question bank: one record per topic with a `questions` JSON array.
|
||||
// Shared across all users; admin-curated; powers on-demand topic tests.
|
||||
name: 'question_bank',
|
||||
type: 'base',
|
||||
...OPEN_RULES,
|
||||
fields: [
|
||||
@@ -65,6 +67,30 @@ const COLLECTIONS = [
|
||||
...AUTODATE_FIELDS,
|
||||
],
|
||||
},
|
||||
{
|
||||
// On-demand attempts log: one record per completed topic test.
|
||||
// Powers the weekly-cap aggregation and the Contributions feed.
|
||||
name: 'on_demand_attempts',
|
||||
type: 'base',
|
||||
...OPEN_RULES,
|
||||
fields: [
|
||||
{ name: 'user_id', type: 'text', required: true },
|
||||
{ name: 'topic_id', type: 'text', required: true },
|
||||
{ name: 'topic_label', type: 'text', required: false },
|
||||
{ name: 'question_ids', type: 'json', required: false },
|
||||
{ name: 'score', type: 'number', required: false },
|
||||
{ name: 'total', type: 'number', required: false },
|
||||
{ name: 'percentage', type: 'number', required: false },
|
||||
{ name: 'time_used', type: 'number', required: false },
|
||||
{ name: 'unseen_correct', type: 'number', required: false },
|
||||
{ name: 'points_earned', type: 'number', required: false },
|
||||
{ name: 'capped', type: 'bool', required: false },
|
||||
{ name: 'iso_week', type: 'text', required: false },
|
||||
{ name: 'completed_at', type: 'text', required: false },
|
||||
{ name: 'breakdown', type: 'json', required: false },
|
||||
...AUTODATE_FIELDS,
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'sources',
|
||||
type: 'base',
|
||||
|
||||
Reference in New Issue
Block a user