Repository navigation
Expand file tree
/
Copy pathresume-parser.binary.test.ts
More file actions
73 lines (66 loc) · 1.96 KB
/
Copy pathresume-parser.binary.test.ts
File metadata and controls
73 lines (66 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { describe, it, expect, vi } from 'vitest';
import { parseResume } from './resume-parser';
vi.mock('pdf-parse', () => {
return {
PDFParse: class {
async getText() {
return {
text: `John Doe
+1 234-567-8901
Skills
TypeScript, React, Node.js
Education
B.Tech Computer Science 2020-2024
Experience
Software Engineer at ABC Corp 2022-2024`,
};
}
async destroy() {}
},
};
});
vi.mock('mammoth', () => {
return {
default: {
extractRawText: vi.fn().mockResolvedValue({
value: `Jane Smith
(555) 123-4567
Skills
Python, Docker, AWS
Education
BS Mathematics 2018-2022
Experience
DevOps Engineer at XYZ 2022-2024`,
}),
},
};
});
describe('resume-parser binary document parsing', () => {
it('correctly uses pdf-parse when parsing a valid PDF buffer', async () => {
// A mock PDF buffer starts with "%PDF"
const buffer = Buffer.from('%PDF-1.4\nSome binary content');
const result = await parseResume(buffer, 'application/pdf');
expect(result.name).toBe('John Doe');
expect(result.phone).toBe('+1 234-567-8901');
expect(result.skills).toContain('TypeScript');
expect(result.education).toHaveLength(1);
expect(result.experience).toHaveLength(1);
});
it('correctly uses mammoth when parsing a valid DOCX buffer', async () => {
// A mock DOCX/ZIP container starts with "PK"
const buffer = Buffer.from('PK\x03\x04\nSome binary docx zip content');
const result = await parseResume(
buffer,
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
);
expect(result.name).toBe('Jane Smith');
expect(result.phone).toBe('(555) 123-4567');
expect(result.skills).toContain('Python');
expect(result.education).toHaveLength(1);
expect(result.experience).toHaveLength(1);
});
});