@@ -3,6 +3,7 @@ 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 {
6+ createTestGuestDefinition ,
67 createTestMilestone ,
78 createTestFaq ,
89 createTestFAQ ,
@@ -341,6 +342,7 @@ describe('Recruitment Tests', () => {
341342 expect ( deletedTestFaq ?. dateDeleted ) . not . toBe ( null ) ;
342343 } ) ;
343344 } ) ;
345+
344346 describe ( 'Create Guest Definitions' , ( ) => {
345347 it ( 'Successful guest definition creation' , async ( ) => {
346348 const def = await RecruitmentServices . createGuestDefinition (
@@ -378,6 +380,49 @@ describe('Recruitment Tests', () => {
378380 } ) ;
379381 } ) ;
380382
383+ describe ( 'Delete Guest Definition' , ( ) => {
384+ it ( 'Fails if user is not an admin' , async ( ) => {
385+ const admin = await createTestUser ( batmanAppAdmin , orgId ) ;
386+ const guest = await createTestUser ( wonderwomanGuest , orgId ) ;
387+ const testDef = await createTestGuestDefinition ( admin , orgId ) ;
388+
389+ await expect (
390+ async ( ) => await RecruitmentServices . deleteGuestDefinition ( guest , testDef . definitionId , organization )
391+ ) . rejects . toThrow ( new AccessDeniedAdminOnlyException ( 'delete a guestDefinition' ) ) ;
392+ } ) ;
393+
394+ it ( 'Fails if definition does not exist' , async ( ) => {
395+ const admin = await createTestUser ( batmanAppAdmin , orgId ) ;
396+
397+ await expect (
398+ async ( ) => await RecruitmentServices . deleteGuestDefinition ( admin , 'fake-id' , organization )
399+ ) . rejects . toThrow ( new NotFoundException ( 'Guest Definition' , 'fake-id' ) ) ;
400+ } ) ;
401+
402+ it ( 'Fails if definition is already deleted' , async ( ) => {
403+ const admin = await createTestUser ( batmanAppAdmin , orgId ) ;
404+ const testDef = await createTestGuestDefinition ( admin , orgId ) ;
405+ await RecruitmentServices . deleteGuestDefinition ( admin , testDef . definitionId , organization ) ;
406+
407+ await expect (
408+ async ( ) => await RecruitmentServices . deleteGuestDefinition ( admin , testDef . definitionId , organization )
409+ ) . rejects . toThrow ( new DeletedException ( 'Guest Definition' , testDef . definitionId ) ) ;
410+ } ) ;
411+
412+ it ( 'Successfully deletes a guest definition' , async ( ) => {
413+ const admin = await createTestUser ( batmanAppAdmin , orgId ) ;
414+ const testDef = await createTestGuestDefinition ( admin , orgId ) ;
415+
416+ await RecruitmentServices . deleteGuestDefinition ( admin , testDef . definitionId , organization ) ;
417+
418+ const deletedTestDef = await prisma . guest_Definition . findUnique ( {
419+ where : { definitionId : testDef . definitionId }
420+ } ) ;
421+
422+ expect ( deletedTestDef ?. dateDeleted ) . not . toBe ( null ) ;
423+ } ) ;
424+ } ) ;
425+
381426 describe ( 'Get All Guest Definitions' , ( ) => {
382427 it ( 'Succeeds and gets all the guest definitions' , async ( ) => {
383428 const def = await RecruitmentServices . createGuestDefinition (
0 commit comments