Skip to content

Commit 3dca047

Browse files
authored
test(resume-parser): add comprehensive test coverage for resume parsing and fallback scenarios (JhaSourav07#3116)
## Description Adds a dedicated test suite for lib/resume-parser.ts to validate resume parsing behavior across normal, malformed, and incomplete inputs. ## Changes - Added lib/resume-parser.test.ts - Added tests for: - Well-formatted resume parsing - Email and phone extraction - Education section extraction - Experience section extraction - Empty/malformed resume handling - Missing section fallback behavior - Exported parser constants validation Fixes JhaSourav07#2290 ## Pillar - [x] 📐 Pillar 2 — Geometric SVG Improvement - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents a7a21a0 + 409aa72 commit 3dca047

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

lib/resume-parser.test.ts

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { parseResume, ALLOWED_MIME_TYPES, MAX_FILE_SIZE } from './resume-parser';
3+
4+
describe('resume-parser', () => {
5+
it('parses a well formatted resume', async () => {
6+
const resume = `
7+
John Doe
8+
john.doe@example.com
9+
+1 234-567-8901
10+
11+
Skills
12+
TypeScript, React, Node.js
13+
14+
Education
15+
B.Tech Computer Science 2020-2024
16+
17+
Experience
18+
Software Engineer at ABC Corp 2022-2024
19+
`;
20+
21+
const result = await parseResume(Buffer.from(resume), 'application/pdf');
22+
23+
expect(result.name).toBe('John Doe');
24+
expect(result.email).toBe('john.doe@example.com');
25+
expect(result.phone).toContain('234');
26+
expect(result.skills).toContain('TypeScript');
27+
expect(result.education).toHaveLength(1);
28+
expect(result.experience).toHaveLength(1);
29+
});
30+
31+
it('extracts contact information correctly', async () => {
32+
const resume = `
33+
Jane Smith
34+
jane.smith@gmail.com
35+
(555) 123-4567
36+
`;
37+
38+
const result = await parseResume(Buffer.from(resume), 'application/pdf');
39+
40+
expect(result.email).toBe('jane.smith@gmail.com');
41+
expect(result.phone).toContain('555');
42+
});
43+
44+
it('extracts education and experience sections', async () => {
45+
const resume = `
46+
Robert Brown
47+
48+
Education
49+
University of Testing 2018-2022
50+
51+
Experience
52+
Frontend Developer at XYZ 2022-2024
53+
`;
54+
55+
const result = await parseResume(Buffer.from(resume), 'application/pdf');
56+
57+
expect(result.education).toEqual([
58+
expect.objectContaining({
59+
institution: 'University of Testing 2018-2022',
60+
startDate: '2018',
61+
endDate: '2022',
62+
}),
63+
]);
64+
65+
expect(result.experience).toEqual([
66+
expect.objectContaining({
67+
company: 'Frontend Developer at XYZ 2022-2024',
68+
startDate: '2022',
69+
endDate: '2024',
70+
}),
71+
]);
72+
});
73+
74+
it('handles empty or malformed resume text', async () => {
75+
const result = await parseResume(Buffer.from(''), 'application/pdf');
76+
77+
expect(result).toEqual({
78+
name: '',
79+
email: '',
80+
phone: '',
81+
skills: [],
82+
education: [],
83+
experience: [],
84+
});
85+
});
86+
87+
it('returns sensible fallbacks when sections are missing', async () => {
88+
const resume = `
89+
Alex Johnson
90+
alex@example.com
91+
92+
Random text without any section headers.
93+
`;
94+
95+
const result = await parseResume(Buffer.from(resume), 'application/pdf');
96+
97+
expect(result.name).toBe('Alex Johnson');
98+
expect(result.email).toBe('alex@example.com');
99+
expect(result.skills).toEqual([]);
100+
expect(result.education).toEqual([]);
101+
expect(result.experience).toEqual([]);
102+
});
103+
});
104+
105+
describe('parser constants', () => {
106+
it('exports allowed mime types and max file size', () => {
107+
expect(ALLOWED_MIME_TYPES).toContain('application/pdf');
108+
expect(ALLOWED_MIME_TYPES).toContain(
109+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
110+
);
111+
112+
expect(MAX_FILE_SIZE).toBe(5 * 1024 * 1024);
113+
});
114+
});

0 commit comments

Comments
 (0)