@@ -379,6 +379,130 @@ describe('Recruitment Tests', () => {
379379 ) . rejects . toThrow ( new AccessDeniedAdminOnlyException ( 'create a guest definition' ) ) ;
380380 } ) ;
381381 } ) ;
382+ describe ( 'Edit Guest Definition' , ( ) => {
383+ it ( 'Fails if user is not an admin' , async ( ) => {
384+ await expect (
385+ async ( ) =>
386+ await RecruitmentServices . editGuestDefinition (
387+ await createTestUser ( member , orgId ) ,
388+ organization ,
389+ 'test term' ,
390+ 'test description' ,
391+ 'test definition id' ,
392+ 2 ,
393+ 'buttonTxt' ,
394+ 'buttonLink'
395+ )
396+ ) . rejects . toThrow ( new AccessDeniedAdminOnlyException ( 'edit a guest definition' ) ) ;
397+ } ) ;
398+
399+ it ( 'Fails if guest definition doesn`t exist' , async ( ) => {
400+ await expect (
401+ async ( ) =>
402+ await RecruitmentServices . editGuestDefinition (
403+ await createTestUser ( batmanAppAdmin , orgId ) ,
404+ organization ,
405+ 'term' ,
406+ 'description' ,
407+ 'definition id' ,
408+ 2 ,
409+ 'buttonTxt' ,
410+ 'buttonLink'
411+ )
412+ ) . rejects . toThrow ( new NotFoundException ( 'Guest Definition' , 'definition id' ) ) ;
413+ } ) ;
414+
415+ it ( 'Successful edit guest definition' , async ( ) => {
416+ const def = await RecruitmentServices . createGuestDefinition (
417+ superman ,
418+ organization ,
419+ 'test term' ,
420+ 'test description' ,
421+ 2 ,
422+ 'iconname' ,
423+ 'buttonTxt' ,
424+ 'buttonLink'
425+ ) ;
426+
427+ const edited = await RecruitmentServices . editGuestDefinition (
428+ await createTestUser ( batmanAppAdmin , orgId ) ,
429+ organization ,
430+ 'new term' ,
431+ 'new description' ,
432+ def . definitionId ,
433+ 4 ,
434+ 'new icon' ,
435+ 'new text' ,
436+ 'new link'
437+ ) ;
438+
439+ expect ( edited . term ) . toBe ( 'new term' ) ;
440+ expect ( edited . description ) . toBe ( 'new description' ) ;
441+ expect ( edited . order ) . toBe ( 4 ) ;
442+ expect ( edited . icon ) . toBe ( 'new icon' ) ;
443+ expect ( edited . buttonText ) . toBe ( 'new text' ) ;
444+ expect ( edited . buttonLink ) . toBe ( 'new link' ) ;
445+ } ) ;
446+
447+ it ( 'Edit guest definition fails if defintion is deleted' , async ( ) => {
448+ const def = await RecruitmentServices . createGuestDefinition (
449+ superman ,
450+ organization ,
451+ 'test term' ,
452+ 'test description' ,
453+ 2 ,
454+ 'iconname' ,
455+ 'buttonTxt' ,
456+ 'buttonLink'
457+ ) ;
458+
459+ const batman = await createTestUser ( batmanAppAdmin , orgId ) ;
460+
461+ await RecruitmentServices . deleteGuestDefinition ( batman , def . definitionId , organization ) ;
462+
463+ await expect (
464+ async ( ) =>
465+ await RecruitmentServices . editGuestDefinition (
466+ batman ,
467+ organization ,
468+ 'term' ,
469+ 'description' ,
470+ def . definitionId ,
471+ 2 ,
472+ 'buttonTxt' ,
473+ 'buttonLink'
474+ )
475+ ) . rejects . toThrow ( new DeletedException ( 'Guest Definition' , def . definitionId ) ) ;
476+ } ) ;
477+
478+ it ( 'Fails if milestone is deleted' , async ( ) => {
479+ const milestone = await RecruitmentServices . createMilestone (
480+ await createTestUser ( batmanAppAdmin , orgId ) ,
481+ 'name' ,
482+ 'description' ,
483+ new Date ( '11/12/24' ) ,
484+ organization
485+ ) ;
486+
487+ await prisma . milestone . delete ( {
488+ where : {
489+ milestoneId : milestone . milestoneId
490+ }
491+ } ) ;
492+
493+ await expect (
494+ async ( ) =>
495+ await RecruitmentServices . editMilestone (
496+ superman ,
497+ 'name' ,
498+ 'description' ,
499+ new Date ( '11/12/24' ) ,
500+ milestone . milestoneId ,
501+ organization
502+ )
503+ ) . rejects . toThrow ( new NotFoundException ( 'Milestone' , milestone . milestoneId ) ) ;
504+ } ) ;
505+ } ) ;
382506
383507 describe ( 'Delete Guest Definition' , ( ) => {
384508 it ( 'Fails if user is not an admin' , async ( ) => {
0 commit comments