diff --git a/src/app/directives/library-membership.directive.spec.ts b/src/app/directives/library-membership.directive.spec.ts index e6e2b44e4..11e58ce18 100644 --- a/src/app/directives/library-membership.directive.spec.ts +++ b/src/app/directives/library-membership.directive.spec.ts @@ -179,5 +179,35 @@ describe('LibraryMembershipDirective', () => { tick(); expect(directive.error.emit).toHaveBeenCalled(); })); + + it('should emit specific error message on invalid email address server error', fakeAsync(() => { + const emitErrorSpy = spyOn(directive.error, 'emit'); + const selection = { entry: { id: 'no-membership-requested' } }; + const change = new SimpleChange(null, selection, true); + directive.ngOnChanges({ selection: change }); + tick(); + + const testData = [ + { + fixture: 'Failed to resolve sender mail address', + expected: 'APP.MESSAGES.ERRORS.INVALID_SENDER_EMAIL' + }, + { + fixture: 'All recipients for the mail action were invalid', + expected: 'APP.MESSAGES.ERRORS.INVALID_RECEIVER_EMAIL' + } + ]; + + testData.forEach(data => { + addMembershipSpy.and.returnValue(throwError({ message: data.fixture })); + emitErrorSpy.calls.reset(); + directive.toggleMembershipRequest(); + tick(); + expect(emitErrorSpy).toHaveBeenCalledWith({ + error: { message: data.fixture }, + i18nKey: data.expected + }); + }); + })); }); }); diff --git a/src/app/directives/library-membership.directive.ts b/src/app/directives/library-membership.directive.ts index fda7569f2..8eb3e2b5f 100644 --- a/src/app/directives/library-membership.directive.ts +++ b/src/app/directives/library-membership.directive.ts @@ -134,12 +134,15 @@ export class LibraryMembershipDirective implements OnChanges { const senderEmailCheck = 'Failed to resolve sender mail address'; const receiverEmailCheck = 'All recipients for the mail action were invalid'; - if ( - error.message && - (error.message.includes(senderEmailCheck) || - error.message.includes(receiverEmailCheck)) - ) { - errWithMessage.i18nKey = 'APP.MESSAGES.ERRORS.INVALID_EMAIL'; + + if (error.message) { + if (error.message.includes(senderEmailCheck)) { + errWithMessage.i18nKey = + 'APP.MESSAGES.ERRORS.INVALID_SENDER_EMAIL'; + } else if (error.message.includes(receiverEmailCheck)) { + errWithMessage.i18nKey = + 'APP.MESSAGES.ERRORS.INVALID_RECEIVER_EMAIL'; + } } this.error.emit(errWithMessage); diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 3aa3db4fb..b916f3fc5 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -278,7 +278,8 @@ "JOIN_REQUEST_FAILED": "Cannot join the library", "JOIN_CANCEL_FAILED": "Cannot cancel the request to join the library", "LEAVE_LIBRARY_FAILED": "Cannot leave this library", - "INVALID_EMAIL": "Sender or receiver email configured on server not valid, contact IT" + "INVALID_SENDER_EMAIL": "Your email address must be valid before requesting to join.", + "INVALID_RECEIVER_EMAIL": "Recipient(s) email address not valid, contact IT." }, "UPLOAD": { "ERROR": {