add error notification if user deletion is unsuccessful and add DELETE_USER_SUCCESS

This commit is contained in:
Maren Süwer
2018-07-19 11:23:20 +02:00
parent 2689a20ee8
commit 9593a18a55
3 changed files with 101 additions and 19 deletions

View File

@@ -23,7 +23,8 @@ import {
DELETE_USER_SUCCESS,
DELETE_USER_FAILURE,
deleteUser,
updateUserFailure
updateUserFailure,
deleteUserSuccess
} from "./users";
import reducer from "./users";
@@ -365,6 +366,44 @@ describe("users reducer", () => {
expect(ford.loading).toBeFalsy();
});
it("should delete deleted user in users in state if delete user action is successful", () => {
const state = {
users: {
entries: [
"zaphod",
"ford"
]
}
};
const newState = reducer(state, deleteUserSuccess(userZaphod));
expect(newState.users.entries).toContain("ford");
expect(newState.users.entries).not.toContain("zaphod");
});
it("should delete deleted user in usersByNames in state if delete user action is successful", () => {
const state = {
users: {
entries: [
"zaphod",
"ford"
]
},
usersByNames: {
zaphod: {
entry: userZaphod
},
ford: {
entry: userFord
}
}
};
const newState = reducer(state, deleteUserSuccess(userZaphod));
const ford = newState.usersByNames["ford"];
const zaphod = newState.usersByNames["zaphod"];
expect(zaphod).toBeUndefined();
expect(ford.entry).toBe(userFord);
});
it("should set global error state if one user could not be deleted", () => {
const state = {
users: {