@@ -481,6 +481,36 @@ describe('Invitations Routes', () => {
481481
482482 expect ( response . statusCode ) . toBe ( 400 ) ;
483483 } ) ;
484+
485+ it ( 'should return 503 when email server is not configured' , async ( ) => {
486+ // Mock the invitations service to throw email not configured error
487+ const { invitationsService } = await import (
488+ '../../../modules/invitations/service.js'
489+ ) ;
490+ const originalInviteUser = invitationsService . inviteUser ;
491+ invitationsService . inviteUser = vi . fn ( ) . mockRejectedValueOnce (
492+ new Error ( 'Email server is not configured' )
493+ ) ;
494+
495+ const response = await app . inject ( {
496+ method : 'POST' ,
497+ url : `/api/v1/invitations/${ testOrganization . id } /invite` ,
498+ headers : {
499+ Authorization : `Bearer ${ authToken } ` ,
500+ } ,
501+ payload : {
502+ email : 'newuser@test.com' ,
503+ role : 'member' ,
504+ } ,
505+ } ) ;
506+
507+ expect ( response . statusCode ) . toBe ( 503 ) ;
508+ const body = JSON . parse ( response . payload ) ;
509+ expect ( body . error ) . toContain ( 'Email server is not configured' ) ;
510+
511+ // Restore original
512+ invitationsService . inviteUser = originalInviteUser ;
513+ } ) ;
484514 } ) ;
485515
486516 // ==========================================================================
@@ -755,5 +785,37 @@ describe('Invitations Routes', () => {
755785
756786 expect ( response . statusCode ) . toBe ( 404 ) ;
757787 } ) ;
788+
789+ it ( 'should return 503 when email server is not configured' , async ( ) => {
790+ const invitation = await createTestInvitation (
791+ testOrganization . id ,
792+ 'resend503@test.com' ,
793+ testUser . id
794+ ) ;
795+
796+ // Mock the invitations service to throw email not configured error
797+ const { invitationsService } = await import (
798+ '../../../modules/invitations/service.js'
799+ ) ;
800+ const originalResendInvitation = invitationsService . resendInvitation ;
801+ invitationsService . resendInvitation = vi . fn ( ) . mockRejectedValueOnce (
802+ new Error ( 'Email server is not configured' )
803+ ) ;
804+
805+ const response = await app . inject ( {
806+ method : 'POST' ,
807+ url : `/api/v1/invitations/${ testOrganization . id } /invitations/${ invitation . id } /resend` ,
808+ headers : {
809+ Authorization : `Bearer ${ authToken } ` ,
810+ } ,
811+ } ) ;
812+
813+ expect ( response . statusCode ) . toBe ( 503 ) ;
814+ const body = JSON . parse ( response . payload ) ;
815+ expect ( body . error ) . toContain ( 'Email server is not configured' ) ;
816+
817+ // Restore original
818+ invitationsService . resendInvitation = originalResendInvitation ;
819+ } ) ;
758820 } ) ;
759821} ) ;
0 commit comments