diff --git a/src/components/common/PageLoading.test.jsx b/src/components/common/PageLoading.test.jsx index 68c5db167..c27e0723e 100644 --- a/src/components/common/PageLoading.test.jsx +++ b/src/components/common/PageLoading.test.jsx @@ -19,7 +19,7 @@ describe('', () => { expect(srElement).toHaveLength(1); expect(srElement.text()).toEqual(message); }); - it('should not throw a warning with correct props', () => { + it('does not throw a warning with correct props', () => { const expectedProps = { srMessage: 'Loading...' }; const propsError = checkProps(PageLoading, expectedProps); diff --git a/src/users/UserPage.test.jsx b/src/users/UserPage.test.jsx index 28e01d11c..a4607b7c3 100644 --- a/src/users/UserPage.test.jsx +++ b/src/users/UserPage.test.jsx @@ -36,7 +36,7 @@ describe('User Page', () => { }); describe('Checking PropTypes', () => { - it('Should not throw a warning', () => { + it('does not throw a warning', () => { const expectedProps = { location }; const propsError = checkProps(UserPage, expectedProps); @@ -86,6 +86,22 @@ describe('User Page', () => { it('when user email is not found', async () => { const validEmail = 'valid-non-existing@email.com'; location.search = `?email=${validEmail}`; + mockAuthApiToThrowError(404); + const expectedAlert = messages.USER_EMAIL_IDENTIFIER_NOT_FOUND_ERROR.replace( + '{identifier}', + validEmail, + ); + + const wrapper = mount(); + await waitForComponentToPaint(wrapper); + + const alert = wrapper.find('.alert'); + expect(alert).toHaveLength(1); + expect(alert.text()).toEqual(expectedAlert); + }); + it('when user email is not found', async () => { + const validEmail = 'valid@email.com'; + location.search = `?email=${validEmail}`; mockAuthApiToThrowError(500); const wrapper = mount(); diff --git a/src/users/UserSearch.test.jsx b/src/users/UserSearch.test.jsx index 6ca6a200f..42473f7ce 100644 --- a/src/users/UserSearch.test.jsx +++ b/src/users/UserSearch.test.jsx @@ -14,18 +14,18 @@ describe('User Search Page', () => { }); describe('Checking PropTypes', () => { - it('should not throw a warning', () => { + it('does not throw a warning', () => { const propsError = checkProps(UserSearch, props); expect(propsError).toBeUndefined(); }); - it('should not throw error with undefined userIdentifier', () => { + it('does not throw error with undefined userIdentifier', () => { delete props.userIdentifier; const propsError = checkProps(UserSearch, props); expect(propsError).toBeUndefined(); }); - it('should throw error with undefined search handler', () => { + it('does throw error with undefined search handler', () => { const propsError = checkProps(UserSearch, {}); expect(propsError).not.toBeUndefined(); diff --git a/src/users/api.js b/src/users/api.js index 75c5f7043..45b0ce612 100644 --- a/src/users/api.js +++ b/src/users/api.js @@ -42,10 +42,11 @@ export async function getSsoRecords(username) { export async function getUser(userIdentifier) { let url = `${getConfig().LMS_BASE_URL}/api/user/v1/accounts`; - // I am avoiding an `else` case here because we have already validated the input - // to fall into one of these cases. const identifierIsEmail = isEmail(userIdentifier); const identifierIsUsername = isValidUsername(userIdentifier); + + // todo: we have already validated the input to fall into one of these cases. + // The following `if` is not required. if (!(identifierIsEmail || identifierIsUsername)) { throw new Error('Invalid Argument!'); } diff --git a/src/utils/index.test.js b/src/utils/index.test.js index c3ac10426..e2863ac5a 100644 --- a/src/utils/index.test.js +++ b/src/utils/index.test.js @@ -5,13 +5,14 @@ describe('Test Utils', () => { const invalidEmails = [ '', ' ', + undefined, 'invalid email@mail.com', 'invalid-email', '2020email.com', 'www.email.com', ]; const validUsername = ['staff', 'admin123']; - const invalidUsername = ['', ' ', 'invalid username', '%invalid']; + const invalidUsername = ['', ' ', undefined, 'invalid username', '%invalid']; test.each(validEmails)('isEmail return true for %s', (email) => { expect(isEmail(email)).toBe(true); });