Skip to content

Commit

Permalink
feature(read-book): prevent redirect on update profile failure
Browse files Browse the repository at this point in the history
  • Loading branch information
segunolalive committed Dec 23, 2017
1 parent a3ecdb1 commit 66e78d9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion client/__tests__/actions/userActions.spec.js
Expand Up @@ -41,7 +41,7 @@ describe('user Actions', () => {
});
const expectedActions = [];
const store = mockStore({});
return store.dispatch(updateProfile({})).then(() => {
return store.dispatch(updateProfile({})).catch(() => {
expect(store.getActions()).toEqual(expectedActions);
expect(Notify.error).toHaveBeenCalled();
});
Expand Down
10 changes: 10 additions & 0 deletions client/__tests__/components/Dashboard/PdfViewer.spec.jsx
Expand Up @@ -54,6 +54,16 @@ describe('PdfViewer Component', () => {
expect(wrapper.state().page).toBe(1);
});

it('should call onDocumentError if file load encounters an error', () => {
const wrapper = setUp();
const onPageCompleteSpy = jest.spyOn(
wrapper.instance(), 'onDocumentError'
);
wrapper.instance().onDocumentError(new Error('failed to load pdf'));
expect(onPageCompleteSpy).toHaveBeenCalledTimes(1);
expect(wrapper.state().fileError).toBe(true);
});

it('should call setPage when page is manually inserted', () => {
const wrapper = setUp();
const setPageSpy = jest.spyOn(
Expand Down
Expand Up @@ -8,7 +8,7 @@ import { mockStoreData } from '../../__mocks__/mockData';

let props = {
...mockStoreData.authReducer,
updateProfile: jest.fn(),
updateProfile: jest.fn(() => Promise.resolve(1)),
};

const middleware = [thunk];
Expand Down
5 changes: 4 additions & 1 deletion client/actions/updateProfile.js
Expand Up @@ -22,7 +22,10 @@ const updateProfile = profile => dispatch => (
Notify.success(response.data.message);
return dispatch(loginUser(response.data));
})
.catch(error => reportNetworkError(error))
.catch((error) => {
reportNetworkError(error);
return Promise.reject(error);
})
);

export default updateProfile;
6 changes: 4 additions & 2 deletions client/components/Dashboard/UpdateProfile.jsx
Expand Up @@ -46,8 +46,10 @@ export class UpdateProfile extends Component {
*/
handleSubmit = (event) => {
event.preventDefault();
this.props.updateProfile(this.state);
this.setState(() => ({ redirect: true }));
this.props.updateProfile(this.state)
.then(() => this.setState(() => ({ redirect: true })))
.catch(() => {})
;
}

/**
Expand Down

0 comments on commit 66e78d9

Please sign in to comment.