import { parseProfile, tracksForGoals, type LearningProfile } from "@/lib/onboarding"; import { buildRoadmap } from "@/lib/roadmap"; import type { TutorialMeta } from "@/lib/tutorial-types"; const tut = (over: Partial): TutorialMeta => ({ slug: "t", track: "claude", title: "T", description: "", level: "Beginner", minutes: 10, publishedAt: "2026-10-30", draft: false, cover: "/covers/claude.webp", ...over, }); const TUTORIALS = [ tut({ slug: "claude-md", track: "claude", minutes: 10 }), tut({ slug: "cc-best", track: "claude", minutes: 5 }), tut({ slug: "comfy", track: "ai-video", level: "Intermediate", minutes: 11, video: "abc" }), tut({ slug: "costs", track: "ai-video", minutes: 7 }), tut({ slug: "draft", track: "ai-video", draft: true }), tut({ slug: "codex", track: "chatgpt" }), ]; const profile = (over: Partial = {}): LearningProfile => ({ goals: ["video"], tracks: ["ai-video"], level: "Beginner", weeklyTime: "steady", format: "both", ...over, }); describe("tracksForGoals", () => { it("maps goals to tracks in site order without duplicates", () => { expect(tracksForGoals(["video", "code", "everyday"])).toEqual(["claude", "chatgpt", "ai-video"]); }); }); describe("parseProfile", () => { it("reads a database row", () => { const p = parseProfile({ goals: ["code"], tracks: ["claude"], level: "Advanced", weekly_time: "deep", format: "video" }); expect(p).toMatchObject({ goals: ["code"], tracks: ["claude"], level: "Advanced", weeklyTime: "deep" }); }); it("rejects incomplete or unknown answers", () => { expect(parseProfile({ goals: [], level: "Beginner", weeklyTime: "light", format: "both" })).toBeNull(); expect(parseProfile({ goals: ["code"], level: "Expert", weeklyTime: "light", format: "both" })).toBeNull(); expect(parseProfile(null)).toBeNull(); }); it("falls back to the goals' tracks when none were picked", () => { expect(parseProfile({ goals: ["automate"], tracks: [], level: "Beginner", weeklyTime: "light", format: "both" })?.tracks).toEqual([ "computer-use", ]); }); }); describe("buildRoadmap", () => { it("only uses published tutorials from the chosen tracks, phased by level", () => { const r = buildRoadmap(profile(), TUTORIALS); expect(r.phases.map((p) => p.level)).toEqual(["Beginner", "Intermediate"]); expect(r.phases.flatMap((p) => p.steps.map((s) => s.key))).toEqual(["ai-video/costs", "ai-video/comfy"]); expect(r.totalSteps).toBe(2); expect(r.phases[0].milestone).toMatch(/GPU pod/); }); it("marks phases below the user's level as optional refreshers", () => { const r = buildRoadmap(profile({ level: "Intermediate" }), TUTORIALS); expect(r.phases[0]).toMatchObject({ level: "Beginner", optional: true }); expect(r.phases[1]).toMatchObject({ level: "Intermediate", optional: false }); }); it("puts videos first for people who prefer them and gives the goal as the reason", () => { const r = buildRoadmap( profile({ goals: ["code"], tracks: ["claude", "ai-video"], format: "video" }), [...TUTORIALS, tut({ slug: "vid", track: "claude", video: "x" })] ); expect(r.phases[0].steps[0].key).toBe("claude/vid"); expect(r.phases[0].steps[0].reason).toBe("Ship code with an AI agent"); }); it("paces phases by weekly time", () => { const light = buildRoadmap(profile({ tracks: ["claude"], goals: ["code"], weeklyTime: "light" }), TUTORIALS); const deep = buildRoadmap(profile({ tracks: ["claude"], goals: ["code"], weeklyTime: "deep" }), TUTORIALS); expect(light.phases[0].weeks).toBeGreaterThanOrEqual(deep.phases[0].weeks); expect(deep.phases[0].weeks).toBe(1); }); });