test(ats): add Vitest unit tests for AtsService with Gemini API mocking#882
test(ats): add Vitest unit tests for AtsService with Gemini API mocking#882Abhushan187 wants to merge 1 commit into
Conversation
|
Hi @Abhushan187, thanks for contributing to InternHack! 🎉 I have automatically:
Our workflows will now analyze your changes to classify:
Tip Ensure your PR description references the issue it resolves (e.g. Happy coding! 🚀 |
📝 WalkthroughWalkthroughAdds a comprehensive Vitest test suite for AtsService covering scoreResume, getScoreHistory, and applySuggestions methods. Tests validate user/ownership guards, cache behavior, PDF parsing, AI response parsing, output constraints, and edge cases using fully mocked Prisma, S3, AI provider, and filesystem dependencies. ChangesAtsService Test Suite
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
server/src/module/ats/__tests__/ats.service.test.ts (1)
184-190: ⚡ Quick winDeduplicate repeated
PDFParsemock setup using existing helper.Both tests reimplement the same mock shape inline. Reuse
mockValidPdf(text)to keep one source of truth and reduce drift.♻️ Proposed refactor
- vi.mocked(PDFParse).mockImplementation( - () => - ({ - getText: vi.fn().mockResolvedValue({ text: "too short" }), - destroy: vi.fn().mockResolvedValue(undefined), - }) as any, - ); + mockValidPdf("too short");- vi.mocked(PDFParse).mockImplementation( - () => - ({ - getText: vi.fn().mockResolvedValue({ text: "tiny" }), - destroy: vi.fn().mockResolvedValue(undefined), - }) as any, - ); + mockValidPdf("tiny");As per coding guidelines, "Apply DRY principle: no duplicate helpers, shared animation variants per file".
Also applies to: 467-473
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@server/src/module/ats/__tests__/ats.service.test.ts` around lines 184 - 190, Replace the inline PDFParse mock implementations with the existing test helper mockValidPdf(text): locate the inline vi.mocked(PDFParse).mockImplementation blocks in ats.service.test.ts and call mockValidPdf("too short") (or other text) instead of re-creating getText/destroy mocks; do the same for the second occurrence that duplicates the same shape so both tests use the single mockValidPdf helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@server/src/module/ats/__tests__/ats.service.test.ts`:
- Around line 184-190: Replace the inline PDFParse mock implementations with the
existing test helper mockValidPdf(text): locate the inline
vi.mocked(PDFParse).mockImplementation blocks in ats.service.test.ts and call
mockValidPdf("too short") (or other text) instead of re-creating getText/destroy
mocks; do the same for the second occurrence that duplicates the same shape so
both tests use the single mockValidPdf helper.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7db48798-846d-4a9b-87e3-4c1969c7af13
📒 Files selected for processing (1)
server/src/module/ats/__tests__/ats.service.test.ts
Sachinchaurasiya360
left a comment
There was a problem hiding this comment.
Review
Verdict: Approve
Great coverage — the safe-defaults beforeEach pattern and the IDOR guard test are highlights. A few things to tighten before merge:
Issues
1. PDFParse mock may not intercept the real call path
The import is import { PDFParse } from "pdf-parse". Verify this matches how pdf-parse v2 actually exports the constructor. If the real module uses a default export, the mock will never intercept it and the test silently passes for the wrong reason.
2. Missing newline at end of file
The last line of the test file has \ No newline at end of file. Add a trailing newline to avoid diff noise on future edits.
3. "throws when AI returns completely unparseable text" has no message assertion
.rejects.toThrow() with no argument passes on any thrown error, including a mock misconfiguration. Pin the expected message (e.g. "Failed to parse ATS score") so the assertion actually validates service behaviour.
4. No test for the cache TTL boundary
The cache-hit test mocks findFirst to always return a row, but there is no test confirming that a row older than the TTL is treated as a cache miss. If TTL logic lives in the service, it should be covered.
5. "falls back to raw AI text when <latex> tag is absent" only asserts toBeTruthy()
This accepts any non-empty string. Pin the expected fallback value (e.g. the raw AI text) so a regression in the fallback path is actually caught.
|
fix the lint and build |
Changes
server/src/module/ats/__tests__/ats.service.test.ts— 22 unit tests across 3 suitesCoverage
scoreResumegetScoreHistoryapplySuggestionsTechnical Notes
vi.mock(): Prisma, S3 utils, AI provider registry, pdf-parse, fs/promisesvitest.config.tsinserver/— no config changes needed__tests__/pattern other ATS sub-services can followCloses #738
Summary by CodeRabbit