Skip to content

Commit

Permalink
OCLOMRS-328: Make error messages on the front-end more descriptive (#245
Browse files Browse the repository at this point in the history
)
  • Loading branch information
AGMETEOR authored and dkayiwa committed Dec 10, 2018
1 parent dcee939 commit 33c642c
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 20 deletions.
11 changes: 9 additions & 2 deletions src/redux/actions/auth/authActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ const loginAction = ({ username, password }) => (dispatch) => {
return dispatch(login(response));
}).catch((error) => {
if (error.response) {
return dispatch(loginFailed(error.response.data.detail));
let errorMessage = error.response.data.detail;
if (errorMessage === 'Not found.') {
errorMessage = 'No such user was found.';
}
if (errorMessage === 'Passwords did not match.') {
errorMessage = 'Either the username or password you provided is incorrect.';
}
return dispatch(loginFailed(errorMessage));
}
return dispatch(loginFailed('Request cannot be made'));
return dispatch(loginFailed('Please check your internet connection.'));
});
};

Expand Down
4 changes: 2 additions & 2 deletions src/redux/actions/concepts/addBulkConcepts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const fetchBulkConcepts = (source = 'CIEL') => async (dispatch) => {
dispatch(isFetching(false));
} catch (error) {
dispatch(isFetching(false));
notify.show('an error occurred, reload your browser', 'error', 3000);
notify.show('An error occurred with your internet connection, please fix it and try reloading the page.', 'error', 3000);
}
};

Expand Down Expand Up @@ -50,7 +50,7 @@ export const fetchFilteredConcepts = (source = 'CIEL', query = '') => async (
dispatch(isFetching(false));
} catch (error) {
dispatch(isFetching(false));
notify.show('an error occurred, reload your browser', 'error', 3000);
notify.show('An error occurred with your internet connection, please fix it and try reloading the page.', 'error', 3000);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/redux/actions/concepts/dictionaryConcepts.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const addConceptToDictionary = (id, dataUrl) => async (dispatch) => {
const response = await instance.put(url, data);
dispatch(isSuccess(response.data, ADD_CONCEPT_TO_DICTIONARY));
} catch (error) {
notify.show('an error occurred', 'error', 3000);
notify.show('An error occurred', 'error', 3000);
}
dispatch(isFetching(false));
};
Expand Down
6 changes: 3 additions & 3 deletions src/redux/actions/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const fetchUser = username => async (dispatch) => {
const response = await instance.get(url);
dispatch(isSuccess(response.data, GET_USER));
} catch (error) {
notify.show('an error occurred, reload the page', 'error', 3000);
notify.show('An error occurred with your internet connection, please fix it and try reloading the page.', 'error', 3000);
}
};

Expand All @@ -27,7 +27,7 @@ export const fetchUserOrganizations = username => async (dispatch) => {
const response = await instance.get(url);
dispatch(isSuccess(response.data, FETCH_USER_ORGANIZATION));
} catch (error) {
notify.show('an error occurred, reload the page', 'error', 3000);
notify.show('An error occurred with your internet connection, please fix it and try reloading the page.', 'error', 3000);
}
};

Expand All @@ -39,7 +39,7 @@ export const fetchsUserDictionaries = username => async (dispatch) => {
const result = filterUserPayload(username, response.data);
dispatch(isSuccess(result, FETCH_USER_DICTIONARY));
} catch (error) {
notify.show('an error occurred, reload the page', 'error', 3000);
notify.show('An error occurred with your internet connection, please fix it and try reloading the page.', 'error', 3000);
}
};

Expand Down
76 changes: 64 additions & 12 deletions src/tests/Login/actions/login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import users from '../../__mocks__/users';
jest.mock('react-notify-toast');
const mockStore = configureStore([thunk]);

const data = {
username: 'testuser',
password: '12345678',
};

describe('Test suite for login action', () => {
beforeEach(() => {
moxios.install();
Expand All @@ -24,11 +29,6 @@ describe('Test suite for login action', () => {
});

it('should handle login', async () => {
const data = {
username: 'testuser',
password: '12345678',
};

moxios.wait(() => {
const request = moxios.requests.mostRecent();
request.respondWith({
Expand All @@ -53,12 +53,7 @@ describe('Test suite for login action', () => {
});
});

it('should handle invalid password', async () => {
const data = {
username: 'testuser',
password: '1234567',
};

it('should handle invalid password for admin', async () => {
moxios.wait(() => {
const request = moxios.requests.mostRecent();
request.respondWith({
Expand All @@ -76,7 +71,64 @@ describe('Test suite for login action', () => {
},
{
type: AUTHENTICATION_FAILED,
payload: { errorMessage: 'Passwords did not match.' },
payload: { errorMessage: 'Either the username or password you provided is incorrect.' },
loading: false,
}];

const store = mockStore();
return store
.dispatch(loginAction(data))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});

it('should handle invalid credentials for non-admin users', async () => {
moxios.wait(() => {
const request = moxios.requests.mostRecent();
request.respondWith({
status: 401,
response: {
detail: 'Not found.',
},
});
});

const expectedActions = [
{
type: AUTHENTICATION_IN_PROGRESS,
loading: true,
},
{
type: AUTHENTICATION_FAILED,
payload: { errorMessage: 'No such user was found.' },
loading: false,
}];

const store = mockStore();
return store
.dispatch(loginAction(data))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});

it('should handle no internet connection', async () => {
moxios.wait(() => {
const request = moxios.requests.mostRecent();
request.respondWith({
response: undefined,
});
});

const expectedActions = [
{
type: AUTHENTICATION_IN_PROGRESS,
loading: true,
},
{
type: AUTHENTICATION_FAILED,
payload: { errorMessage: 'Please check your internet connection.' },
loading: false,
}];

Expand Down

0 comments on commit 33c642c

Please sign in to comment.