diff --git a/react-frontend/src/sagas/recognitionSaga.test.js b/react-frontend/src/sagas/recognitionSaga.test.js index 9eb0f6044..722c88074 100644 --- a/react-frontend/src/sagas/recognitionSaga.test.js +++ b/react-frontend/src/sagas/recognitionSaga.test.js @@ -1,9 +1,15 @@ -import { takeEvery, call } from "redux-saga/effects"; +import { takeEvery, call, put } from "redux-saga/effects"; import { recognitionApi, getRecognitionList } from "sagas/recognitionSaga"; import getJson from "utils/getJson"; +import actionGenerator from "utils/actionGenerator"; +import success_mockResponse from "../../../mock-responses/recognitions/get_api_call_success_response.json"; +import failure_mockResponse from "../../../mock-responses/recognitions/get_api_call_failure_response.json"; describe("RECOGNITION SAGAS", () => { + const status = actionGenerator("LIST_RECOGNITION"); + const response = { json: () => "success" }; + it("should dispatch action 'LIST_RECOGNITION_API' for recognition saga", () => { const generator = recognitionApi(); expect(generator.next().value).toEqual( @@ -13,15 +19,42 @@ describe("RECOGNITION SAGAS", () => { expect(status).toEqual(true); }); - it("should dispatch action 'LIST_RECOGNITION_API' for fetch list", () => { + it("should dispatch action 'LIST_RECOGNITION_API' for fetch list with 200 status", () => { const generator = getRecognitionList(); - expect(generator.next().value).toEqual( + const callFunctionDefination = generator.next().value; + + expect(callFunctionDefination).toEqual( + call(getJson, { + path: "recognitions", + apiToken: "", + }) + ); + generator.next(response).value; + expect(generator.next(success_mockResponse).value).toEqual( + put({ + type: status.success, + payload: success_mockResponse.data, + }) + ); + expect(generator.next().done).toEqual(true); + }); + + it("should dispatch action 'LIST_RECOGNITION_API' for fetch list with 401 error response", () => { + const generator = getRecognitionList(); + const callFunctionDefination = generator.next().value; + expect(callFunctionDefination).toEqual( call(getJson, { path: "recognitions", apiToken: "", }) ); - expect(generator.next().done).toEqual(false); + expect(generator.next(response).value).toEqual("success"); + expect(generator.next(failure_mockResponse).value).toEqual( + put({ + type: status.failure, + payload: failure_mockResponse.error, + }) + ); expect(generator.next().done).toEqual(true); }); });