|
|
|
@@ -12,7 +12,11 @@ import { setUsersError } from "../../store/actions/users/usersActions"; |
|
|
|
import { getUsers, invite } from "../../store/saga/usersSaga"; |
|
|
|
import InviteDialog from "../../components/MUI/InviteDialog"; |
|
|
|
import * as userReqs from "../../store/actions/users/usersActions"; |
|
|
|
import { inviteUserSuccess } from "../../store/actions/users/usersActions"; |
|
|
|
import { |
|
|
|
inviteUserSuccess, |
|
|
|
inviteUserError, |
|
|
|
} from "../../store/actions/users/usersActions"; |
|
|
|
import * as helper from "../../util/helpers/rejectErrorCodeHelper"; |
|
|
|
|
|
|
|
const props = { |
|
|
|
title: "Any", |
|
|
|
@@ -37,6 +41,7 @@ describe("invite dialog reducer tests onSuccess", () => { |
|
|
|
let spyOnUseSelector; |
|
|
|
let spyOnUseDispatch; |
|
|
|
let mockDispatch; |
|
|
|
let spyHelper; |
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
|
// Mock useSelector hook |
|
|
|
@@ -54,6 +59,9 @@ describe("invite dialog reducer tests onSuccess", () => { |
|
|
|
// Mock dispatch function returned from useDispatch |
|
|
|
mockDispatch = jest.fn(); |
|
|
|
spyOnUseDispatch.mockReturnValueOnce(mockDispatch); |
|
|
|
|
|
|
|
// Mock rejectErrorCodeHelper |
|
|
|
spyHelper = jest.spyOn(helper, "rejectErrorCodeHelper") |
|
|
|
}); |
|
|
|
|
|
|
|
afterEach(() => { |
|
|
|
@@ -157,4 +165,45 @@ describe("invite reducer tests default", () => { |
|
|
|
expect(api.inviteUserRequest.mock.calls.length).toBe(1); |
|
|
|
expect(dispatchedActions).toContainEqual(inviteUserSuccess()); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should run inviteUser saga function with error actions in case of api error", async () => { |
|
|
|
const dispatchedActions = []; |
|
|
|
|
|
|
|
helper.rejectErrorCodeHelper = jest.fn(()=> 'Server error') |
|
|
|
|
|
|
|
// we don't want to perform an actual api call in our tests |
|
|
|
// so we will mock the getAllUsers api with jest |
|
|
|
// this will mutate the dependency which we may reset if other tests |
|
|
|
// are dependent on it |
|
|
|
const mockError = { |
|
|
|
response: { |
|
|
|
data: { message: "Server error" }, |
|
|
|
}, |
|
|
|
}; |
|
|
|
api.inviteUserRequest = jest.fn(() => Promise.reject(mockError)); |
|
|
|
|
|
|
|
const fakeStore = { |
|
|
|
getState: () => ({ |
|
|
|
invite: { |
|
|
|
isSuccess: false, |
|
|
|
errorMessage: "", |
|
|
|
}, |
|
|
|
}), |
|
|
|
dispatch: (action) => dispatchedActions.push(action), |
|
|
|
}; |
|
|
|
|
|
|
|
// wait for saga to complete |
|
|
|
await runSaga(fakeStore, invite, { |
|
|
|
payload: { |
|
|
|
firstName: "st", |
|
|
|
lastName: "Test", |
|
|
|
email: "test@dilig.net", |
|
|
|
}, |
|
|
|
}).done; |
|
|
|
|
|
|
|
expect(api.inviteUserRequest.mock.calls.length).toBe(1); |
|
|
|
expect(dispatchedActions).toContainEqual( |
|
|
|
inviteUserError("Server error") |
|
|
|
); |
|
|
|
}); |
|
|
|
}); |