Added unit tests

This commit is contained in:
Philipp Czora
2018-07-17 16:26:20 +02:00
parent 4ecc4338d6
commit db9e468877
2 changed files with 32 additions and 1 deletions

View File

@@ -11,6 +11,10 @@ import {
FETCH_USERS_SUCCESS,
fetchUsers,
FETCH_USERS_FAILURE,
addUser,
ADD_USER,
ADD_USER_SUCCESS,
ADD_USER_FAILURE,
updateUser,
UPDATE_USER,
UPDATE_USER_FAILURE,
@@ -158,6 +162,33 @@ describe("fetch tests", () => {
});
});
test("successful user add", () => {
fetchMock.postOnce("/scm/api/rest/v2/users", {
status: 204
});
const store = mockStore({});
return store.dispatch(addUser(userZaphod)).then(() => {
const actions = store.getActions();
expect(actions[0].type).toEqual(ADD_USER);
expect(actions[1].type).toEqual(ADD_USER_SUCCESS);
});
});
test("user add failed", () => {
fetchMock.postOnce("/scm/api/rest/v2/users", {
status: 500
});
const store = mockStore({});
return store.dispatch(addUser(userZaphod)).then(() => {
const actions = store.getActions();
expect(actions[0].type).toEqual(ADD_USER);
expect(actions[1].type).toEqual(ADD_USER_FAILURE);
expect(actions[1].payload).toBeDefined();
});
});
test("successful user update", () => {
fetchMock.putOnce("http://localhost:8081/scm/api/rest/v2/users/zaphod", {
status: 204