cv-generator.test.js
1 const { test, suite } = require('node:test'); 2 const assert = require('assert'); 3 const { CVGenerator } = require('./cv-generator.js'); 4 const fs = require('fs').promises; 5 6 function mockFs() { 7 fs.rm = async () => {}; 8 fs.mkdir = async () => {}; 9 fs.readFile = async (filePath) => { 10 if (filePath.includes('index.html')) return '<html><head><title>Test</title><meta name="description" content="test"></head><body><p id="professional-summary"></p><span id="footer-last-updated"></span></body></html>'; 11 if (filePath.includes('base-cv.json')) return JSON.stringify({ 12 personal_info: { name: 'Test User', title: 'Test Title', location: 'Test City', phone: '555', email: 'test@test.com', linkedin: 'https://linkedin.com/in/test', github: 'https://github.com/test' }, 13 professional_summary: 'First sentence. Second sentence. Third sentence. Fourth sentence. Fifth sentence.', 14 skills: [{name: 'JS', category: 'Programming Languages'}], 15 experience: [{ position: 'Dev', company: 'Co', period: '2020-2024', description: 'Did things. More things.', achievements: ['Built X', 'Shipped Y', 'Led Z', 'Extra'] }], 16 projects: [{ name: 'Proj1', description: 'A project. Details here.' }], 17 education: [{ degree: 'CS Degree', institution: 'Uni', period: '2016-2020' }] 18 }); 19 if (filePath.includes('ats-template.html')) return '<!DOCTYPE html><html><body><h1>{{NAME}}</h1><p>{{TITLE}}</p><p>{{LOCATION}} {{PHONE}} {{EMAIL}} {{LINKEDIN_URL}} {{GITHUB_URL}}</p><p>{{SUMMARY}}</p><p>{{COMPETENCIES}}</p>{{EXPERIENCE}}<ul>{{PROJECTS}}</ul><p>{{SKILLS}}</p>{{EDUCATION}}</body></html>'; 20 if (filePath.includes('activity-summary.json')) return JSON.stringify({ 21 summary: { total_commits: 42, active_days: 10, net_lines_contributed: 5000, tracking_status: 'active', last_commit_date: '2026-03-01' }, 22 last_updated: '2026-03-01T00:00:00Z' 23 }); 24 if (filePath.includes('ai-enhancements.json')) return JSON.stringify({ 25 last_updated: null, professional_summary: {}, skills_enhancement: {}, enhancement_summary: {} 26 }); 27 return '{}'; 28 }; 29 fs.writeFile = async () => {}; 30 fs.copyFile = async () => {}; 31 } 32 33 suite('CVGenerator', () => { 34 test('should load data sources correctly', async () => { 35 mockFs(); 36 const generator = new CVGenerator(); 37 await generator.loadDataSources(); 38 assert.strictEqual(generator.cvData.personal_info.name, 'Test User'); 39 }); 40 41 test('should generate HTML with updated meta tags', async () => { 42 mockFs(); 43 const generator = new CVGenerator(); 44 await generator.loadDataSources(); 45 await generator.generateHTML(); 46 assert(true); 47 }); 48 49 test('should call generatePDF during overall generation', async () => { 50 mockFs(); 51 const generator = new CVGenerator(); 52 generator.generatePDF = async () => { generator._pdfGenerated = true; }; 53 generator.generateATSPDF = async () => { generator._atsPdfGenerated = true; }; 54 await generator.generate(); 55 assert.strictEqual(generator._pdfGenerated, true, 'generatePDF should be called'); 56 assert.strictEqual(generator._atsPdfGenerated, true, 'generateATSPDF should be called'); 57 }); 58 59 test('buildATSHTML should return HTML with no remaining placeholders', async () => { 60 mockFs(); 61 const generator = new CVGenerator(); 62 await generator.loadDataSources(); 63 const html = await generator.buildATSHTML(); 64 assert.strictEqual(html.includes('{{'), false, 'No unreplaced {{ placeholders should remain'); 65 assert.strictEqual(html.includes('}}'), false, 'No unreplaced }} placeholders should remain'); 66 }); 67 68 test('buildATSHTML should include name and title', async () => { 69 mockFs(); 70 const generator = new CVGenerator(); 71 await generator.loadDataSources(); 72 const html = await generator.buildATSHTML(); 73 assert(html.includes('Test User'), 'HTML should include the name'); 74 assert(html.includes('Test Title'), 'HTML should include the title'); 75 }); 76 });