add error handling for fetching users

This commit is contained in:
Maren Süwer
2018-07-19 11:57:59 +02:00
parent 9593a18a55
commit 8562b9d65e
3 changed files with 43 additions and 17 deletions

View File

@@ -24,7 +24,8 @@ import {
DELETE_USER_FAILURE,
deleteUser,
updateUserFailure,
deleteUserSuccess
deleteUserSuccess,
failedToFetchUsers
} from "./users";
import reducer from "./users";
@@ -442,6 +443,20 @@ describe("users reducer", () => {
expect(newState.users.error).toBe(null);
});
it("should set error state if users could not be fetched", () => {
const state = {
users: {
error: null,
loading: true
}
};
const error = new Error("could not edit user zaphod: ..");
const newState = reducer(state, failedToFetchUsers('/users', error));
expect(newState.users.error).toBe(error);
expect(newState.users.loading).toBeFalsy();
});
it("should not replace whole usersByNames map when fetching users", () => {
const oldState = {
usersByNames: {