AI Resource Pro / website · airesourcepro.com / src / lib / roadmap.test.ts
| 1 | import { parseProfile, tracksForGoals, type LearningProfile } from "@/lib/onboarding"; |
| 2 | import { buildRoadmap } from "@/lib/roadmap"; |
| 3 | import type { TutorialMeta } from "@/lib/tutorial-types"; |
| 4 | |
| 5 | const tut = (over: Partial<TutorialMeta>): TutorialMeta => ({ |
| 6 | slug: "t", |
| 7 | track: "claude", |
| 8 | title: "T", |
| 9 | description: "", |
| 10 | level: "Beginner", |
| 11 | minutes: 10, |
| 12 | publishedAt: "2026-10-30", |
| 13 | draft: false, |
| 14 | cover: "/covers/claude.webp", |
| 15 | ...over, |
| 16 | }); |
| 17 | |
| 18 | const TUTORIALS = [ |
| 19 | tut({ slug: "claude-md", track: "claude", minutes: 10 }), |
| 20 | tut({ slug: "cc-best", track: "claude", minutes: 5 }), |
| 21 | tut({ slug: "comfy", track: "ai-video", level: "Intermediate", minutes: 11, video: "abc" }), |
| 22 | tut({ slug: "costs", track: "ai-video", minutes: 7 }), |
| 23 | tut({ slug: "draft", track: "ai-video", draft: true }), |
| 24 | tut({ slug: "codex", track: "chatgpt" }), |
| 25 | ]; |
| 26 | |
| 27 | const profile = (over: Partial<LearningProfile> = {}): LearningProfile => ({ |
| 28 | goals: ["video"], |
| 29 | tracks: ["ai-video"], |
| 30 | level: "Beginner", |
| 31 | weeklyTime: "steady", |
| 32 | format: "both", |
| 33 | ...over, |
| 34 | }); |
| 35 | |
| 36 | describe("tracksForGoals", () => { |
| 37 | it("maps goals to tracks in site order without duplicates", () => { |
| 38 | expect(tracksForGoals(["video", "code", "everyday"])).toEqual(["claude", "chatgpt", "ai-video"]); |
| 39 | }); |
| 40 | }); |
| 41 | |
| 42 | describe("parseProfile", () => { |
| 43 | it("reads a database row", () => { |
| 44 | const p = parseProfile({ goals: ["code"], tracks: ["claude"], level: "Advanced", weekly_time: "deep", format: "video" }); |
| 45 | expect(p).toMatchObject({ goals: ["code"], tracks: ["claude"], level: "Advanced", weeklyTime: "deep" }); |
| 46 | }); |
| 47 | |
| 48 | it("rejects incomplete or unknown answers", () => { |
| 49 | expect(parseProfile({ goals: [], level: "Beginner", weeklyTime: "light", format: "both" })).toBeNull(); |
| 50 | expect(parseProfile({ goals: ["code"], level: "Expert", weeklyTime: "light", format: "both" })).toBeNull(); |
| 51 | expect(parseProfile(null)).toBeNull(); |
| 52 | }); |
| 53 | |
| 54 | it("falls back to the goals' tracks when none were picked", () => { |
| 55 | expect(parseProfile({ goals: ["automate"], tracks: [], level: "Beginner", weeklyTime: "light", format: "both" })?.tracks).toEqual([ |
| 56 | "computer-use", |
| 57 | ]); |
| 58 | }); |
| 59 | }); |
| 60 | |
| 61 | describe("buildRoadmap", () => { |
| 62 | it("only uses published tutorials from the chosen tracks, phased by level", () => { |
| 63 | const r = buildRoadmap(profile(), TUTORIALS); |
| 64 | expect(r.phases.map((p) => p.level)).toEqual(["Beginner", "Intermediate"]); |
| 65 | expect(r.phases.flatMap((p) => p.steps.map((s) => s.key))).toEqual(["ai-video/costs", "ai-video/comfy"]); |
| 66 | expect(r.totalSteps).toBe(2); |
| 67 | expect(r.phases[0].milestone).toMatch(/GPU pod/); |
| 68 | }); |
| 69 | |
| 70 | it("marks phases below the user's level as optional refreshers", () => { |
| 71 | const r = buildRoadmap(profile({ level: "Intermediate" }), TUTORIALS); |
| 72 | expect(r.phases[0]).toMatchObject({ level: "Beginner", optional: true }); |
| 73 | expect(r.phases[1]).toMatchObject({ level: "Intermediate", optional: false }); |
| 74 | }); |
| 75 | |
| 76 | it("puts videos first for people who prefer them and gives the goal as the reason", () => { |
| 77 | const r = buildRoadmap( |
| 78 | profile({ goals: ["code"], tracks: ["claude", "ai-video"], format: "video" }), |
| 79 | [...TUTORIALS, tut({ slug: "vid", track: "claude", video: "x" })] |
| 80 | ); |
| 81 | expect(r.phases[0].steps[0].key).toBe("claude/vid"); |
| 82 | expect(r.phases[0].steps[0].reason).toBe("Ship code with an AI agent"); |
| 83 | }); |
| 84 | |
| 85 | it("paces phases by weekly time", () => { |
| 86 | const light = buildRoadmap(profile({ tracks: ["claude"], goals: ["code"], weeklyTime: "light" }), TUTORIALS); |
| 87 | const deep = buildRoadmap(profile({ tracks: ["claude"], goals: ["code"], weeklyTime: "deep" }), TUTORIALS); |
| 88 | expect(light.phases[0].weeks).toBeGreaterThanOrEqual(deep.phases[0].weeks); |
| 89 | expect(deep.phases[0].weeks).toBe(1); |
| 90 | }); |
| 91 | }); |