-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrecruitment.test.ts
More file actions
118 lines (106 loc) · 3.83 KB
/
recruitment.test.ts
File metadata and controls
118 lines (106 loc) · 3.83 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
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
import RecruitmentServices from '../../src/services/recruitment.services';
import { AccessDeniedAdminOnlyException, HttpException, NotFoundException } from '../../src/utils/errors.utils';
import { batmanAppAdmin, wonderwomanGuest, supermanAdmin, member } from '../test-data/users.test-data';
import { createTestOrganization, createTestUser, resetUsers } from '../test-utils';
describe('Recruitment Tests', () => {
let orgId: string;
beforeEach(async () => {
orgId = (await createTestOrganization()).organizationId;
});
afterEach(async () => {
await resetUsers();
});
describe('Create Milestone', () => {
it('Fails if user is not an admin', async () => {
await expect(
async () =>
await RecruitmentServices.createMilestone(
await createTestUser(wonderwomanGuest, orgId),
'name',
'description',
new Date(),
orgId
)
).rejects.toThrow(new AccessDeniedAdminOnlyException('create a milestone'));
});
it('Fails if organization doesn`t exist', async () => {
await expect(
async () =>
await RecruitmentServices.createMilestone(
await createTestUser(batmanAppAdmin, orgId),
'name',
'description',
new Date(),
'1'
)
).rejects.toThrow(new HttpException(400, `Organization with id 1 doesn't exist`));
});
it('Succeeds and creates a milestone', async () => {
const result = await RecruitmentServices.createMilestone(
await createTestUser(batmanAppAdmin, orgId),
'name',
'description',
new Date('11/12/24'),
orgId
);
expect(result.name).toEqual('name');
expect(result.description).toEqual('description');
expect(result.dateOfEvent).toEqual(new Date('11/12/24'));
});
});
describe('Get All Milestones', () => {
it('Fails if the organization ID is wrong', async () => {
await expect(
async () =>
await RecruitmentServices.createMilestone(
await createTestUser(batmanAppAdmin, orgId),
'name',
'description',
new Date(),
'55'
)
).rejects.toThrow(new HttpException(400, `Organization with id 55 doesn't exist`));
});
it('Succeeds and gets all the milestones', async () => {
const milestone1 = await RecruitmentServices.createMilestone(
await createTestUser(batmanAppAdmin, orgId),
'name',
'description',
new Date('11/11/24'),
orgId
);
const milestone2 = await RecruitmentServices.createMilestone(
await createTestUser(supermanAdmin, orgId),
'name2',
'description2',
new Date('1/1/1'),
orgId
);
const result = await RecruitmentServices.getAllMilestones(orgId);
expect(result).toStrictEqual([milestone1, milestone2]);
});
});
describe('Create FAQ', () => {
it('Fails if user is not an admin', async () => {
await expect(
async () => await RecruitmentServices.createFaq(await createTestUser(member, orgId), 'question', 'answer', orgId)
).rejects.toThrow(new AccessDeniedAdminOnlyException('create an faq'));
});
it('Fails if organization doesn`t exist', async () => {
await expect(
async () =>
await RecruitmentServices.createFaq(await createTestUser(batmanAppAdmin, orgId), 'question', 'answer', '5')
).rejects.toThrow(new NotFoundException('Organization', `5`));
});
it('Succeeds and creates an FAQ', async () => {
const result = await RecruitmentServices.createFaq(
await createTestUser(batmanAppAdmin, orgId),
'question',
'answer',
orgId
);
expect(result.question).toEqual('question');
expect(result.answer).toEqual('answer');
});
});
});