11import prisma from '../../src/prisma/prisma.js' ;
2- import { Organization } from '@prisma/client' ;
2+ import { Organization , User } from '@prisma/client' ;
33import RecruitmentServices from '../../src/services/recruitment.services.js' ;
44import { AccessDeniedAdminOnlyException , DeletedException , NotFoundException } from '../../src/utils/errors.utils.js' ;
55import {
@@ -23,9 +23,11 @@ import {
2323describe ( 'Recruitment Tests' , ( ) => {
2424 let orgId : string ;
2525 let organization : Organization ;
26+ let superman : User ;
2627 beforeEach ( async ( ) => {
2728 organization = await createTestOrganization ( ) ;
2829 orgId = organization . organizationId ;
30+ superman = await createTestUser ( supermanAdmin , orgId ) ;
2931 } ) ;
3032
3133 afterEach ( async ( ) => {
@@ -40,12 +42,7 @@ describe('Recruitment Tests', () => {
4042 'answer' ,
4143 organization
4244 ) ;
43- const faq2 = await RecruitmentServices . createOrganizationFaq (
44- await createTestUser ( supermanAdmin , orgId ) ,
45- 'question2' ,
46- 'answer2' ,
47- organization
48- ) ;
45+ const faq2 = await RecruitmentServices . createOrganizationFaq ( superman , 'question2' , 'answer2' , organization ) ;
4946 const result = await RecruitmentServices . getAllOrganizationFaqs ( organization ) ;
5047 expect ( result ) . toHaveLength ( 2 ) ;
5148 expect ( result [ 0 ] . question ) . toEqual ( faq1 . question ) ;
@@ -172,7 +169,7 @@ describe('Recruitment Tests', () => {
172169 await expect (
173170 async ( ) =>
174171 await RecruitmentServices . editMilestone (
175- await createTestUser ( supermanAdmin , orgId ) ,
172+ superman ,
176173 'name' ,
177174 'description' ,
178175 new Date ( '11/12/24' ) ,
@@ -192,7 +189,7 @@ describe('Recruitment Tests', () => {
192189 ) ;
193190
194191 const updatedMilestone = await RecruitmentServices . editMilestone (
195- await createTestUser ( supermanAdmin , orgId ) ,
192+ superman ,
196193 'new name' ,
197194 'new description' ,
198195 new Date ( '11/14/24' ) ,
@@ -217,7 +214,7 @@ describe('Recruitment Tests', () => {
217214 ) ;
218215
219216 const milestone2 = await RecruitmentServices . createMilestone (
220- await createTestUser ( supermanAdmin , orgId ) ,
217+ superman ,
221218 'name2' ,
222219 'description2' ,
223220 new Date ( '1/1/1' ) ,
@@ -257,7 +254,7 @@ describe('Recruitment Tests', () => {
257254 } ) ;
258255
259256 it ( 'Fails if milestone is already deleted' , async ( ) => {
260- const testSuperman = await createTestUser ( supermanAdmin , orgId ) ;
257+ const testSuperman = superman ;
261258 const testMilestone = await createTestMilestone ( testSuperman , orgId ) ;
262259 await RecruitmentServices . deleteMilestone ( testSuperman , testMilestone . milestoneId , organization ) ;
263260
@@ -267,7 +264,7 @@ describe('Recruitment Tests', () => {
267264 } ) ;
268265
269266 it ( 'Succeeds and deletes milestone' , async ( ) => {
270- const testSuperman = await createTestUser ( supermanAdmin , orgId ) ;
267+ const testSuperman = superman ;
271268 const testMilestone1 = await createTestMilestone ( testSuperman , orgId ) ;
272269
273270 await RecruitmentServices . deleteMilestone ( testSuperman , testMilestone1 . milestoneId , organization ) ;
@@ -327,10 +324,9 @@ describe('Recruitment Tests', () => {
327324 const testFaq = await createTestFaq ( await createTestUser ( batmanAppAdmin , orgId ) , orgId ) ;
328325 await RecruitmentServices . deleteFaq ( await createTestUser ( flashAdmin , orgId ) , testFaq . faqId , organization ) ;
329326
330- await expect (
331- async ( ) =>
332- await RecruitmentServices . deleteFaq ( await createTestUser ( supermanAdmin , orgId ) , testFaq . faqId , organization )
333- ) . rejects . toThrow ( new DeletedException ( 'Faq' , testFaq . faqId ) ) ;
327+ await expect ( async ( ) => await RecruitmentServices . deleteFaq ( superman , testFaq . faqId , organization ) ) . rejects . toThrow (
328+ new DeletedException ( 'Faq' , testFaq . faqId )
329+ ) ;
334330 } ) ;
335331
336332 it ( 'Succeeds and deletes an FAQ' , async ( ) => {
@@ -345,4 +341,40 @@ describe('Recruitment Tests', () => {
345341 expect ( deletedTestFaq ?. dateDeleted ) . not . toBe ( null ) ;
346342 } ) ;
347343 } ) ;
344+ describe ( 'Create Guest Definitions' , ( ) => {
345+ it ( 'Successful guest definition creation' , async ( ) => {
346+ const def = await RecruitmentServices . createGuestDefinition (
347+ superman ,
348+ organization ,
349+ 'test term' ,
350+ 'test description' ,
351+ 2 ,
352+ 'iconname' ,
353+ 'buttonTxt' ,
354+ 'buttonLink'
355+ ) ;
356+
357+ expect ( def . term ) . toBe ( 'test term' ) ;
358+ expect ( def . description ) . toBe ( 'test description' ) ;
359+ expect ( def . order ) . toBe ( 2 ) ;
360+ expect ( def . icon ) . toBe ( 'iconname' ) ;
361+ expect ( def . buttonText ) . toBe ( 'buttonTxt' ) ;
362+ expect ( def . buttonLink ) . toBe ( 'buttonLink' ) ;
363+ } ) ;
364+ it ( 'Fails when non admin tries to create guest definition' , async ( ) => {
365+ await expect (
366+ async ( ) =>
367+ await RecruitmentServices . createGuestDefinition (
368+ await createTestUser ( member , orgId ) ,
369+ organization ,
370+ 'test term' ,
371+ 'test description' ,
372+ 2 ,
373+ 'iconname' ,
374+ 'buttonTxt' ,
375+ 'buttonLink'
376+ )
377+ ) . rejects . toThrow ( new AccessDeniedAdminOnlyException ( 'create a guest definition' ) ) ;
378+ } ) ;
379+ } ) ;
348380} ) ;
0 commit comments