-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrecruitment.test.ts
More file actions
353 lines (313 loc) · 12.1 KB
/
recruitment.test.ts
File metadata and controls
353 lines (313 loc) · 12.1 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
import prisma from '../../src/prisma/prisma';
import { Organization } from '@prisma/client';
import RecruitmentServices from '../../src/services/recruitment.services';
import {
AccessDeniedAdminOnlyException,
DeletedException,
HttpException,
NotFoundException
} from '../../src/utils/errors.utils';
import {
createTestMilestone,
createTestFaq,
createTestFAQ,
createTestOrganization,
createTestUser,
resetUsers
} from '../test-utils';
import {
batmanAppAdmin,
wonderwomanGuest,
supermanAdmin,
member,
theVisitorGuest,
flashAdmin,
alfred
} from '../test-data/users.test-data';
describe('Recruitment Tests', () => {
let orgId: string;
let organization: Organization;
beforeEach(async () => {
organization = await createTestOrganization();
orgId = organization.organizationId;
});
afterEach(async () => {
await resetUsers();
});
describe('Get All FAQs', () => {
it('Succeeds and gets all the FAQs', async () => {
const faq1 = await RecruitmentServices.createOrganizationFaq(
await createTestUser(batmanAppAdmin, orgId),
'question',
'answer',
organization
);
const faq2 = await RecruitmentServices.createOrganizationFaq(
await createTestUser(supermanAdmin, orgId),
'question2',
'answer2',
organization
);
const result = await RecruitmentServices.getAllOrganizationFaqs(organization);
expect(result).toHaveLength(2);
expect(result[0].question).toEqual(faq1.question);
expect(result[0].answer).toEqual(faq1.answer);
expect(result[1].question).toEqual(faq2.question);
expect(result[1].answer).toEqual(faq2.answer);
});
describe('Edit FAQ', () => {
it('Fails if user is not an admin', async () => {
await expect(
async () =>
await RecruitmentServices.editFAQ(
'What is your return policy?',
'You can return any item within 30 days of purchase.',
await createTestUser(wonderwomanGuest, orgId),
organization,
'faq123'
)
).rejects.toThrow(new AccessDeniedAdminOnlyException('edit frequently asked questions'));
});
it('Fails if FAQ does not exist', async () => {
await expect(
async () =>
await RecruitmentServices.editFAQ(
'What is your return policy?',
'You can return any item within 30 days of purchase.',
await createTestUser(batmanAppAdmin, orgId),
organization,
'nonExistentFaqId'
)
).rejects.toThrow(new NotFoundException('Faq', 'nonExistentFaqId'));
});
it('Succeeds and edits an FAQ', async () => {
await createTestFAQ(orgId, 'faq123');
const result = await RecruitmentServices.editFAQ(
'What is your return policy?',
'You can return any item within 60 days of purchase.',
await createTestUser(batmanAppAdmin, orgId),
organization,
'faq123'
);
expect(result.question).toEqual('What is your return policy?');
expect(result.answer).toEqual('You can return any item within 60 days of purchase.');
});
});
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(),
organization
)
).rejects.toThrow(new AccessDeniedAdminOnlyException('create a milestone'));
});
it('Succeeds and creates a milestone', async () => {
const result = await RecruitmentServices.createMilestone(
await createTestUser(batmanAppAdmin, orgId),
'name',
'description',
new Date('11/12/24'),
organization
);
expect(result.name).toEqual('name');
expect(result.description).toEqual('description');
expect(result.dateOfEvent).toEqual(new Date('11/12/24'));
});
});
describe('Edit Milestone', () => {
it('Fails if user is not an admin', async () => {
await expect(
async () =>
await RecruitmentServices.editMilestone(
await createTestUser(wonderwomanGuest, orgId),
'name',
'description',
new Date(),
'1',
organization
)
).rejects.toThrow(new AccessDeniedAdminOnlyException('create a milestone'));
});
it('Fails if milestone doesn`t exist', async () => {
await expect(
async () =>
await RecruitmentServices.editMilestone(
await createTestUser(batmanAppAdmin, orgId),
'name',
'description',
new Date('11/12/24'),
'1',
organization
)
).rejects.toThrow(new NotFoundException('Milestone', 1));
});
it('Fails if milestone is deleted', async () => {
const milestone = await RecruitmentServices.createMilestone(
await createTestUser(batmanAppAdmin, orgId),
'name',
'description',
new Date('11/12/24'),
organization
);
await prisma.milestone.delete({
where: {
milestoneId: milestone.milestoneId
}
});
await expect(
async () =>
await RecruitmentServices.editMilestone(
await createTestUser(supermanAdmin, orgId),
'name',
'description',
new Date('11/12/24'),
milestone.milestoneId,
organization
)
).rejects.toThrow(new NotFoundException('Milestone', milestone.milestoneId));
});
it('Succeeds and edits a milestone', async () => {
const milestone = await RecruitmentServices.createMilestone(
await createTestUser(batmanAppAdmin, orgId),
'name',
'description',
new Date('11/12/24'),
organization
);
const updatedMilestone = await RecruitmentServices.editMilestone(
await createTestUser(supermanAdmin, orgId),
'new name',
'new description',
new Date('11/14/24'),
milestone.milestoneId,
organization
);
expect(updatedMilestone.name).toEqual('new name');
expect(updatedMilestone.description).toEqual('new description');
expect(updatedMilestone.dateOfEvent).toEqual(new Date('11/14/24'));
});
});
describe('Get All Milestones', () => {
it('Succeeds and gets all the milestones', async () => {
const milestone1 = await RecruitmentServices.createMilestone(
await createTestUser(batmanAppAdmin, orgId),
'name',
'description',
new Date('11/11/24'),
organization
);
const milestone2 = await RecruitmentServices.createMilestone(
await createTestUser(supermanAdmin, orgId),
'name2',
'description2',
new Date('1/1/1'),
organization
);
const result = await RecruitmentServices.getAllMilestones(organization);
expect(result).toStrictEqual([milestone1, milestone2]);
});
});
describe('Create FAQ', () => {
it('Fails if user is not an admin', async () => {
await expect(
async () =>
await RecruitmentServices.createOrganizationFaq(
await createTestUser(member, orgId),
'question',
'answer',
organization
)
).rejects.toThrow(new AccessDeniedAdminOnlyException('create an faq'));
});
describe('Delete a single milestone', () => {
it('Fails if user is not admin', async () => {
await expect(
async () =>
await RecruitmentServices.deleteMilestone(await createTestUser(wonderwomanGuest, orgId), 'id', organization)
).rejects.toThrow(new AccessDeniedAdminOnlyException('delete milestone'));
});
it('Fails if milestoneId is not found', async () => {
await expect(
async () =>
await RecruitmentServices.deleteMilestone(await createTestUser(batmanAppAdmin, orgId), 'id1', organization)
).rejects.toThrow(new HttpException(400, 'Milestone with id: id1 not found!'));
});
it('Fails if milestone is already deleted', async () => {
const testSuperman = await createTestUser(supermanAdmin, orgId);
const testMilestone = await createTestMilestone(testSuperman, orgId);
await RecruitmentServices.deleteMilestone(testSuperman, testMilestone.milestoneId, organization);
await expect(
async () => await RecruitmentServices.deleteMilestone(testSuperman, testMilestone.milestoneId, organization)
).rejects.toThrow(new DeletedException('Milestone', testMilestone.milestoneId));
});
it('Succeeds and deletes milestone', async () => {
const testSuperman = await createTestUser(supermanAdmin, orgId);
const testMilestone1 = await createTestMilestone(testSuperman, orgId);
await RecruitmentServices.deleteMilestone(testSuperman, testMilestone1.milestoneId, organization);
const updatedTestMilestone1 = await prisma.milestone.findUnique({
where: { milestoneId: testMilestone1.milestoneId }
});
expect(updatedTestMilestone1?.dateDeleted).not.toBe(null);
});
describe('Create FAQ', () => {
it('Fails if user is not an admin', async () => {
await expect(
async () =>
await RecruitmentServices.createOrganizationFaq(
await createTestUser(member, orgId),
'question',
'answer',
organization
)
).rejects.toThrow(new AccessDeniedAdminOnlyException('create an faq'));
});
it('Succeeds and creates an FAQ', async () => {
const result = await RecruitmentServices.createOrganizationFaq(
await createTestUser(batmanAppAdmin, orgId),
'question',
'answer',
organization
);
expect(result.question).toEqual('question');
expect(result.answer).toEqual('answer');
});
});
});
});
});
describe('Delete FAQ', () => {
it('Fails if user is not an admin', async () => {
const testFaq = await createTestFaq(await createTestUser(batmanAppAdmin, orgId), orgId);
await expect(
async () =>
await RecruitmentServices.deleteFaq(await createTestUser(theVisitorGuest, orgId), testFaq.faqId, organization)
).rejects.toThrow(new AccessDeniedAdminOnlyException('delete an faq'));
});
it('Fails if faq doesn`t exist', async () => {
await expect(
async () => await RecruitmentServices.deleteFaq(await createTestUser(batmanAppAdmin, orgId), '1', organization)
).rejects.toThrow(new NotFoundException('Faq', '1'));
});
it('Fails if faq is already deleted', async () => {
const testFaq = await createTestFaq(await createTestUser(batmanAppAdmin, orgId), orgId);
await RecruitmentServices.deleteFaq(await createTestUser(flashAdmin, orgId), testFaq.faqId, organization);
await expect(
async () =>
await RecruitmentServices.deleteFaq(await createTestUser(supermanAdmin, orgId), testFaq.faqId, organization)
).rejects.toThrow(new DeletedException('Faq', testFaq.faqId));
});
it('Succeeds and deletes an FAQ', async () => {
const testFaq = await createTestFaq(await createTestUser(batmanAppAdmin, orgId), orgId);
await RecruitmentServices.deleteFaq(await createTestUser(alfred, orgId), testFaq.faqId, organization);
const deletedTestFaq = await prisma.frequentlyAskedQuestion.findUnique({
where: { faqId: testFaq.faqId }
});
expect(deletedTestFaq?.dateDeleted).not.toBe(null);
});
});
});