-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrecruitment.test.ts
More file actions
602 lines (534 loc) · 19.9 KB
/
recruitment.test.ts
File metadata and controls
602 lines (534 loc) · 19.9 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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
import prisma from '../../src/prisma/prisma.js';
import { Organization, User } from '@prisma/client';
import RecruitmentServices from '../../src/services/recruitment.services.js';
import { AccessDeniedAdminOnlyException, DeletedException, NotFoundException } from '../../src/utils/errors.utils.js';
import {
createTestGuestDefinition,
createTestMilestone,
createTestFaq,
createTestFAQ,
createTestOrganization,
createTestUser,
resetUsers
} from '../test-utils.js';
import {
batmanAppAdmin,
wonderwomanGuest,
supermanAdmin,
member,
theVisitorGuest,
flashAdmin,
alfred
} from '../test-data/users.test-data.js';
describe('Recruitment Tests', () => {
let orgId: string;
let organization: Organization;
let superman: User;
beforeEach(async () => {
organization = await createTestOrganization();
orgId = organization.organizationId;
superman = await createTestUser(supermanAdmin, orgId);
});
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(superman, '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(
superman,
'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(
superman,
'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(
superman,
'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 NotFoundException('Milestone', 'id1'));
});
it('Fails if milestone is already deleted', async () => {
const testSuperman = superman;
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 = superman;
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(superman, 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);
});
});
describe('Create Guest Definitions', () => {
it('Successful guest definition creation', async () => {
const def = await RecruitmentServices.createGuestDefinition(
superman,
organization,
'test term',
'test description',
2,
'iconname',
'buttonTxt',
'buttonLink'
);
expect(def.term).toBe('test term');
expect(def.description).toBe('test description');
expect(def.order).toBe(2);
expect(def.icon).toBe('iconname');
expect(def.buttonText).toBe('buttonTxt');
expect(def.buttonLink).toBe('buttonLink');
});
it('Fails when non admin tries to create guest definition', async () => {
await expect(
async () =>
await RecruitmentServices.createGuestDefinition(
await createTestUser(member, orgId),
organization,
'test term',
'test description',
2,
'iconname',
'buttonTxt',
'buttonLink'
)
).rejects.toThrow(new AccessDeniedAdminOnlyException('create a guest definition'));
});
});
describe('Get a single guest definition', () => {
it('Get a single guest definition works', async () => {
const guestDefinition = await RecruitmentServices.createGuestDefinition(
superman,
organization,
'test term',
'test description',
2,
'iconname',
'buttonTxt',
'buttonLink'
);
const result = await RecruitmentServices.getGuestDefinition(orgId, guestDefinition.definitionId);
expect(result).toStrictEqual(guestDefinition);
});
it('Get a single guest definition fails', async () => {
const nonExistingDefinitionId = 'nonExistingDefinition';
await expect(async () => RecruitmentServices.getGuestDefinition(orgId, nonExistingDefinitionId)).rejects.toThrow(
new NotFoundException('Guest Definition', nonExistingDefinitionId)
);
});
});
describe('Edit Guest Definition', () => {
it('Fails if user is not an admin', async () => {
await expect(
async () =>
await RecruitmentServices.editGuestDefinition(
await createTestUser(member, orgId),
organization,
'test term',
'test description',
'test definition id',
2,
'buttonTxt',
'buttonLink'
)
).rejects.toThrow(new AccessDeniedAdminOnlyException('edit a guest definition'));
});
it('Fails if guest definition doesn`t exist', async () => {
await expect(
async () =>
await RecruitmentServices.editGuestDefinition(
await createTestUser(batmanAppAdmin, orgId),
organization,
'term',
'description',
'definition id',
2,
'buttonTxt',
'buttonLink'
)
).rejects.toThrow(new NotFoundException('Guest Definition', 'definition id'));
});
it('Successful edit guest definition', async () => {
const def = await RecruitmentServices.createGuestDefinition(
superman,
organization,
'test term',
'test description',
2,
'iconname',
'buttonTxt',
'buttonLink'
);
const edited = await RecruitmentServices.editGuestDefinition(
await createTestUser(batmanAppAdmin, orgId),
organization,
'new term',
'new description',
def.definitionId,
4,
'new icon',
'new text',
'new link'
);
expect(edited.term).toBe('new term');
expect(edited.description).toBe('new description');
expect(edited.order).toBe(4);
expect(edited.icon).toBe('new icon');
expect(edited.buttonText).toBe('new text');
expect(edited.buttonLink).toBe('new link');
});
it('Edit guest definition fails if defintion is deleted', async () => {
const def = await RecruitmentServices.createGuestDefinition(
superman,
organization,
'test term',
'test description',
2,
'iconname',
'buttonTxt',
'buttonLink'
);
const batman = await createTestUser(batmanAppAdmin, orgId);
await RecruitmentServices.deleteGuestDefinition(batman, def.definitionId, organization);
await expect(
async () =>
await RecruitmentServices.editGuestDefinition(
batman,
organization,
'term',
'description',
def.definitionId,
2,
'buttonTxt',
'buttonLink'
)
).rejects.toThrow(new DeletedException('Guest Definition', def.definitionId));
});
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(
superman,
'name',
'description',
new Date('11/12/24'),
milestone.milestoneId,
organization
)
).rejects.toThrow(new NotFoundException('Milestone', milestone.milestoneId));
});
});
describe('Delete Guest Definition', () => {
it('Fails if user is not an admin', async () => {
const admin = await createTestUser(batmanAppAdmin, orgId);
const guest = await createTestUser(wonderwomanGuest, orgId);
const testDef = await createTestGuestDefinition(admin, orgId);
await expect(
async () => await RecruitmentServices.deleteGuestDefinition(guest, testDef.definitionId, organization)
).rejects.toThrow(new AccessDeniedAdminOnlyException('delete a guestDefinition'));
});
it('Fails if definition does not exist', async () => {
const admin = await createTestUser(batmanAppAdmin, orgId);
await expect(
async () => await RecruitmentServices.deleteGuestDefinition(admin, 'fake-id', organization)
).rejects.toThrow(new NotFoundException('Guest Definition', 'fake-id'));
});
it('Fails if definition is already deleted', async () => {
const admin = await createTestUser(batmanAppAdmin, orgId);
const testDef = await createTestGuestDefinition(admin, orgId);
await RecruitmentServices.deleteGuestDefinition(admin, testDef.definitionId, organization);
await expect(
async () => await RecruitmentServices.deleteGuestDefinition(admin, testDef.definitionId, organization)
).rejects.toThrow(new DeletedException('Guest Definition', testDef.definitionId));
});
it('Successfully deletes a guest definition', async () => {
const admin = await createTestUser(batmanAppAdmin, orgId);
const testDef = await createTestGuestDefinition(admin, orgId);
await RecruitmentServices.deleteGuestDefinition(admin, testDef.definitionId, organization);
const deletedTestDef = await prisma.guest_Definition.findUnique({
where: { definitionId: testDef.definitionId }
});
expect(deletedTestDef?.dateDeleted).not.toBe(null);
});
});
describe('Get All Guest Definitions', () => {
it('Succeeds and gets all the guest definitions', async () => {
const def = await RecruitmentServices.createGuestDefinition(
superman,
organization,
'test term',
'test description',
2,
'iconname',
'buttonTxt',
'buttonLink'
);
const def2 = await RecruitmentServices.createGuestDefinition(
superman,
organization,
'test term',
'test description',
2,
'iconname',
'buttonTxt',
'buttonLink'
);
const result = await RecruitmentServices.getAllGuestDefinitions(organization);
expect(result).toStrictEqual([def, def2]);
});
});
});