|
| 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