Spaces:
Sleeping
Sleeping
File size: 4,368 Bytes
92a138e | 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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | const request = require('supertest');
const app = require('../src/server');
const { getDb } = require('../src/config/database');
let token = '';
let resumeId = '';
afterAll(() => {
const db = getDb();
db.prepare("DELETE FROM users WHERE email = 'test@example.com'").run();
});
describe('Auth', () => {
test('POST /api/auth/register', async () => {
const res = await request(app).post('/api/auth/register').send({
name: 'Test User', email: 'test@example.com', password: 'password123',
});
expect(res.status).toBe(201);
expect(res.body.success).toBe(true);
token = res.body.tokens.access;
});
test('POST /api/auth/login', async () => {
const res = await request(app).post('/api/auth/login').send({
email: 'test@example.com', password: 'password123',
});
expect(res.status).toBe(200);
token = res.body.tokens.access;
});
test('GET /api/auth/me', async () => {
const res = await request(app)
.get('/api/auth/me')
.set('Authorization', `Bearer ${token}`);
expect(res.status).toBe(200);
expect(res.body.user.email).toBe('test@example.com');
});
});
describe('Templates', () => {
test('GET /api/templates', async () => {
const res = await request(app).get('/api/templates');
expect(res.status).toBe(200);
expect(Array.isArray(res.body.templates)).toBe(true);
});
test('GET /api/templates/categories', async () => {
const res = await request(app).get('/api/templates/categories');
expect(res.status).toBe(200);
expect(Array.isArray(res.body.categories)).toBe(true);
});
});
describe('Resumes', () => {
test('POST /api/resumes — create', async () => {
const res = await request(app)
.post('/api/resumes')
.set('Authorization', `Bearer ${token}`)
.send({ title: 'My Test Resume' });
expect(res.status).toBe(201);
resumeId = res.body.resume.id;
});
test('GET /api/resumes — list', async () => {
const res = await request(app)
.get('/api/resumes')
.set('Authorization', `Bearer ${token}`);
expect(res.status).toBe(200);
expect(res.body.resumes.length).toBeGreaterThan(0);
});
test('PATCH /api/resumes/:id — update content', async () => {
const res = await request(app)
.patch(`/api/resumes/${resumeId}`)
.set('Authorization', `Bearer ${token}`)
.send({
content: {
contact: { name: 'Jane Doe', email: 'jane@example.com', phone: '555-0100' },
summary: 'Senior software engineer with 8 years experience.',
experience: [{ title: 'Engineer', company: 'Acme', startDate: 'Jan 2020', endDate: 'Present', description: 'Built things' }],
education: [{ degree: 'BSc', field: 'CS', institution: 'MIT', endDate: '2018' }],
skills: ['JavaScript', 'React', 'Node.js'],
},
});
expect(res.status).toBe(200);
});
test('GET /api/resumes/:id/ats — score', async () => {
const res = await request(app)
.get(`/api/resumes/${resumeId}/ats`)
.set('Authorization', `Bearer ${token}`);
expect(res.status).toBe(200);
expect(typeof res.body.ats.score).toBe('number');
});
test('POST /api/resumes/:id/duplicate', async () => {
const res = await request(app)
.post(`/api/resumes/${resumeId}/duplicate`)
.set('Authorization', `Bearer ${token}`);
expect(res.status).toBe(201);
// Cleanup duplicate
await request(app)
.delete(`/api/resumes/${res.body.resume.id}`)
.set('Authorization', `Bearer ${token}`);
});
test('DELETE /api/resumes/:id', async () => {
const res = await request(app)
.delete(`/api/resumes/${resumeId}`)
.set('Authorization', `Bearer ${token}`);
expect(res.status).toBe(200);
});
});
describe('Tips', () => {
test('GET /api/tips', async () => {
const res = await request(app).get('/api/tips');
expect(res.status).toBe(200);
expect(res.body.tips).toBeDefined();
});
test('GET /api/tips/experience', async () => {
const res = await request(app).get('/api/tips/experience');
expect(res.status).toBe(200);
expect(res.body.tips.length).toBeGreaterThan(0);
});
});
describe('Health', () => {
test('GET /health', async () => {
const res = await request(app).get('/health');
expect(res.status).toBe(200);
expect(res.body.status).toBe('ok');
});
});
|