80 lines
2.4 KiB
JavaScript
80 lines
2.4 KiB
JavaScript
const request = require('supertest');
|
|
const app = require('../server');
|
|
const { registerUser, createEmployerProfile } = require('./utils');
|
|
|
|
async function createJob(token) {
|
|
const response = await request(app)
|
|
.post('/api/jobs')
|
|
.set('Authorization', `Bearer ${token}`)
|
|
.send({
|
|
title: 'QA Engineer',
|
|
description: 'Ensure software quality',
|
|
requirements: ['Attention to detail'],
|
|
responsibilities: ['Write test plans'],
|
|
location: 'Remote',
|
|
employmentType: 'full-time',
|
|
remoteAllowed: true
|
|
})
|
|
.expect(201);
|
|
|
|
return response.body.job;
|
|
}
|
|
|
|
describe('Applications API', () => {
|
|
it('supports full application lifecycle', async () => {
|
|
const { token: employerToken } = await registerUser('employer');
|
|
await createEmployerProfile(employerToken);
|
|
const job = await createJob(employerToken);
|
|
|
|
const { token: candidateToken } = await registerUser('candidate');
|
|
|
|
await request(app)
|
|
.post('/api/candidates')
|
|
.set('Authorization', `Bearer ${candidateToken}`)
|
|
.send({
|
|
location: 'Remote',
|
|
skills: ['Automation'],
|
|
experienceLevel: 'mid'
|
|
})
|
|
.expect(201);
|
|
|
|
const applicationResponse = await request(app)
|
|
.post('/api/applications')
|
|
.set('Authorization', `Bearer ${candidateToken}`)
|
|
.send({
|
|
jobId: job.id,
|
|
coverLetter: 'Excited to apply'
|
|
})
|
|
.expect(201);
|
|
|
|
const applicationId = applicationResponse.body.application.id;
|
|
|
|
const listForCandidate = await request(app)
|
|
.get('/api/applications')
|
|
.set('Authorization', `Bearer ${candidateToken}`)
|
|
.expect(200);
|
|
|
|
expect(listForCandidate.body.applications).toHaveLength(1);
|
|
|
|
await request(app)
|
|
.put(`/api/applications/${applicationId}/status`)
|
|
.set('Authorization', `Bearer ${employerToken}`)
|
|
.send({ status: 'reviewed' })
|
|
.expect(200);
|
|
|
|
await request(app)
|
|
.put(`/api/applications/${applicationId}/notes`)
|
|
.set('Authorization', `Bearer ${employerToken}`)
|
|
.send({ notes: 'Strong automation background' })
|
|
.expect(200);
|
|
|
|
const detailResponse = await request(app)
|
|
.get(`/api/applications/${applicationId}`)
|
|
.set('Authorization', `Bearer ${employerToken}`)
|
|
.expect(200);
|
|
|
|
expect(detailResponse.body.status).toBe('reviewed');
|
|
expect(detailResponse.body.notes).toBe('Strong automation background');
|
|
});
|
|
});
|