|
|
|
|
|
|
|
|
import { |
|
|
import { |
|
|
getProcesses, |
|
|
getProcesses, |
|
|
getFilteredProcesses, |
|
|
getFilteredProcesses, |
|
|
|
|
|
finishProcess, |
|
|
|
|
|
changeStatus, |
|
|
|
|
|
changeInterviewer, |
|
|
} from "../../store/saga/processSaga"; |
|
|
} from "../../store/saga/processSaga"; |
|
|
import { |
|
|
import { |
|
|
setProcesses, |
|
|
setProcesses, |
|
|
setProcessesError, |
|
|
setProcessesError, |
|
|
} from "../../store/actions/processes/processesAction"; |
|
|
} from "../../store/actions/processes/processesAction"; |
|
|
import { SelectionProvider } from "../../context/SelectionContext"; |
|
|
import { SelectionProvider } from "../../context/SelectionContext"; |
|
|
|
|
|
import { |
|
|
|
|
|
setDoneProcess, |
|
|
|
|
|
setDoneProcessError, |
|
|
|
|
|
setUpdateInterviewerErr, |
|
|
|
|
|
setUpdateInterviewerSucc, |
|
|
|
|
|
setUpdateStatusErr, |
|
|
|
|
|
setUpdateStatusSucc, |
|
|
|
|
|
} from "../../store/actions/processes/processAction"; |
|
|
|
|
|
|
|
|
describe("SelectionProcessPage render tests", () => { |
|
|
describe("SelectionProcessPage render tests", () => { |
|
|
const cont = ( |
|
|
const cont = ( |
|
|
|
|
|
|
|
|
expect(api.getAllFilteredProcessesReq.mock.calls.length).toBe(1); |
|
|
expect(api.getAllFilteredProcessesReq.mock.calls.length).toBe(1); |
|
|
expect(dispatchedActions).toContainEqual(setProcesses(filteredData)); |
|
|
expect(dispatchedActions).toContainEqual(setProcesses(filteredData)); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it("should handle process to set it done in case of finish success", async () => { |
|
|
|
|
|
const dispatchedActions = []; |
|
|
|
|
|
const mockedCall = { data: { isSuccess: true } }; |
|
|
|
|
|
api.doneProcess = jest.fn(() => Promise.resolve(mockedCall)); |
|
|
|
|
|
|
|
|
|
|
|
const fakeStore = { |
|
|
|
|
|
getState: () => mockState.selections.processes, |
|
|
|
|
|
dispatch: (action) => dispatchedActions.push(action), |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// wait for saga to complete |
|
|
|
|
|
await runSaga(fakeStore, finishProcess, { |
|
|
|
|
|
payload: { |
|
|
|
|
|
id: 1, |
|
|
|
|
|
name: "Some random name", |
|
|
|
|
|
applicantId: 5, |
|
|
|
|
|
schedulerId: 10, |
|
|
|
|
|
}, |
|
|
|
|
|
}).done; |
|
|
|
|
|
|
|
|
|
|
|
expect(api.doneProcess.mock.calls.length).toBe(1); |
|
|
|
|
|
expect(dispatchedActions).toContainEqual(setDoneProcess(mockedCall.data)); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it("should handle error in case of finish process exception", async () => { |
|
|
|
|
|
const dispatchedActions = []; |
|
|
|
|
|
|
|
|
|
|
|
const error = { |
|
|
|
|
|
response: { |
|
|
|
|
|
data: { message: mockState.selections.fetchSelectionsErrorMessage }, |
|
|
|
|
|
}, |
|
|
|
|
|
}; |
|
|
|
|
|
api.doneProcess = jest.fn(() => Promise.reject(error)); |
|
|
|
|
|
|
|
|
|
|
|
const fakeStore = { |
|
|
|
|
|
getState: () => mockState.selections.processes, |
|
|
|
|
|
dispatch: (action) => dispatchedActions.push(action), |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// wait for saga to complete |
|
|
|
|
|
await runSaga(fakeStore, finishProcess, { |
|
|
|
|
|
payload: { |
|
|
|
|
|
id: 1, |
|
|
|
|
|
name: "Some random name", |
|
|
|
|
|
applicantId: 5, |
|
|
|
|
|
schedulerId: 10, |
|
|
|
|
|
}, |
|
|
|
|
|
}).done; |
|
|
|
|
|
|
|
|
|
|
|
expect(api.doneProcess.mock.calls.length).toBe(1); |
|
|
|
|
|
expect(dispatchedActions).toContainEqual( |
|
|
|
|
|
setDoneProcessError(error.response.data.message) |
|
|
|
|
|
); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it("should handle process status update", async () => { |
|
|
|
|
|
const dispatchedActions = []; |
|
|
|
|
|
const mockedCall = { data: { isSuccess: true } }; |
|
|
|
|
|
api.updateStatus = jest.fn(() => Promise.resolve(mockedCall)); |
|
|
|
|
|
|
|
|
|
|
|
const fakeStore = { |
|
|
|
|
|
getState: () => mockState.selections.processes, |
|
|
|
|
|
dispatch: (action) => dispatchedActions.push(action), |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// wait for saga to complete |
|
|
|
|
|
await runSaga(fakeStore, changeStatus, { |
|
|
|
|
|
payload: { |
|
|
|
|
|
data: { |
|
|
|
|
|
schedulerId: 3, |
|
|
|
|
|
appointment: "22-10-2023", |
|
|
|
|
|
newStatus: "Odrađen", |
|
|
|
|
|
processId: 1, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
}).done; |
|
|
|
|
|
|
|
|
|
|
|
expect(api.updateStatus.mock.calls.length).toBe(1); |
|
|
|
|
|
expect(dispatchedActions).toContainEqual(setUpdateStatusSucc()); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it("should call responsehandler while handling process status update", async () => { |
|
|
|
|
|
const dispatchedActions = []; |
|
|
|
|
|
const mockedCall = { data: { isSuccess: true } }; |
|
|
|
|
|
api.updateStatus = jest.fn(() => Promise.resolve(mockedCall)); |
|
|
|
|
|
|
|
|
|
|
|
const mockfn = jest.fn(); |
|
|
|
|
|
|
|
|
|
|
|
const fakeStore = { |
|
|
|
|
|
getState: () => mockState.selections.processes, |
|
|
|
|
|
dispatch: (action) => dispatchedActions.push(action), |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// wait for saga to complete |
|
|
|
|
|
await runSaga(fakeStore, changeStatus, { |
|
|
|
|
|
payload: { |
|
|
|
|
|
data: { |
|
|
|
|
|
schedulerId: 3, |
|
|
|
|
|
appointment: "22-10-2023", |
|
|
|
|
|
newStatus: "Odrađen", |
|
|
|
|
|
processId: 1, |
|
|
|
|
|
}, |
|
|
|
|
|
responseHandler: mockfn, |
|
|
|
|
|
}, |
|
|
|
|
|
}).done; |
|
|
|
|
|
|
|
|
|
|
|
expect(mockfn).toHaveBeenCalled(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it("should handle process status update error if exception is thrown", async () => { |
|
|
|
|
|
const dispatchedActions = []; |
|
|
|
|
|
|
|
|
|
|
|
const error = { |
|
|
|
|
|
response: { |
|
|
|
|
|
data: { message: mockState.selections.fetchSelectionsErrorMessage }, |
|
|
|
|
|
}, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
api.updateStatus = jest.fn(() => Promise.reject(error)); |
|
|
|
|
|
|
|
|
|
|
|
const fakeStore = { |
|
|
|
|
|
getState: () => mockState.selections.processes, |
|
|
|
|
|
dispatch: (action) => dispatchedActions.push(action), |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// wait for saga to complete |
|
|
|
|
|
await runSaga(fakeStore, changeStatus, { |
|
|
|
|
|
payload: { |
|
|
|
|
|
data: { |
|
|
|
|
|
schedulerId: 3, |
|
|
|
|
|
appointment: "22-10-2023", |
|
|
|
|
|
newStatus: "Odrađen", |
|
|
|
|
|
processId: 1, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
}).done; |
|
|
|
|
|
|
|
|
|
|
|
expect(api.updateStatus.mock.calls.length).toBe(1); |
|
|
|
|
|
expect(dispatchedActions).toContainEqual( |
|
|
|
|
|
setUpdateStatusErr(error.response.data.message) |
|
|
|
|
|
); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it("should not call responseHandler if exception is thrown", async () => { |
|
|
|
|
|
const dispatchedActions = []; |
|
|
|
|
|
const error = { |
|
|
|
|
|
response: { |
|
|
|
|
|
data: { message: mockState.selections.fetchSelectionsErrorMessage }, |
|
|
|
|
|
}, |
|
|
|
|
|
}; |
|
|
|
|
|
api.updateStatus = jest.fn(() => Promise.reject(error)); |
|
|
|
|
|
|
|
|
|
|
|
const mockfn = jest.fn(); |
|
|
|
|
|
|
|
|
|
|
|
const fakeStore = { |
|
|
|
|
|
getState: () => mockState.selections.processes, |
|
|
|
|
|
dispatch: (action) => dispatchedActions.push(action), |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// wait for saga to complete |
|
|
|
|
|
await runSaga(fakeStore, changeStatus, { |
|
|
|
|
|
payload: { |
|
|
|
|
|
data: { |
|
|
|
|
|
schedulerId: 3, |
|
|
|
|
|
appointment: "22-10-2023", |
|
|
|
|
|
newStatus: "Odrađen", |
|
|
|
|
|
processId: 1, |
|
|
|
|
|
}, |
|
|
|
|
|
responseHandler: mockfn, |
|
|
|
|
|
}, |
|
|
|
|
|
}).done; |
|
|
|
|
|
|
|
|
|
|
|
expect(mockfn).not.toHaveBeenCalled(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it("should handle interviewer update", async () => { |
|
|
|
|
|
const dispatchedActions = []; |
|
|
|
|
|
const mockedCall = { data: { isSuccess: true } }; |
|
|
|
|
|
api.updateInterviewer = jest.fn(() => Promise.resolve(mockedCall)); |
|
|
|
|
|
|
|
|
|
|
|
const fakeStore = { |
|
|
|
|
|
getState: () => mockState.selections.processes, |
|
|
|
|
|
dispatch: (action) => dispatchedActions.push(action), |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// wait for saga to complete |
|
|
|
|
|
await runSaga(fakeStore, changeInterviewer, { |
|
|
|
|
|
payload: { |
|
|
|
|
|
data: { |
|
|
|
|
|
schedulerId: 1, |
|
|
|
|
|
processId: 2, |
|
|
|
|
|
}, |
|
|
|
|
|
// responseHandler: apiSuccess, |
|
|
|
|
|
} |
|
|
|
|
|
}).done; |
|
|
|
|
|
|
|
|
|
|
|
expect(api.updateInterviewer.mock.calls.length).toBe(1); |
|
|
|
|
|
expect(dispatchedActions).toContainEqual(setUpdateInterviewerSucc()); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it("should call response handler on change success", async () => { |
|
|
|
|
|
const dispatchedActions = []; |
|
|
|
|
|
const mockedCall = { data: { isSuccess: true } }; |
|
|
|
|
|
api.updateInterviewer = jest.fn(() => Promise.resolve(mockedCall)); |
|
|
|
|
|
|
|
|
|
|
|
const fakeStore = { |
|
|
|
|
|
getState: () => mockState.selections.processes, |
|
|
|
|
|
dispatch: (action) => dispatchedActions.push(action), |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const mockfn = jest.fn() |
|
|
|
|
|
|
|
|
|
|
|
// wait for saga to complete |
|
|
|
|
|
await runSaga(fakeStore, changeInterviewer, { |
|
|
|
|
|
payload: { |
|
|
|
|
|
data: { |
|
|
|
|
|
schedulerId: 1, |
|
|
|
|
|
processId: 2, |
|
|
|
|
|
}, |
|
|
|
|
|
responseHandler: mockfn, |
|
|
|
|
|
} |
|
|
|
|
|
}).done; |
|
|
|
|
|
|
|
|
|
|
|
expect(mockfn).toHaveBeenCalled(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it("should handle interviewer update error if exception is thrown", async () => { |
|
|
|
|
|
const dispatchedActions = []; |
|
|
|
|
|
const error = { |
|
|
|
|
|
response: { |
|
|
|
|
|
data: { message: mockState.selections.fetchSelectionsErrorMessage }, |
|
|
|
|
|
}, |
|
|
|
|
|
}; |
|
|
|
|
|
api.updateInterviewer = jest.fn(() => Promise.reject(error)); |
|
|
|
|
|
|
|
|
|
|
|
const fakeStore = { |
|
|
|
|
|
getState: () => mockState.selections.processes, |
|
|
|
|
|
dispatch: (action) => dispatchedActions.push(action), |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// wait for saga to complete |
|
|
|
|
|
await runSaga(fakeStore, changeInterviewer, { |
|
|
|
|
|
payload: { |
|
|
|
|
|
data: { |
|
|
|
|
|
schedulerId: 1, |
|
|
|
|
|
processId: 2, |
|
|
|
|
|
}, |
|
|
|
|
|
// responseHandler: mockfn, |
|
|
|
|
|
} |
|
|
|
|
|
}).done; |
|
|
|
|
|
|
|
|
|
|
|
expect(api.updateInterviewer.mock.calls.length).toBe(1); |
|
|
|
|
|
expect(dispatchedActions).toContainEqual( |
|
|
|
|
|
setUpdateInterviewerErr(error.response.data.message) |
|
|
|
|
|
); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it("should not call response handler if exception is thrown", async () => { |
|
|
|
|
|
const dispatchedActions = []; |
|
|
|
|
|
const error = { |
|
|
|
|
|
response: { |
|
|
|
|
|
data: { message: mockState.selections.fetchSelectionsErrorMessage }, |
|
|
|
|
|
}, |
|
|
|
|
|
}; |
|
|
|
|
|
api.updateInterviewer = jest.fn(() => Promise.reject(error)); |
|
|
|
|
|
|
|
|
|
|
|
const mockfn = jest.fn() |
|
|
|
|
|
|
|
|
|
|
|
const fakeStore = { |
|
|
|
|
|
getState: () => mockState.selections.processes, |
|
|
|
|
|
dispatch: (action) => dispatchedActions.push(action), |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// wait for saga to complete |
|
|
|
|
|
await runSaga(fakeStore, changeInterviewer, { |
|
|
|
|
|
payload: { |
|
|
|
|
|
data: { |
|
|
|
|
|
schedulerId: 1, |
|
|
|
|
|
processId: 2, |
|
|
|
|
|
}, |
|
|
|
|
|
responseHandler: mockfn, |
|
|
|
|
|
} |
|
|
|
|
|
}).done; |
|
|
|
|
|
|
|
|
|
|
|
expect(mockfn).not.toHaveBeenCalled(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |