Files
SCM-Manager/scm-ui/ui-webapp/src/groups/modules/groups.test.js

682 lines
18 KiB
JavaScript
Raw Normal View History

2018-07-31 10:53:44 +02:00
//@flow
import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
import fetchMock from "fetch-mock";
2018-07-31 11:30:30 +02:00
import reducer, {
fetchGroups,
2018-07-31 13:04:09 +02:00
FETCH_GROUPS,
2018-07-31 10:53:44 +02:00
FETCH_GROUPS_PENDING,
FETCH_GROUPS_SUCCESS,
2018-07-31 11:30:30 +02:00
FETCH_GROUPS_FAILURE,
2018-07-31 13:04:09 +02:00
fetchGroupsSuccess,
isPermittedToCreateGroups,
getGroupsFromState,
getFetchGroupsFailure,
isFetchGroupsPending,
2018-07-31 13:49:46 +02:00
selectListAsCollection,
2018-11-05 14:12:35 +01:00
fetchGroupByLink,
fetchGroupByName,
2018-07-31 15:09:45 +02:00
FETCH_GROUP_PENDING,
FETCH_GROUP_SUCCESS,
FETCH_GROUP_FAILURE,
fetchGroupSuccess,
getFetchGroupFailure,
FETCH_GROUP,
isFetchGroupPending,
getGroupByName,
2018-07-31 13:49:46 +02:00
createGroup,
CREATE_GROUP_SUCCESS,
CREATE_GROUP_PENDING,
2018-07-31 14:22:15 +02:00
CREATE_GROUP_FAILURE,
isCreateGroupPending,
CREATE_GROUP,
2018-07-31 16:48:28 +02:00
getCreateGroupFailure,
deleteGroup,
DELETE_GROUP_PENDING,
DELETE_GROUP_SUCCESS,
DELETE_GROUP_FAILURE,
DELETE_GROUP,
deleteGroupSuccess,
isDeleteGroupPending,
2018-08-02 11:38:08 +02:00
getDeleteGroupFailure,
modifyGroup,
MODIFY_GROUP_PENDING,
MODIFY_GROUP_SUCCESS,
2018-10-09 16:17:25 +02:00
MODIFY_GROUP_FAILURE,
getCreateGroupLink
2018-07-31 13:49:46 +02:00
} from "./groups";
2018-10-01 17:22:03 +02:00
const GROUPS_URL = "/api/v2/groups";
const URL_HUMAN_GROUP = "http://localhost:8081/api/v2/groups/humanGroup";
2018-10-09 16:17:25 +02:00
const URL = "/groups";
2018-07-31 10:53:44 +02:00
2018-07-31 13:04:09 +02:00
const error = new Error("You have an error!");
2018-07-31 15:09:45 +02:00
const humanGroup = {
2018-07-31 11:30:30 +02:00
creationDate: "2018-07-31T08:39:07.860Z",
description: "This is a group",
2018-07-31 15:09:45 +02:00
name: "humanGroup",
2018-07-31 11:30:30 +02:00
type: "xml",
properties: {},
members: ["userZaphod"],
_links: {
self: {
href: URL_HUMAN_GROUP
2018-07-31 11:30:30 +02:00
},
delete: {
href: URL_HUMAN_GROUP
2018-07-31 11:30:30 +02:00
},
update: {
href: URL_HUMAN_GROUP
2018-07-31 11:30:30 +02:00
}
},
_embedded: {
2018-07-31 13:49:46 +02:00
members: [
{
name: "userZaphod",
_links: {
self: {
2018-10-01 17:22:03 +02:00
href: "http://localhost:8081/api/v2/users/userZaphod"
2018-07-31 13:49:46 +02:00
}
2018-07-31 11:30:30 +02:00
}
}
2018-07-31 13:49:46 +02:00
]
2018-07-31 11:30:30 +02:00
}
2018-07-31 10:53:44 +02:00
};
2018-07-31 15:09:45 +02:00
const emptyGroup = {
2018-07-31 11:30:30 +02:00
creationDate: "2018-07-31T08:39:07.860Z",
description: "This is a group",
2018-07-31 15:09:45 +02:00
name: "emptyGroup",
2018-07-31 11:30:30 +02:00
type: "xml",
properties: {},
members: [],
_links: {
self: {
2018-10-01 17:22:03 +02:00
href: "http://localhost:8081/api/v2/groups/emptyGroup"
2018-07-31 11:30:30 +02:00
},
delete: {
2018-10-01 17:22:03 +02:00
href: "http://localhost:8081/api/v2/groups/emptyGroup"
2018-07-31 11:30:30 +02:00
},
update: {
2018-10-09 16:17:25 +02:00
href: "http://localhost:8081/api/v2/groups/emptyGroup"
2018-07-31 11:30:30 +02:00
}
},
_embedded: {
members: []
}
2018-07-31 10:53:44 +02:00
};
const responseBody = {
page: 0,
pageTotal: 1,
_links: {
self: {
2018-10-01 17:22:03 +02:00
href: "http://localhost:3000/api/v2/groups/?page=0&pageSize=10"
2018-07-31 10:53:44 +02:00
},
first: {
2018-10-01 17:22:03 +02:00
href: "http://localhost:3000/api/v2/groups/?page=0&pageSize=10"
2018-07-31 10:53:44 +02:00
},
last: {
2018-10-01 17:22:03 +02:00
href: "http://localhost:3000/api/v2/groups/?page=0&pageSize=10"
2018-07-31 10:53:44 +02:00
},
create: {
2018-10-01 17:22:03 +02:00
href: "http://localhost:3000/api/v2/groups/"
2018-07-31 10:53:44 +02:00
}
},
_embedded: {
2018-07-31 15:09:45 +02:00
groups: [humanGroup, emptyGroup]
2018-07-31 10:53:44 +02:00
}
};
const response = {
headers: { "content-type": "application/json" },
responseBody
};
describe("groups fetch()", () => {
const mockStore = configureMockStore([thunk]);
afterEach(() => {
fetchMock.reset();
fetchMock.restore();
});
it("should successfully fetch groups", () => {
fetchMock.getOnce(GROUPS_URL, response);
const expectedActions = [
{ type: FETCH_GROUPS_PENDING },
{
type: FETCH_GROUPS_SUCCESS,
payload: response
}
];
const store = mockStore({});
2018-10-09 16:17:25 +02:00
return store.dispatch(fetchGroups(URL)).then(() => {
2018-07-31 10:53:44 +02:00
expect(store.getActions()).toEqual(expectedActions);
});
});
it("should fail getting groups on HTTP 500", () => {
fetchMock.getOnce(GROUPS_URL, {
status: 500
});
const store = mockStore({});
2018-10-09 16:17:25 +02:00
return store.dispatch(fetchGroups(URL)).then(() => {
2018-07-31 10:53:44 +02:00
const actions = store.getActions();
expect(actions[0].type).toEqual(FETCH_GROUPS_PENDING);
expect(actions[1].type).toEqual(FETCH_GROUPS_FAILURE);
expect(actions[1].payload).toBeDefined();
});
});
2018-07-31 13:49:46 +02:00
2018-11-05 14:12:35 +01:00
it("should sucessfully fetch single group by name", () => {
2018-07-31 16:48:28 +02:00
fetchMock.getOnce(GROUPS_URL + "/humanGroup", humanGroup);
2018-07-31 15:09:45 +02:00
const store = mockStore({});
2018-11-05 14:12:35 +01:00
return store.dispatch(fetchGroupByName(URL, "humanGroup")).then(() => {
2018-07-31 15:09:45 +02:00
const actions = store.getActions();
expect(actions[0].type).toEqual(FETCH_GROUP_PENDING);
expect(actions[1].type).toEqual(FETCH_GROUP_SUCCESS);
expect(actions[1].payload).toBeDefined();
});
});
2018-11-05 14:12:35 +01:00
it("should fail fetching single group by name on HTTP 500", () => {
2018-07-31 16:48:28 +02:00
fetchMock.getOnce(GROUPS_URL + "/humanGroup", {
2018-07-31 15:09:45 +02:00
status: 500
});
const store = mockStore({});
2018-11-05 14:12:35 +01:00
return store.dispatch(fetchGroupByName(URL, "humanGroup")).then(() => {
const actions = store.getActions();
expect(actions[0].type).toEqual(FETCH_GROUP_PENDING);
expect(actions[1].type).toEqual(FETCH_GROUP_FAILURE);
expect(actions[1].payload).toBeDefined();
});
});
it("should sucessfully fetch single group", () => {
fetchMock.getOnce(URL_HUMAN_GROUP, humanGroup);
2018-11-05 14:12:35 +01:00
const store = mockStore({});
return store.dispatch(fetchGroupByLink(humanGroup)).then(() => {
const actions = store.getActions();
expect(actions[0].type).toEqual(FETCH_GROUP_PENDING);
expect(actions[1].type).toEqual(FETCH_GROUP_SUCCESS);
expect(actions[1].payload).toBeDefined();
});
});
it("should fail fetching single group on HTTP 500", () => {
fetchMock.getOnce(URL_HUMAN_GROUP, {
2018-11-05 14:12:35 +01:00
status: 500
});
const store = mockStore({});
return store.dispatch(fetchGroupByLink(humanGroup)).then(() => {
2018-07-31 15:09:45 +02:00
const actions = store.getActions();
expect(actions[0].type).toEqual(FETCH_GROUP_PENDING);
expect(actions[1].type).toEqual(FETCH_GROUP_FAILURE);
expect(actions[1].payload).toBeDefined();
});
});
2018-07-31 13:49:46 +02:00
it("should successfully create group", () => {
fetchMock.postOnce(GROUPS_URL, {
status: 201
});
const store = mockStore({});
2018-10-09 16:17:25 +02:00
return store.dispatch(createGroup(URL, humanGroup)).then(() => {
2018-07-31 13:49:46 +02:00
const actions = store.getActions();
expect(actions[0].type).toEqual(CREATE_GROUP_PENDING);
expect(actions[1].type).toEqual(CREATE_GROUP_SUCCESS);
});
});
2018-08-01 13:40:54 +02:00
it("should call the callback after creating group", () => {
fetchMock.postOnce(GROUPS_URL, {
status: 201
});
let called = false;
const callMe = () => {
called = true;
2018-08-31 10:47:42 +02:00
};
2018-08-01 13:40:54 +02:00
const store = mockStore({});
2018-10-09 16:17:25 +02:00
return store.dispatch(createGroup(URL, humanGroup, callMe)).then(() => {
2018-08-01 13:40:54 +02:00
const actions = store.getActions();
expect(actions[0].type).toEqual(CREATE_GROUP_PENDING);
expect(actions[1].type).toEqual(CREATE_GROUP_SUCCESS);
expect(called).toEqual(true);
});
});
2018-07-31 13:49:46 +02:00
it("should fail creating group on HTTP 500", () => {
fetchMock.postOnce(GROUPS_URL, {
status: 500
});
const store = mockStore({});
2018-10-09 16:17:25 +02:00
return store.dispatch(createGroup(URL, humanGroup)).then(() => {
2018-07-31 13:49:46 +02:00
const actions = store.getActions();
expect(actions[0].type).toEqual(CREATE_GROUP_PENDING);
expect(actions[1].type).toEqual(CREATE_GROUP_FAILURE);
expect(actions[1].payload).toBeDefined();
expect(actions[1].payload instanceof Error).toBeTruthy();
});
});
2018-07-31 16:48:28 +02:00
2018-08-02 11:38:08 +02:00
it("should successfully modify group", () => {
fetchMock.putOnce(URL_HUMAN_GROUP, {
2018-08-02 11:38:08 +02:00
status: 204
});
fetchMock.getOnce(URL_HUMAN_GROUP, humanGroup);
2018-08-02 11:38:08 +02:00
2018-10-09 16:17:25 +02:00
const store = mockStore({});
2018-08-02 11:38:08 +02:00
return store.dispatch(modifyGroup(humanGroup)).then(() => {
const actions = store.getActions();
expect(actions[0].type).toEqual(MODIFY_GROUP_PENDING);
expect(actions[1].type).toEqual(MODIFY_GROUP_SUCCESS);
2018-11-05 14:12:35 +01:00
expect(actions[2].type).toEqual(FETCH_GROUP_PENDING);
2018-08-31 10:47:42 +02:00
expect(actions[1].payload).toEqual(humanGroup);
2018-08-02 11:38:08 +02:00
});
2018-08-31 10:47:42 +02:00
});
2018-08-02 11:38:08 +02:00
it("should call the callback after modifying group", () => {
fetchMock.putOnce(URL_HUMAN_GROUP, {
2018-08-02 11:38:08 +02:00
status: 204
});
fetchMock.getOnce(URL_HUMAN_GROUP, humanGroup);
2018-08-02 11:38:08 +02:00
let called = false;
const callback = () => {
called = true;
2018-08-31 10:47:42 +02:00
};
2018-10-09 16:17:25 +02:00
const store = mockStore({});
2018-08-02 11:38:08 +02:00
return store.dispatch(modifyGroup(humanGroup, callback)).then(() => {
const actions = store.getActions();
expect(actions[0].type).toEqual(MODIFY_GROUP_PENDING);
expect(actions[1].type).toEqual(MODIFY_GROUP_SUCCESS);
2018-11-05 14:12:35 +01:00
expect(actions[2].type).toEqual(FETCH_GROUP_PENDING);
2018-08-02 11:38:08 +02:00
expect(called).toBe(true);
});
2018-08-31 10:47:42 +02:00
});
2018-08-02 11:38:08 +02:00
it("should fail modifying group on HTTP 500", () => {
fetchMock.putOnce(URL_HUMAN_GROUP, {
2018-08-02 11:38:08 +02:00
status: 500
});
2018-10-09 16:17:25 +02:00
const store = mockStore({});
2018-08-02 11:38:08 +02:00
return store.dispatch(modifyGroup(humanGroup)).then(() => {
const actions = store.getActions();
expect(actions[0].type).toEqual(MODIFY_GROUP_PENDING);
expect(actions[1].type).toEqual(MODIFY_GROUP_FAILURE);
expect(actions[1].payload).toBeDefined();
});
2018-08-31 10:47:42 +02:00
});
2018-08-02 11:38:08 +02:00
2018-07-31 16:48:28 +02:00
it("should delete successfully group humanGroup", () => {
fetchMock.deleteOnce(URL_HUMAN_GROUP, {
2018-07-31 16:48:28 +02:00
status: 204
});
const store = mockStore({});
return store.dispatch(deleteGroup(humanGroup)).then(() => {
const actions = store.getActions();
expect(actions.length).toBe(2);
expect(actions[0].type).toEqual(DELETE_GROUP_PENDING);
expect(actions[0].payload).toBe(humanGroup);
expect(actions[1].type).toEqual(DELETE_GROUP_SUCCESS);
});
});
it("should call the callback, after successful delete", () => {
fetchMock.deleteOnce(URL_HUMAN_GROUP, {
2018-07-31 16:48:28 +02:00
status: 204
});
let called = false;
const callMe = () => {
called = true;
};
const store = mockStore({});
return store.dispatch(deleteGroup(humanGroup, callMe)).then(() => {
expect(called).toBeTruthy();
});
});
it("should fail to delete group humanGroup", () => {
fetchMock.deleteOnce(URL_HUMAN_GROUP, {
2018-07-31 16:48:28 +02:00
status: 500
});
const store = mockStore({});
return store.dispatch(deleteGroup(humanGroup)).then(() => {
const actions = store.getActions();
expect(actions[0].type).toEqual(DELETE_GROUP_PENDING);
expect(actions[0].payload).toBe(humanGroup);
expect(actions[1].type).toEqual(DELETE_GROUP_FAILURE);
expect(actions[1].payload).toBeDefined();
});
});
2018-07-31 10:53:44 +02:00
});
2018-07-31 11:30:30 +02:00
describe("groups reducer", () => {
2018-07-31 15:09:45 +02:00
it("should update state correctly according to FETCH_GROUPS_SUCCESS action", () => {
2018-07-31 11:30:30 +02:00
const newState = reducer({}, fetchGroupsSuccess(responseBody));
expect(newState.list).toEqual({
2018-07-31 15:09:45 +02:00
entries: ["humanGroup", "emptyGroup"],
2018-07-31 11:30:30 +02:00
entry: {
groupCreatePermission: true,
page: 0,
pageTotal: 1,
_links: responseBody._links
}
});
expect(newState.byNames).toEqual({
2018-07-31 15:09:45 +02:00
humanGroup: humanGroup,
emptyGroup: emptyGroup
2018-07-31 11:30:30 +02:00
});
expect(newState.list.entry.groupCreatePermission).toBeTruthy();
});
it("should set groupCreatePermission to true if update link is present", () => {
const newState = reducer({}, fetchGroupsSuccess(responseBody));
expect(newState.list.entry.groupCreatePermission).toBeTruthy();
});
2018-07-31 15:09:45 +02:00
it("should not replace whole byNames map when fetching groups", () => {
2018-07-31 11:30:30 +02:00
const oldState = {
byNames: {
2018-07-31 15:09:45 +02:00
emptyGroup: emptyGroup
2018-07-31 11:30:30 +02:00
}
};
const newState = reducer(oldState, fetchGroupsSuccess(responseBody));
2018-07-31 15:09:45 +02:00
expect(newState.byNames["humanGroup"]).toBeDefined();
expect(newState.byNames["emptyGroup"]).toBeDefined();
2018-07-31 11:30:30 +02:00
});
2018-07-31 15:09:45 +02:00
it("should set groupCreatePermission to true if create link is present", () => {
2018-07-31 11:30:30 +02:00
const newState = reducer({}, fetchGroupsSuccess(responseBody));
expect(newState.list.entry.groupCreatePermission).toBeTruthy();
2018-07-31 15:09:45 +02:00
expect(newState.list.entries).toEqual(["humanGroup", "emptyGroup"]);
expect(newState.byNames["emptyGroup"]).toBeTruthy();
expect(newState.byNames["humanGroup"]).toBeTruthy();
});
it("should update state according to FETCH_GROUP_SUCCESS action", () => {
const newState = reducer({}, fetchGroupSuccess(emptyGroup));
expect(newState.byNames["emptyGroup"]).toBe(emptyGroup);
});
it("should affect groups state nor the state of other groups", () => {
const newState = reducer(
{
list: {
entries: ["humanGroup"]
}
},
fetchGroupSuccess(emptyGroup)
);
expect(newState.byNames["emptyGroup"]).toBe(emptyGroup);
expect(newState.list.entries).toEqual(["humanGroup"]);
2018-07-31 11:30:30 +02:00
});
2018-07-31 15:09:45 +02:00
2018-07-31 16:48:28 +02:00
it("should remove group from state when delete succeeds", () => {
const state = {
list: {
entries: ["humanGroup", "emptyGroup"]
},
byNames: {
humanGroup: humanGroup,
emptyGroup: emptyGroup
}
};
const newState = reducer(state, deleteGroupSuccess(emptyGroup));
expect(newState.byNames["humanGroup"]).toBeDefined();
expect(newState.byNames["emptyGroup"]).toBeFalsy();
expect(newState.list.entries).toEqual(["humanGroup"]);
});
2018-07-31 11:30:30 +02:00
});
2018-07-31 13:04:09 +02:00
describe("selector tests", () => {
it("should return an empty object", () => {
expect(selectListAsCollection({})).toEqual({});
expect(selectListAsCollection({ groups: { a: "a" } })).toEqual({});
});
it("should return a state slice collection", () => {
const collection = {
page: 3,
totalPages: 42
};
const state = {
groups: {
list: {
entry: collection
}
}
};
expect(selectListAsCollection(state)).toBe(collection);
});
2018-08-02 10:06:13 +02:00
it("should return false when groupCreatePermission is false", () => {
2018-07-31 13:04:09 +02:00
expect(isPermittedToCreateGroups({})).toBe(false);
expect(isPermittedToCreateGroups({ groups: { list: { entry: {} } } })).toBe(
false
);
expect(
isPermittedToCreateGroups({
groups: { list: { entry: { groupCreatePermission: false } } }
})
).toBe(false);
});
2018-08-02 10:06:13 +02:00
it("should return true when groupCreatePermission is true", () => {
2018-07-31 13:04:09 +02:00
const state = {
groups: {
list: {
entry: {
groupCreatePermission: true
}
}
}
};
expect(isPermittedToCreateGroups(state)).toBe(true);
});
2018-10-09 16:17:25 +02:00
it("should return create Group link", () => {
const state = {
groups: {
list: {
entry: {
_links: {
create: {
href: "/create"
}
}
}
}
}
};
expect(getCreateGroupLink(state)).toBe("/create");
});
2018-07-31 13:04:09 +02:00
it("should get groups from state", () => {
const state = {
groups: {
list: {
entries: ["a", "b"]
},
byNames: {
a: { name: "a" },
b: { name: "b" }
}
}
};
2018-10-09 16:17:25 +02:00
2018-07-31 13:04:09 +02:00
expect(getGroupsFromState(state)).toEqual([{ name: "a" }, { name: "b" }]);
});
2018-08-02 08:44:13 +02:00
it("should return null when there are no groups in the state", () => {
2018-08-31 10:47:42 +02:00
expect(getGroupsFromState({})).toBe(null);
2018-08-02 08:44:13 +02:00
});
2018-07-31 13:04:09 +02:00
it("should return true, when fetch groups is pending", () => {
const state = {
pending: {
[FETCH_GROUPS]: true
}
};
expect(isFetchGroupsPending(state)).toEqual(true);
});
it("should return false, when fetch groups is not pending", () => {
expect(isFetchGroupsPending({})).toEqual(false);
});
it("should return error when fetch groups did fail", () => {
const state = {
failure: {
[FETCH_GROUPS]: error
}
};
expect(getFetchGroupsFailure(state)).toEqual(error);
});
2018-07-31 15:09:45 +02:00
it("should return undefined when fetch groups did not fail", () => {
2018-07-31 13:04:09 +02:00
expect(getFetchGroupsFailure({})).toBe(undefined);
});
2018-07-31 14:22:15 +02:00
2018-07-31 15:09:45 +02:00
it("should return group emptyGroup", () => {
const state = {
groups: {
byNames: {
emptyGroup: emptyGroup
}
}
};
expect(getGroupByName(state, "emptyGroup")).toEqual(emptyGroup);
});
2018-07-31 16:48:28 +02:00
it("should return true, when fetch group humanGroup is pending", () => {
2018-07-31 15:09:45 +02:00
const state = {
pending: {
2018-07-31 16:48:28 +02:00
[FETCH_GROUP + "/humanGroup"]: true
2018-07-31 15:09:45 +02:00
}
};
2018-07-31 16:48:28 +02:00
expect(isFetchGroupPending(state, "humanGroup")).toEqual(true);
2018-07-31 15:09:45 +02:00
});
2018-07-31 16:48:28 +02:00
it("should return false, when fetch group humanGroup is not pending", () => {
expect(isFetchGroupPending({}, "humanGroup")).toEqual(false);
2018-07-31 15:09:45 +02:00
});
2018-07-31 16:48:28 +02:00
it("should return error when fetch group humanGroup did fail", () => {
2018-07-31 15:09:45 +02:00
const state = {
failure: {
2018-07-31 16:48:28 +02:00
[FETCH_GROUP + "/humanGroup"]: error
2018-07-31 15:09:45 +02:00
}
};
2018-07-31 16:48:28 +02:00
expect(getFetchGroupFailure(state, "humanGroup")).toEqual(error);
2018-07-31 15:09:45 +02:00
});
2018-07-31 16:48:28 +02:00
it("should return undefined when fetch group humanGroup did not fail", () => {
expect(getFetchGroupFailure({}, "humanGroup")).toBe(undefined);
2018-07-31 15:09:45 +02:00
});
2018-07-31 14:22:15 +02:00
it("should return true if create group is pending", () => {
2018-10-09 16:17:25 +02:00
expect(
isCreateGroupPending({
pending: {
[CREATE_GROUP]: true
}
})
).toBeTruthy();
2018-08-31 10:47:42 +02:00
});
2018-07-31 14:22:15 +02:00
it("should return false if create group is not pending", () => {
expect(isCreateGroupPending({})).toBe(false);
2018-08-31 10:47:42 +02:00
});
2018-07-31 14:22:15 +02:00
it("should return error if creating group failed", () => {
2018-10-09 16:17:25 +02:00
expect(
getCreateGroupFailure({
failure: {
[CREATE_GROUP]: error
}
})
).toEqual(error);
2018-08-31 10:47:42 +02:00
});
2018-07-31 14:22:15 +02:00
it("should return undefined if creating group did not fail", () => {
2018-08-31 10:47:42 +02:00
expect(getCreateGroupFailure({})).toBeUndefined();
});
2018-07-31 15:09:45 +02:00
2018-07-31 16:48:28 +02:00
it("should return true, when delete group humanGroup is pending", () => {
const state = {
pending: {
[DELETE_GROUP + "/humanGroup"]: true
}
};
expect(isDeleteGroupPending(state, "humanGroup")).toEqual(true);
});
it("should return false, when delete group humanGroup is not pending", () => {
expect(isDeleteGroupPending({}, "humanGroup")).toEqual(false);
});
it("should return error when delete group humanGroup did fail", () => {
const state = {
failure: {
[DELETE_GROUP + "/humanGroup"]: error
}
};
expect(getDeleteGroupFailure(state, "humanGroup")).toEqual(error);
});
it("should return undefined when delete group humanGroup did not fail", () => {
expect(getDeleteGroupFailure({}, "humanGroup")).toBe(undefined);
});
2018-08-02 08:36:12 +02:00
it("should return true, if createGroup is pending", () => {
const state = {
pending: {
[CREATE_GROUP]: true
}
2018-08-31 10:47:42 +02:00
};
2018-08-02 08:36:12 +02:00
expect(isCreateGroupPending(state)).toBe(true);
2018-08-31 10:47:42 +02:00
});
2018-08-02 08:36:12 +02:00
it("should return false, if createGroup is not pending", () => {
2018-08-31 10:47:42 +02:00
expect(isCreateGroupPending({})).toBe(false);
});
2018-08-02 08:36:12 +02:00
it("should return error of createGroup failed", () => {
const state = {
failure: {
[CREATE_GROUP]: error
}
2018-08-31 10:47:42 +02:00
};
expect(getCreateGroupFailure(state)).toEqual(error);
});
2018-07-31 13:04:09 +02:00
});