test: fix Prisma mock drift for pulse-league + article + tracks - #53
Conversation
pulse-league-service: getLatestEligibilityScores was refactored from groupBy + N×findFirst into a single $queryRaw (DISTINCT ON). Tests still mocked the old shape. Add $queryRaw to the prisma mock and a mockEligibilityScores helper, replacing all groupBy/findFirst setup across the 25 affected cases. article-service: getArticleBySlug now reads from prisma.contentLink to resolve linked tool slugs. Mock contentLink.findMany so the slug lookup test stops throwing 'Cannot read properties of undefined (reading findMany)'. tracks/route: already passing — no change needed. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes 26 failing tests caused by Prisma mock drift after recent service refactors. Scope is limited to test files only — no schema, migration, jest.setup.js, or src/lib/mcp/* changes.
getLatestEligibilityScoreswas refactored fromgroupBy+ N×findFirstinto a single$queryRaw(DISTINCT ON) for perf. Tests still mocked the old shape, so every case threw_db.prisma.$queryRaw is not a function. Added$queryRawto the prisma mock plus amockEligibilityScores(scores)helper that seeds the raw rows directly, and replaced all the oldgroupBy/findFirstsetup blocks with calls to it.getArticleBySlugnow reads fromprisma.contentLinkto resolve linked tool slugs. The mock didn't includecontentLink, so the slug-lookup case threwCannot read properties of undefined (reading findMany). AddedcontentLink.findMany(resolves to[]) to the mock.All 82 tests across the three suites pass locally.
tsc --noEmitis clean for these files (the only error is a pre-existing missingdocs-index.generated.jsoninsrc/lib/mcp/, which is in active PR review on #48 and outside scope).Test plan
yarn test src/lib/services/__tests__/pulse-league-service.test.ts --ci— 34/34 passyarn test src/lib/services/__tests__/article-service.test.ts --ci— 45/45 passyarn test src/app/api/tracks/__tests__/route.test.ts --ci— 3/3 pass🤖 Generated with Claude Code