From 4b4be355e09da63a0a22e767480df415d9a9e809 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Tue, 26 May 2020 15:01:30 +0530 Subject: [PATCH 01/35] create reducer for store recognition list --- react-frontend/src/reducers/recognitionReducer.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 react-frontend/src/reducers/recognitionReducer.js diff --git a/react-frontend/src/reducers/recognitionReducer.js b/react-frontend/src/reducers/recognitionReducer.js new file mode 100644 index 000000000..116dd82cd --- /dev/null +++ b/react-frontend/src/reducers/recognitionReducer.js @@ -0,0 +1,12 @@ +const defaultState = [{}]; + +export default (state = defaultState, action) => { + switch (action.type) { + case "GET_RECOGNITION_LIST_SUCCESS": + return action.value; + case "GET_RECOGNITION_LIST_FAILURE": + return action.value; + default: + return state; + } +}; From 1ee0089ea4f3668620e04002cdc71438fc2c812f Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Tue, 26 May 2020 18:53:26 +0530 Subject: [PATCH 02/35] update recognition Reducer --- react-frontend/src/reducers/recognitionReducer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/react-frontend/src/reducers/recognitionReducer.js b/react-frontend/src/reducers/recognitionReducer.js index 116dd82cd..83dc68e0c 100644 --- a/react-frontend/src/reducers/recognitionReducer.js +++ b/react-frontend/src/reducers/recognitionReducer.js @@ -3,9 +3,9 @@ const defaultState = [{}]; export default (state = defaultState, action) => { switch (action.type) { case "GET_RECOGNITION_LIST_SUCCESS": - return action.value; + return action.payload; case "GET_RECOGNITION_LIST_FAILURE": - return action.value; + return action.payload; default: return state; } From 5464f6e1a76f0dee6c81e192100771f677ca51f6 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Tue, 26 May 2020 19:01:40 +0530 Subject: [PATCH 03/35] add recognitionReducer in root combineReducers --- react-frontend/src/reducers/rootReducer.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/react-frontend/src/reducers/rootReducer.js b/react-frontend/src/reducers/rootReducer.js index 007b7e21d..1281ca4da 100644 --- a/react-frontend/src/reducers/rootReducer.js +++ b/react-frontend/src/reducers/rootReducer.js @@ -1,7 +1,9 @@ import { combineReducers } from "redux"; import appReducer from "reducers/appReducer.js"; +import recognitionReducer from "reducers/recognitionReducer"; export default combineReducers({ appReducer, + recognitionReducer, }); From 709c5df6f18213ae0b6a53774d0da9ff78c7860a Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Tue, 26 May 2020 19:04:04 +0530 Subject: [PATCH 04/35] create recognitionSaga file for run sagaMiddleware for Api call --- react-frontend/src/sagas/recognitionSaga.js | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 react-frontend/src/sagas/recognitionSaga.js diff --git a/react-frontend/src/sagas/recognitionSaga.js b/react-frontend/src/sagas/recognitionSaga.js new file mode 100644 index 000000000..4249c5a4c --- /dev/null +++ b/react-frontend/src/sagas/recognitionSaga.js @@ -0,0 +1,35 @@ +import { put, takeEvery, spawn, call } from "redux-saga/effects"; +import GetJson from "utils/getJson"; + +export function* getRecognitionList(action) { + try { + const response = yield call(GetJson, { + path: "recognitions", + apiToken: + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJub2RlLnBlZXJseS5jb20iLCJzdWIiOjE4LCJhdWQiOiJwZWVybHkuY29tIiwibmJmIjoxNTkwNDY1MDM0LCJodHRwczovL3BlZXJseS5jb20iOnsicm9sZUlkIjozLCJvcmdJZCI6Mywib3JnTmFtZSI6Impvc2gifSwiaWF0IjoxNTkwNDY1MDM0LCJleHAiOjE1OTA1MDEwMzR9.on9odD7zsg4sjoEX_iEhY5A9u5oaqJANIN5B4_pJAHM", + paramsObj: action.payload, + }); + const responseObj = yield response.json(); + if (responseObj.data) { + yield put({ + type: "GET_RECOGNITION_LIST_SUCCESS", + payload: responseObj.data, + }); + } else { + yield put({ + type: "GET_RECOGNITION_LIST_FAILURE", + payload: responseObj.error, + }); + } + } catch (error) { + yield put({ type: "GET_RECOGNITION_LIST_FAILURE", payload: error }); + } +} + +export function* recognitionApi() { + yield takeEvery("RECOGNITION_GET_API", getRecognitionList); +} + +export default function* rootSaga() { + yield spawn(recognitionApi); +} From 8bc9d70771415e7182ec13202df60e11c4f831cc Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Tue, 26 May 2020 19:08:28 +0530 Subject: [PATCH 05/35] add code in redux-store for run recognitionSaga at sagaMiddleware --- react-frontend/src/root/redux-store.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/react-frontend/src/root/redux-store.js b/react-frontend/src/root/redux-store.js index 7c7fb1fec..e534c8869 100644 --- a/react-frontend/src/root/redux-store.js +++ b/react-frontend/src/root/redux-store.js @@ -4,6 +4,7 @@ import createSagaMiddleware from "redux-saga"; import rootReducer from "reducers/rootReducer.js"; import rootSaga from "sagas/rootSaga.js"; +import recognitionSaga from "sagas/recognitionSaga"; // create the saga middleware export const sagaMiddleware = createSagaMiddleware(); @@ -19,3 +20,4 @@ export const store = configureStore(); // run the root saga sagaMiddleware.run(rootSaga); +sagaMiddleware.run(recognitionSaga); From b23825fe0f351ce49a81a4e8e7c8eab07cb87057 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Tue, 26 May 2020 19:10:10 +0530 Subject: [PATCH 06/35] add RecognitionListContainer and add store.dispatch code for saga Api call --- .../RecognitionListContainer.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 react-frontend/src/recognition-list/RecognitionListContainer.js diff --git a/react-frontend/src/recognition-list/RecognitionListContainer.js b/react-frontend/src/recognition-list/RecognitionListContainer.js new file mode 100644 index 000000000..a83a6f36f --- /dev/null +++ b/react-frontend/src/recognition-list/RecognitionListContainer.js @@ -0,0 +1,26 @@ +import React, { useEffect, useState } from "react"; +import { useSelector } from "react-redux"; + +import { store } from "root/redux-store"; + +const RecognnitionListContainer = () => { + const recognitionList = useSelector((state) => state.recognitionReducer); + const [ListStatus, setListStatus] = useState(false); + + useEffect(() => { + if (!ListStatus) { + store.dispatch({ type: "RECOGNITION_GET_API", payload: {} }); + setListStatus(true); + } + }, [ListStatus]); + + return ( +
+ {recognitionList.map((el, key) => ( +

{el.id}

+ ))} +
+ ); +}; + +export default RecognnitionListContainer; From 41e4847fcf510be1cfcb65d4b4f6641c6837c789 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Wed, 27 May 2020 13:49:34 +0530 Subject: [PATCH 07/35] change the position to use of recognitionSaga middleware --- react-frontend/src/root/redux-store.js | 2 -- react-frontend/src/sagas/recognitionSaga.js | 8 ++++---- react-frontend/src/sagas/rootSaga.js | 2 ++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/react-frontend/src/root/redux-store.js b/react-frontend/src/root/redux-store.js index e534c8869..7c7fb1fec 100644 --- a/react-frontend/src/root/redux-store.js +++ b/react-frontend/src/root/redux-store.js @@ -4,7 +4,6 @@ import createSagaMiddleware from "redux-saga"; import rootReducer from "reducers/rootReducer.js"; import rootSaga from "sagas/rootSaga.js"; -import recognitionSaga from "sagas/recognitionSaga"; // create the saga middleware export const sagaMiddleware = createSagaMiddleware(); @@ -20,4 +19,3 @@ export const store = configureStore(); // run the root saga sagaMiddleware.run(rootSaga); -sagaMiddleware.run(recognitionSaga); diff --git a/react-frontend/src/sagas/recognitionSaga.js b/react-frontend/src/sagas/recognitionSaga.js index 4249c5a4c..df9f54b89 100644 --- a/react-frontend/src/sagas/recognitionSaga.js +++ b/react-frontend/src/sagas/recognitionSaga.js @@ -6,7 +6,7 @@ export function* getRecognitionList(action) { const response = yield call(GetJson, { path: "recognitions", apiToken: - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJub2RlLnBlZXJseS5jb20iLCJzdWIiOjE4LCJhdWQiOiJwZWVybHkuY29tIiwibmJmIjoxNTkwNDY1MDM0LCJodHRwczovL3BlZXJseS5jb20iOnsicm9sZUlkIjozLCJvcmdJZCI6Mywib3JnTmFtZSI6Impvc2gifSwiaWF0IjoxNTkwNDY1MDM0LCJleHAiOjE1OTA1MDEwMzR9.on9odD7zsg4sjoEX_iEhY5A9u5oaqJANIN5B4_pJAHM", + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJub2RlLnBlZXJseS5jb20iLCJzdWIiOjE5LCJhdWQiOiJwZWVybHkuY29tIiwibmJmIjoxNTkwNTQ3MzA1LCJodHRwczovL3BlZXJseS5jb20iOnsicm9sZUlkIjozLCJvcmdJZCI6Mywib3JnTmFtZSI6Impvc2gifSwiaWF0IjoxNTkwNTQ3MzA1LCJleHAiOjE1OTA1ODMzMDV9.5zNi8j6IZHa0Y1lGBFjeyaNvUrh82Gf0kmOAZQHvuXg", paramsObj: action.payload, }); const responseObj = yield response.json(); @@ -18,11 +18,11 @@ export function* getRecognitionList(action) { } else { yield put({ type: "GET_RECOGNITION_LIST_FAILURE", - payload: responseObj.error, + payload: [responseObj.error], }); } } catch (error) { - yield put({ type: "GET_RECOGNITION_LIST_FAILURE", payload: error }); + yield put({ type: "GET_RECOGNITION_LIST_FAILURE", payload: [error] }); } } @@ -30,6 +30,6 @@ export function* recognitionApi() { yield takeEvery("RECOGNITION_GET_API", getRecognitionList); } -export default function* rootSaga() { +export default function* rootRecognitionSaga() { yield spawn(recognitionApi); } diff --git a/react-frontend/src/sagas/rootSaga.js b/react-frontend/src/sagas/rootSaga.js index c56c1033b..ec894aa92 100644 --- a/react-frontend/src/sagas/rootSaga.js +++ b/react-frontend/src/sagas/rootSaga.js @@ -1,4 +1,5 @@ import { spawn } from "redux-saga/effects"; +import recognitionSaga from "sagas/recognitionSaga"; export function* helloSaga() { const msg = yield "Hello Sagas!"; @@ -8,4 +9,5 @@ export function* helloSaga() { export default function* rootSaga() { yield spawn(helloSaga); + yield spawn(recognitionSaga); } From e86e4d1e31220199321d79b282fc2c5ba1c1139f Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Wed, 27 May 2020 13:57:44 +0530 Subject: [PATCH 08/35] add some error related rendering code --- .../RecognitionListContainer.js | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/react-frontend/src/recognition-list/RecognitionListContainer.js b/react-frontend/src/recognition-list/RecognitionListContainer.js index a83a6f36f..52c2b55d4 100644 --- a/react-frontend/src/recognition-list/RecognitionListContainer.js +++ b/react-frontend/src/recognition-list/RecognitionListContainer.js @@ -1,23 +1,24 @@ -import React, { useEffect, useState } from "react"; -import { useSelector } from "react-redux"; - -import { store } from "root/redux-store"; +import React, { useEffect } from "react"; +import { useSelector, useDispatch } from "react-redux"; const RecognnitionListContainer = () => { const recognitionList = useSelector((state) => state.recognitionReducer); - const [ListStatus, setListStatus] = useState(false); + const dispatch = useDispatch(); useEffect(() => { - if (!ListStatus) { - store.dispatch({ type: "RECOGNITION_GET_API", payload: {} }); - setListStatus(true); - } - }, [ListStatus]); + dispatch({ type: "RECOGNITION_GET_API" }); + }, [dispatch]); + + if (recognitionList[0].code == "invalid_token") { + return

unauthorised user

; + } else if (recognitionList[0].code == "access_denied") { + return

Permission required

; + } return (
{recognitionList.map((el, key) => ( -

{el.id}

+

{el.text}

))}
); From 3cf2b24ac11e68b5214abcdb2d6de931b549e179 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Wed, 27 May 2020 16:37:30 +0530 Subject: [PATCH 09/35] restructure default state of recognition reducer --- react-frontend/src/reducers/recognitionReducer.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/react-frontend/src/reducers/recognitionReducer.js b/react-frontend/src/reducers/recognitionReducer.js index 83dc68e0c..41d812b98 100644 --- a/react-frontend/src/reducers/recognitionReducer.js +++ b/react-frontend/src/reducers/recognitionReducer.js @@ -1,11 +1,14 @@ -const defaultState = [{}]; +const defaultState = { + list: [{}], + error: {}, +}; export default (state = defaultState, action) => { switch (action.type) { case "GET_RECOGNITION_LIST_SUCCESS": - return action.payload; + return { ...state, list: action.payload }; case "GET_RECOGNITION_LIST_FAILURE": - return action.payload; + return { ...state, error: action.payload }; default: return state; } From ede91cda9c0b3a5fbb8790c438d072320eac69fb Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Wed, 27 May 2020 16:39:01 +0530 Subject: [PATCH 10/35] adjust code as per default state of recognition reducer --- react-frontend/src/sagas/recognitionSaga.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/react-frontend/src/sagas/recognitionSaga.js b/react-frontend/src/sagas/recognitionSaga.js index df9f54b89..fb3156ce7 100644 --- a/react-frontend/src/sagas/recognitionSaga.js +++ b/react-frontend/src/sagas/recognitionSaga.js @@ -1,9 +1,9 @@ import { put, takeEvery, spawn, call } from "redux-saga/effects"; -import GetJson from "utils/getJson"; +import getJson from "utils/getJson"; export function* getRecognitionList(action) { try { - const response = yield call(GetJson, { + const response = yield call(getJson, { path: "recognitions", apiToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJub2RlLnBlZXJseS5jb20iLCJzdWIiOjE5LCJhdWQiOiJwZWVybHkuY29tIiwibmJmIjoxNTkwNTQ3MzA1LCJodHRwczovL3BlZXJseS5jb20iOnsicm9sZUlkIjozLCJvcmdJZCI6Mywib3JnTmFtZSI6Impvc2gifSwiaWF0IjoxNTkwNTQ3MzA1LCJleHAiOjE1OTA1ODMzMDV9.5zNi8j6IZHa0Y1lGBFjeyaNvUrh82Gf0kmOAZQHvuXg", @@ -18,11 +18,11 @@ export function* getRecognitionList(action) { } else { yield put({ type: "GET_RECOGNITION_LIST_FAILURE", - payload: [responseObj.error], + payload: responseObj.error, }); } } catch (error) { - yield put({ type: "GET_RECOGNITION_LIST_FAILURE", payload: [error] }); + yield put({ type: "GET_RECOGNITION_LIST_FAILURE", payload: error }); } } From da8418638b4e15b7025156a0f2fe90cca911918c Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Wed, 27 May 2020 16:40:58 +0530 Subject: [PATCH 11/35] add SessionTimeoutComponent and UnauthorisedErrorComponent for rendering on error --- .../recognition-list/RecognitionListContainer.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/react-frontend/src/recognition-list/RecognitionListContainer.js b/react-frontend/src/recognition-list/RecognitionListContainer.js index 52c2b55d4..b7ab37e09 100644 --- a/react-frontend/src/recognition-list/RecognitionListContainer.js +++ b/react-frontend/src/recognition-list/RecognitionListContainer.js @@ -1,6 +1,9 @@ import React, { useEffect } from "react"; import { useSelector, useDispatch } from "react-redux"; +import SessionTimeoutComponent from "shared-components/SessionTimeoutComponent"; +import UnauthorisedErrorComponent from "shared-components/UnauthorisedErrorComponent"; + const RecognnitionListContainer = () => { const recognitionList = useSelector((state) => state.recognitionReducer); const dispatch = useDispatch(); @@ -9,15 +12,15 @@ const RecognnitionListContainer = () => { dispatch({ type: "RECOGNITION_GET_API" }); }, [dispatch]); - if (recognitionList[0].code == "invalid_token") { - return

unauthorised user

; - } else if (recognitionList[0].code == "access_denied") { - return

Permission required

; + if (recognitionList.error.code === "invalid_token") { + return ; + } else if (recognitionList.error.code === "access_denied") { + return ; } return (
- {recognitionList.map((el, key) => ( + {recognitionList.list.map((el, key) => (

{el.text}

))}
From 6910d53c731d4ccc4f9d9f13349d44f4b0aa90eb Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Wed, 27 May 2020 19:03:42 +0530 Subject: [PATCH 12/35] add test case file for recognitionReducer --- .../src/reducers/recognitionReducer.test.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 react-frontend/src/reducers/recognitionReducer.test.js diff --git a/react-frontend/src/reducers/recognitionReducer.test.js b/react-frontend/src/reducers/recognitionReducer.test.js new file mode 100644 index 000000000..50bded548 --- /dev/null +++ b/react-frontend/src/reducers/recognitionReducer.test.js @@ -0,0 +1,21 @@ +import reducer from "reducers/recognitionReducer"; + +describe("recognition reducer", () => { + it("recognition reducer should return the initial state", () => { + expect(reducer(undefined, {})).toEqual({ + list: [{}], + error: {}, + }); + }); + + it("recognition reducer should handle 'GET_RECOGNITION_LIST_SUCCESS' action", () => { + let reducerData = reducer(undefined, { + type: "GET_RECOGNITION_LIST_SUCCESS", + payload: [{ id: 1 }], + }); + expect(reducerData).toEqual({ + list: [{ id: 1 }], + error: {}, + }); + }); +}); From 1a840dbae38c84933776f241eef96307a6987404 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Wed, 27 May 2020 19:12:20 +0530 Subject: [PATCH 13/35] add one test case in recognitionReducer.test.js file action at failure --- .../src/reducers/recognitionReducer.test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/react-frontend/src/reducers/recognitionReducer.test.js b/react-frontend/src/reducers/recognitionReducer.test.js index 50bded548..f5489238b 100644 --- a/react-frontend/src/reducers/recognitionReducer.test.js +++ b/react-frontend/src/reducers/recognitionReducer.test.js @@ -18,4 +18,15 @@ describe("recognition reducer", () => { error: {}, }); }); + + it("recognition reducer should handle 'GET_RECOGNITION_LIST_FAILURE' action", () => { + let reducerData = reducer(undefined, { + type: "GET_RECOGNITION_LIST_FAILURE", + payload: { code: "invalid token" }, + }); + expect(reducerData).toEqual({ + list: [{}], + error: { code: "invalid token" }, + }); + }); }); From 2e30634146215662637e03c01569d280311b2ec7 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Thu, 28 May 2020 11:29:36 +0530 Subject: [PATCH 14/35] add test case file for recognitionSaga middleware --- .../src/sagas/recognitionSaga.test.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 react-frontend/src/sagas/recognitionSaga.test.js diff --git a/react-frontend/src/sagas/recognitionSaga.test.js b/react-frontend/src/sagas/recognitionSaga.test.js new file mode 100644 index 000000000..9964ff133 --- /dev/null +++ b/react-frontend/src/sagas/recognitionSaga.test.js @@ -0,0 +1,27 @@ +import { takeEvery, call } from "redux-saga/effects"; + +import { recognitionApi, getRecognitionList } from "sagas/recognitionSaga"; +import getJson from "utils/getJson"; + +describe("RECOGNITION SAGAS", () => { + it("should dispatch action 'RECOGNITION_GET_API' for recognition saga", () => { + const generator = recognitionApi(); + expect(generator.next().value).toEqual( + takeEvery("RECOGNITION_GET_API", getRecognitionList) + ); + const status = generator.next().done; + expect(status).toBeTruthy(); + }); + + it("should dispatch action 'RECOGNITION_GET_API' with result from fetch get list API", () => { + const generator = getRecognitionList(); + + expect(generator.next().value).toEqual( + call(getJson, { + path: "recognitions", + apiToken: + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJub2RlLnBlZXJseS5jb20iLCJzdWIiOjE5LCJhdWQiOiJwZWVybHkuY29tIiwibmJmIjoxNTkwNjM2NDUyLCJodHRwczovL3BlZXJseS5jb20iOnsicm9sZUlkIjozLCJvcmdJZCI6Mywib3JnTmFtZSI6Impvc2gifSwiaWF0IjoxNTkwNjM2NDUyLCJleHAiOjE1OTA2NzI0NTJ9.MKkukGmgx9RHyFm_dfrGp8j_W09fBU8Qy9EzPXXcv3w", + }) + ); + }); +}); From b4cc2c0434fb6dd16cd15cf90f555ca0d06bf67f Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Thu, 28 May 2020 11:46:35 +0530 Subject: [PATCH 15/35] rename and recogntionReducer file name and use actionGenerator utils function on it --- .../{recognitionReducer.js => listRecognitionReducer.js} | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) rename react-frontend/src/reducers/{recognitionReducer.js => listRecognitionReducer.js} (63%) diff --git a/react-frontend/src/reducers/recognitionReducer.js b/react-frontend/src/reducers/listRecognitionReducer.js similarity index 63% rename from react-frontend/src/reducers/recognitionReducer.js rename to react-frontend/src/reducers/listRecognitionReducer.js index 41d812b98..d4090c1a0 100644 --- a/react-frontend/src/reducers/recognitionReducer.js +++ b/react-frontend/src/reducers/listRecognitionReducer.js @@ -1,13 +1,16 @@ +import actionGenerator from "utils/actionGenerator"; + const defaultState = { list: [{}], error: {}, }; +const status = actionGenerator("LIST_RECOGNITION"); export default (state = defaultState, action) => { switch (action.type) { - case "GET_RECOGNITION_LIST_SUCCESS": + case status.success: return { ...state, list: action.payload }; - case "GET_RECOGNITION_LIST_FAILURE": + case status.failure: return { ...state, error: action.payload }; default: return state; From a8b1c220585a3f3e146987936c5ae3327920f73e Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Thu, 28 May 2020 12:40:39 +0530 Subject: [PATCH 16/35] update test case of listRecognition reducer and use actionGenerator util function for get action types obj --- .../src/reducers/listRecognitionReducer.js | 2 +- ...cer.test.js => listRecognitionReducer.test.js} | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) rename react-frontend/src/reducers/{recognitionReducer.test.js => listRecognitionReducer.test.js} (62%) diff --git a/react-frontend/src/reducers/listRecognitionReducer.js b/react-frontend/src/reducers/listRecognitionReducer.js index d4090c1a0..243623184 100644 --- a/react-frontend/src/reducers/listRecognitionReducer.js +++ b/react-frontend/src/reducers/listRecognitionReducer.js @@ -1,6 +1,6 @@ import actionGenerator from "utils/actionGenerator"; -const defaultState = { +export const defaultState = { list: [{}], error: {}, }; diff --git a/react-frontend/src/reducers/recognitionReducer.test.js b/react-frontend/src/reducers/listRecognitionReducer.test.js similarity index 62% rename from react-frontend/src/reducers/recognitionReducer.test.js rename to react-frontend/src/reducers/listRecognitionReducer.test.js index f5489238b..4f0726894 100644 --- a/react-frontend/src/reducers/recognitionReducer.test.js +++ b/react-frontend/src/reducers/listRecognitionReducer.test.js @@ -1,16 +1,19 @@ -import reducer from "reducers/recognitionReducer"; +import reducer, { defaultState } from "reducers/listRecognitionReducer"; +import actionGenerator from "utils/actionGenerator"; describe("recognition reducer", () => { + const status = actionGenerator("LIST_RECOGNITION"); + it("recognition reducer should return the initial state", () => { - expect(reducer(undefined, {})).toEqual({ + expect(reducer(defaultState, {})).toEqual({ list: [{}], error: {}, }); }); it("recognition reducer should handle 'GET_RECOGNITION_LIST_SUCCESS' action", () => { - let reducerData = reducer(undefined, { - type: "GET_RECOGNITION_LIST_SUCCESS", + let reducerData = reducer(defaultState, { + type: status.success, payload: [{ id: 1 }], }); expect(reducerData).toEqual({ @@ -20,8 +23,8 @@ describe("recognition reducer", () => { }); it("recognition reducer should handle 'GET_RECOGNITION_LIST_FAILURE' action", () => { - let reducerData = reducer(undefined, { - type: "GET_RECOGNITION_LIST_FAILURE", + let reducerData = reducer(defaultState, { + type: status.failure, payload: { code: "invalid token" }, }); expect(reducerData).toEqual({ From 1db20123761cf5d119f559ad441271191cb320a4 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Thu, 28 May 2020 15:48:26 +0530 Subject: [PATCH 17/35] change the name of recognitionReducer to listRecognitionReducer in rootReducer.js file --- react-frontend/src/reducers/rootReducer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/react-frontend/src/reducers/rootReducer.js b/react-frontend/src/reducers/rootReducer.js index 1281ca4da..fad9cda06 100644 --- a/react-frontend/src/reducers/rootReducer.js +++ b/react-frontend/src/reducers/rootReducer.js @@ -1,9 +1,9 @@ import { combineReducers } from "redux"; import appReducer from "reducers/appReducer.js"; -import recognitionReducer from "reducers/recognitionReducer"; +import listRecognitionReducer from "reducers/listRecognitionReducer"; export default combineReducers({ appReducer, - recognitionReducer, + listRecognitionReducer, }); From 8138af0ac4570347f6509a53c7f30074c2fb88bf Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Thu, 28 May 2020 15:53:18 +0530 Subject: [PATCH 18/35] update recognitionSaga by use utils actionGenerator function --- react-frontend/src/sagas/recognitionSaga.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/react-frontend/src/sagas/recognitionSaga.js b/react-frontend/src/sagas/recognitionSaga.js index fb3156ce7..faf122ff1 100644 --- a/react-frontend/src/sagas/recognitionSaga.js +++ b/react-frontend/src/sagas/recognitionSaga.js @@ -1,33 +1,34 @@ import { put, takeEvery, spawn, call } from "redux-saga/effects"; import getJson from "utils/getJson"; -export function* getRecognitionList(action) { +import actionGenerator from "utils/actionGenerator"; + +export function* getRecognitionList() { + const status = actionGenerator("LIST_RECOGNITION"); try { const response = yield call(getJson, { path: "recognitions", - apiToken: - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJub2RlLnBlZXJseS5jb20iLCJzdWIiOjE5LCJhdWQiOiJwZWVybHkuY29tIiwibmJmIjoxNTkwNTQ3MzA1LCJodHRwczovL3BlZXJseS5jb20iOnsicm9sZUlkIjozLCJvcmdJZCI6Mywib3JnTmFtZSI6Impvc2gifSwiaWF0IjoxNTkwNTQ3MzA1LCJleHAiOjE1OTA1ODMzMDV9.5zNi8j6IZHa0Y1lGBFjeyaNvUrh82Gf0kmOAZQHvuXg", - paramsObj: action.payload, + apiToken: "", }); const responseObj = yield response.json(); if (responseObj.data) { yield put({ - type: "GET_RECOGNITION_LIST_SUCCESS", + type: status.success, payload: responseObj.data, }); } else { yield put({ - type: "GET_RECOGNITION_LIST_FAILURE", + type: status.failure, payload: responseObj.error, }); } } catch (error) { - yield put({ type: "GET_RECOGNITION_LIST_FAILURE", payload: error }); + yield put({ type: status.failure, payload: error }); } } export function* recognitionApi() { - yield takeEvery("RECOGNITION_GET_API", getRecognitionList); + yield takeEvery("LIST_RECOGNITION_API", getRecognitionList); } export default function* rootRecognitionSaga() { From a57181d69fa6e986e45fd1e2ed42d50f35fb1b73 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Thu, 28 May 2020 15:56:46 +0530 Subject: [PATCH 19/35] update RecognitionContainer because of change file name of recognitionReducer to listRecognitionReducer --- .../src/recognition-list/RecognitionListContainer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/react-frontend/src/recognition-list/RecognitionListContainer.js b/react-frontend/src/recognition-list/RecognitionListContainer.js index b7ab37e09..e7d3f475a 100644 --- a/react-frontend/src/recognition-list/RecognitionListContainer.js +++ b/react-frontend/src/recognition-list/RecognitionListContainer.js @@ -5,11 +5,11 @@ import SessionTimeoutComponent from "shared-components/SessionTimeoutComponent"; import UnauthorisedErrorComponent from "shared-components/UnauthorisedErrorComponent"; const RecognnitionListContainer = () => { - const recognitionList = useSelector((state) => state.recognitionReducer); + const recognitionList = useSelector((state) => state.listRecognitionReducer); const dispatch = useDispatch(); useEffect(() => { - dispatch({ type: "RECOGNITION_GET_API" }); + dispatch({ type: "LIST_RECOGNITION_API" }); }, [dispatch]); if (recognitionList.error.code === "invalid_token") { From 6610c833867678f9cfe1544115b21374031835c2 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Thu, 28 May 2020 16:34:49 +0530 Subject: [PATCH 20/35] add some test case for recognitionSaga --- react-frontend/src/sagas/recognitionSaga.test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/react-frontend/src/sagas/recognitionSaga.test.js b/react-frontend/src/sagas/recognitionSaga.test.js index 9964ff133..2e0f63b81 100644 --- a/react-frontend/src/sagas/recognitionSaga.test.js +++ b/react-frontend/src/sagas/recognitionSaga.test.js @@ -4,24 +4,24 @@ import { recognitionApi, getRecognitionList } from "sagas/recognitionSaga"; import getJson from "utils/getJson"; describe("RECOGNITION SAGAS", () => { - it("should dispatch action 'RECOGNITION_GET_API' for recognition saga", () => { + it("should dispatch action 'LIST_RECOGNITION_API' for recognition saga", () => { const generator = recognitionApi(); expect(generator.next().value).toEqual( - takeEvery("RECOGNITION_GET_API", getRecognitionList) + takeEvery("LIST_RECOGNITION_API", getRecognitionList) ); const status = generator.next().done; expect(status).toBeTruthy(); }); - it("should dispatch action 'RECOGNITION_GET_API' with result from fetch get list API", () => { + it("should dispatch action 'LIST_RECOGNITION_API' for fetch list", () => { const generator = getRecognitionList(); - expect(generator.next().value).toEqual( call(getJson, { path: "recognitions", - apiToken: - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJub2RlLnBlZXJseS5jb20iLCJzdWIiOjE5LCJhdWQiOiJwZWVybHkuY29tIiwibmJmIjoxNTkwNjM2NDUyLCJodHRwczovL3BlZXJseS5jb20iOnsicm9sZUlkIjozLCJvcmdJZCI6Mywib3JnTmFtZSI6Impvc2gifSwiaWF0IjoxNTkwNjM2NDUyLCJleHAiOjE1OTA2NzI0NTJ9.MKkukGmgx9RHyFm_dfrGp8j_W09fBU8Qy9EzPXXcv3w", + apiToken: "", }) ); + expect(generator.next().done).toEqual(false); + expect(generator.next().done).toBeTruthy(); }); }); From ccdd29883557ee3a84bc41a002377395a6e2a716 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Thu, 28 May 2020 19:15:07 +0530 Subject: [PATCH 21/35] update test case message as per action possiblity --- react-frontend/src/reducers/listRecognitionReducer.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/react-frontend/src/reducers/listRecognitionReducer.test.js b/react-frontend/src/reducers/listRecognitionReducer.test.js index 4f0726894..02ae9d2ab 100644 --- a/react-frontend/src/reducers/listRecognitionReducer.test.js +++ b/react-frontend/src/reducers/listRecognitionReducer.test.js @@ -1,7 +1,7 @@ import reducer, { defaultState } from "reducers/listRecognitionReducer"; import actionGenerator from "utils/actionGenerator"; -describe("recognition reducer", () => { +describe("list recognition reducer", () => { const status = actionGenerator("LIST_RECOGNITION"); it("recognition reducer should return the initial state", () => { @@ -11,7 +11,7 @@ describe("recognition reducer", () => { }); }); - it("recognition reducer should handle 'GET_RECOGNITION_LIST_SUCCESS' action", () => { + it("recognition reducer should handle success action", () => { let reducerData = reducer(defaultState, { type: status.success, payload: [{ id: 1 }], @@ -22,7 +22,7 @@ describe("recognition reducer", () => { }); }); - it("recognition reducer should handle 'GET_RECOGNITION_LIST_FAILURE' action", () => { + it("recognition reducer should handle failure action", () => { let reducerData = reducer(defaultState, { type: status.failure, payload: { code: "invalid token" }, From 0584c665e7ba81ff5bacdcbfb6c680b799e75768 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Fri, 29 May 2020 11:48:49 +0530 Subject: [PATCH 22/35] update test case of recognitionSaga test.js --- react-frontend/src/sagas/recognitionSaga.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/react-frontend/src/sagas/recognitionSaga.test.js b/react-frontend/src/sagas/recognitionSaga.test.js index 2e0f63b81..9eb0f6044 100644 --- a/react-frontend/src/sagas/recognitionSaga.test.js +++ b/react-frontend/src/sagas/recognitionSaga.test.js @@ -10,7 +10,7 @@ describe("RECOGNITION SAGAS", () => { takeEvery("LIST_RECOGNITION_API", getRecognitionList) ); const status = generator.next().done; - expect(status).toBeTruthy(); + expect(status).toEqual(true); }); it("should dispatch action 'LIST_RECOGNITION_API' for fetch list", () => { @@ -22,6 +22,6 @@ describe("RECOGNITION SAGAS", () => { }) ); expect(generator.next().done).toEqual(false); - expect(generator.next().done).toBeTruthy(); + expect(generator.next().done).toEqual(true); }); }); From 100381c764e9fbeb597d7f82a88b436961e6199a Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Fri, 29 May 2020 12:49:15 +0530 Subject: [PATCH 23/35] adjust proper indentation in recognitionSaga and listRecognitionReducer test case file --- react-frontend/src/reducers/listRecognitionReducer.test.js | 6 +++--- react-frontend/src/sagas/recognitionSaga.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/react-frontend/src/reducers/listRecognitionReducer.test.js b/react-frontend/src/reducers/listRecognitionReducer.test.js index 02ae9d2ab..c766a74c8 100644 --- a/react-frontend/src/reducers/listRecognitionReducer.test.js +++ b/react-frontend/src/reducers/listRecognitionReducer.test.js @@ -4,14 +4,14 @@ import actionGenerator from "utils/actionGenerator"; describe("list recognition reducer", () => { const status = actionGenerator("LIST_RECOGNITION"); - it("recognition reducer should return the initial state", () => { + it("list recognition reducer should return the initial state", () => { expect(reducer(defaultState, {})).toEqual({ list: [{}], error: {}, }); }); - it("recognition reducer should handle success action", () => { + it("list recognition reducer should handle success action", () => { let reducerData = reducer(defaultState, { type: status.success, payload: [{ id: 1 }], @@ -22,7 +22,7 @@ describe("list recognition reducer", () => { }); }); - it("recognition reducer should handle failure action", () => { + it("list recognition reducer should handle failure action", () => { let reducerData = reducer(defaultState, { type: status.failure, payload: { code: "invalid token" }, diff --git a/react-frontend/src/sagas/recognitionSaga.js b/react-frontend/src/sagas/recognitionSaga.js index faf122ff1..021f396d9 100644 --- a/react-frontend/src/sagas/recognitionSaga.js +++ b/react-frontend/src/sagas/recognitionSaga.js @@ -1,6 +1,6 @@ import { put, takeEvery, spawn, call } from "redux-saga/effects"; -import getJson from "utils/getJson"; +import getJson from "utils/getJson"; import actionGenerator from "utils/actionGenerator"; export function* getRecognitionList() { From 7e1bcf4fa5cd22fe540c642eeb05b0cb89a03911 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Wed, 10 Jun 2020 10:06:58 +0530 Subject: [PATCH 24/35] add recognition saga test cases for success full get list call --- .../src/sagas/recognitionSaga.test.js | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) 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); }); }); From 8ecf64c6cbe61602d1bd36340cf52709804e82b7 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Wed, 10 Jun 2020 10:09:38 +0530 Subject: [PATCH 25/35] add mock response files for get list api call --- .../get_api_call_failure_response.json | 6 +++ .../get_api_call_success_response.json | 54 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 mock-responses/recognitions/get_api_call_failure_response.json create mode 100644 mock-responses/recognitions/get_api_call_success_response.json diff --git a/mock-responses/recognitions/get_api_call_failure_response.json b/mock-responses/recognitions/get_api_call_failure_response.json new file mode 100644 index 000000000..1bd1c22b5 --- /dev/null +++ b/mock-responses/recognitions/get_api_call_failure_response.json @@ -0,0 +1,6 @@ +{ + "error": { + "code": "invalid_token", + "message": "unauthorized user" + } +} diff --git a/mock-responses/recognitions/get_api_call_success_response.json b/mock-responses/recognitions/get_api_call_success_response.json new file mode 100644 index 000000000..2fe4688d2 --- /dev/null +++ b/mock-responses/recognitions/get_api_call_success_response.json @@ -0,0 +1,54 @@ +{ + "data": [ + { + "id": 1, + "core_value_id": 2, + "text": "good work", + "given_for": 4, + "given_by": 6, + "given_at": "1588924868", + "givenFor": { + "id": 4, + "first_name": "Avinash", + "last_name": "mane", + "profile_image_url": null + }, + "givenBy": { + "id": 6, + "first_name": "Avinash", + "last_name": "mane", + "profile_image_url": null + }, + "core_value": { + "id": 2, + "text": "good work", + "description": "good working in peerly" + } + }, + { + "id": 1, + "core_value_id": 2, + "text": "good work", + "given_for": 4, + "given_by": 6, + "given_at": "1588924868", + "givenFor": { + "id": 4, + "first_name": "Avinash", + "last_name": "mane", + "profile_image_url": null + }, + "givenBy": { + "id": 6, + "first_name": "Avinash", + "last_name": "mane", + "profile_image_url": null + }, + "core_value": { + "id": 2, + "text": "good work", + "description": "good working in peerly" + } + } + ] +} \ No newline at end of file From fe600d2005d78bb1bb1b96b3565b357f92853b6e Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Wed, 10 Jun 2020 10:20:33 +0530 Subject: [PATCH 26/35] update defaulte state of reducer as per get list api response and update there test cases --- .../src/reducers/listRecognitionReducer.js | 12 ++++++++-- .../reducers/listRecognitionReducer.test.js | 24 +++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/react-frontend/src/reducers/listRecognitionReducer.js b/react-frontend/src/reducers/listRecognitionReducer.js index 243623184..a8153c679 100644 --- a/react-frontend/src/reducers/listRecognitionReducer.js +++ b/react-frontend/src/reducers/listRecognitionReducer.js @@ -1,8 +1,16 @@ import actionGenerator from "utils/actionGenerator"; export const defaultState = { - list: [{}], - error: {}, + list: [ + { + core_value: {}, + givenFor: {}, + givenBy: {}, + }, + ], + error: { + fields: {}, + }, }; const status = actionGenerator("LIST_RECOGNITION"); diff --git a/react-frontend/src/reducers/listRecognitionReducer.test.js b/react-frontend/src/reducers/listRecognitionReducer.test.js index c766a74c8..d8fec701f 100644 --- a/react-frontend/src/reducers/listRecognitionReducer.test.js +++ b/react-frontend/src/reducers/listRecognitionReducer.test.js @@ -6,8 +6,16 @@ describe("list recognition reducer", () => { it("list recognition reducer should return the initial state", () => { expect(reducer(defaultState, {})).toEqual({ - list: [{}], - error: {}, + list: [ + { + core_value: {}, + givenFor: {}, + givenBy: {}, + }, + ], + error: { + fields: {}, + }, }); }); @@ -18,7 +26,9 @@ describe("list recognition reducer", () => { }); expect(reducerData).toEqual({ list: [{ id: 1 }], - error: {}, + error: { + fields: {}, + }, }); }); @@ -28,7 +38,13 @@ describe("list recognition reducer", () => { payload: { code: "invalid token" }, }); expect(reducerData).toEqual({ - list: [{}], + list: [ + { + core_value: {}, + givenFor: {}, + givenBy: {}, + }, + ], error: { code: "invalid token" }, }); }); From e8ef2df6776c858c21bf2f5e29b7099799830ef7 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Thu, 11 Jun 2020 15:35:29 +0530 Subject: [PATCH 27/35] add action file for list recognition container for provide action object --- react-frontend/src/actions/listRecognitionAction.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 react-frontend/src/actions/listRecognitionAction.js diff --git a/react-frontend/src/actions/listRecognitionAction.js b/react-frontend/src/actions/listRecognitionAction.js new file mode 100644 index 000000000..68f5e3036 --- /dev/null +++ b/react-frontend/src/actions/listRecognitionAction.js @@ -0,0 +1,6 @@ +export default (type, payload) => { + return { + type: type, + payload: payload, + }; +}; From 5b788d697fd5751ed2778340d2eecf20d7268e18 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Thu, 11 Jun 2020 15:36:12 +0530 Subject: [PATCH 28/35] update recognition list container and get action object from action/listRecognitionAction.js and pass to dispatch and use actionGenrator for typeof action --- .../src/recognition-list/RecognitionListContainer.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/react-frontend/src/recognition-list/RecognitionListContainer.js b/react-frontend/src/recognition-list/RecognitionListContainer.js index e7d3f475a..d6f5a3192 100644 --- a/react-frontend/src/recognition-list/RecognitionListContainer.js +++ b/react-frontend/src/recognition-list/RecognitionListContainer.js @@ -3,14 +3,17 @@ import { useSelector, useDispatch } from "react-redux"; import SessionTimeoutComponent from "shared-components/SessionTimeoutComponent"; import UnauthorisedErrorComponent from "shared-components/UnauthorisedErrorComponent"; +import actionObject from "actions/listRecognitionAction"; +import actionGenrator from "utils/actionGenerator"; const RecognnitionListContainer = () => { const recognitionList = useSelector((state) => state.listRecognitionReducer); const dispatch = useDispatch(); + const status = actionGenrator("LIST_RECOGNITION_API"); useEffect(() => { - dispatch({ type: "LIST_RECOGNITION_API" }); - }, [dispatch]); + dispatch(actionObject(status.success)); + }, [dispatch, status.success]); if (recognitionList.error.code === "invalid_token") { return ; From c5dc7d368e9e66a9a7a4dcd8a55233db00942a86 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Thu, 11 Jun 2020 15:45:50 +0530 Subject: [PATCH 29/35] use actionGenerator in saga and update there test cases --- react-frontend/src/sagas/recognitionSaga.js | 3 ++- react-frontend/src/sagas/recognitionSaga.test.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/react-frontend/src/sagas/recognitionSaga.js b/react-frontend/src/sagas/recognitionSaga.js index 021f396d9..1f35d244f 100644 --- a/react-frontend/src/sagas/recognitionSaga.js +++ b/react-frontend/src/sagas/recognitionSaga.js @@ -28,7 +28,8 @@ export function* getRecognitionList() { } export function* recognitionApi() { - yield takeEvery("LIST_RECOGNITION_API", getRecognitionList); + const status = actionGenerator("LIST_RECOGNITION_API"); + yield takeEvery(status.success, getRecognitionList); } export default function* rootRecognitionSaga() { diff --git a/react-frontend/src/sagas/recognitionSaga.test.js b/react-frontend/src/sagas/recognitionSaga.test.js index 722c88074..7e391f971 100644 --- a/react-frontend/src/sagas/recognitionSaga.test.js +++ b/react-frontend/src/sagas/recognitionSaga.test.js @@ -8,12 +8,13 @@ import failure_mockResponse from "../../../mock-responses/recognitions/get_api_c describe("RECOGNITION SAGAS", () => { const status = actionGenerator("LIST_RECOGNITION"); + const apiStatus = actionGenerator("LIST_RECOGNITION_API"); const response = { json: () => "success" }; it("should dispatch action 'LIST_RECOGNITION_API' for recognition saga", () => { const generator = recognitionApi(); expect(generator.next().value).toEqual( - takeEvery("LIST_RECOGNITION_API", getRecognitionList) + takeEvery(apiStatus.success, getRecognitionList) ); const status = generator.next().done; expect(status).toEqual(true); From c3a4e2a3e2f129c1cfa76e1d540ca2780c39c73b Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Thu, 11 Jun 2020 16:02:19 +0530 Subject: [PATCH 30/35] use actionObjectGenerator function for action object in recognition reducer test cases --- .../src/reducers/listRecognitionReducer.test.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/react-frontend/src/reducers/listRecognitionReducer.test.js b/react-frontend/src/reducers/listRecognitionReducer.test.js index d8fec701f..560b94198 100644 --- a/react-frontend/src/reducers/listRecognitionReducer.test.js +++ b/react-frontend/src/reducers/listRecognitionReducer.test.js @@ -1,5 +1,6 @@ import reducer, { defaultState } from "reducers/listRecognitionReducer"; import actionGenerator from "utils/actionGenerator"; +import actionObjectGenerator from "actions/listRecognitionAction"; describe("list recognition reducer", () => { const status = actionGenerator("LIST_RECOGNITION"); @@ -20,10 +21,10 @@ describe("list recognition reducer", () => { }); it("list recognition reducer should handle success action", () => { - let reducerData = reducer(defaultState, { - type: status.success, - payload: [{ id: 1 }], - }); + let reducerData = reducer( + defaultState, + actionObjectGenerator(status.success, [{ id: 1 }]) + ); expect(reducerData).toEqual({ list: [{ id: 1 }], error: { @@ -33,10 +34,10 @@ describe("list recognition reducer", () => { }); it("list recognition reducer should handle failure action", () => { - let reducerData = reducer(defaultState, { - type: status.failure, - payload: { code: "invalid token" }, - }); + let reducerData = reducer( + defaultState, + actionObjectGenerator(status.failure, { code: "invalid token" }) + ); expect(reducerData).toEqual({ list: [ { From f3361f55910955a70a071deeefc87d2fb2c4f33d Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Thu, 11 Jun 2020 16:23:47 +0530 Subject: [PATCH 31/35] create actionConstants.js file for add actions names --- react-frontend/src/constants/actionConstants.js | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 react-frontend/src/constants/actionConstants.js diff --git a/react-frontend/src/constants/actionConstants.js b/react-frontend/src/constants/actionConstants.js new file mode 100644 index 000000000..0d26f856f --- /dev/null +++ b/react-frontend/src/constants/actionConstants.js @@ -0,0 +1,3 @@ +export const LIST_RECOGNITION = "LIST_RECOGNITION"; + +export const LIST_RECOGNITION_API = "LIST_RECOGNITION_API"; From 71e1197a5b9124b677b05a9f2dbdb47aef6ad6dd Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Thu, 11 Jun 2020 16:25:51 +0530 Subject: [PATCH 32/35] use the action name into recognition saga and test case file and also in recognition list container --- .../src/recognition-list/RecognitionListContainer.js | 3 ++- react-frontend/src/sagas/recognitionSaga.js | 8 ++++++-- react-frontend/src/sagas/recognitionSaga.test.js | 8 ++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/react-frontend/src/recognition-list/RecognitionListContainer.js b/react-frontend/src/recognition-list/RecognitionListContainer.js index d6f5a3192..43fd3570e 100644 --- a/react-frontend/src/recognition-list/RecognitionListContainer.js +++ b/react-frontend/src/recognition-list/RecognitionListContainer.js @@ -5,11 +5,12 @@ import SessionTimeoutComponent from "shared-components/SessionTimeoutComponent"; import UnauthorisedErrorComponent from "shared-components/UnauthorisedErrorComponent"; import actionObject from "actions/listRecognitionAction"; import actionGenrator from "utils/actionGenerator"; +import { LIST_RECOGNITION_API } from "constants/actionConstants"; const RecognnitionListContainer = () => { const recognitionList = useSelector((state) => state.listRecognitionReducer); const dispatch = useDispatch(); - const status = actionGenrator("LIST_RECOGNITION_API"); + const status = actionGenrator(LIST_RECOGNITION_API); useEffect(() => { dispatch(actionObject(status.success)); diff --git a/react-frontend/src/sagas/recognitionSaga.js b/react-frontend/src/sagas/recognitionSaga.js index 1f35d244f..bb43d2cdc 100644 --- a/react-frontend/src/sagas/recognitionSaga.js +++ b/react-frontend/src/sagas/recognitionSaga.js @@ -2,9 +2,13 @@ import { put, takeEvery, spawn, call } from "redux-saga/effects"; import getJson from "utils/getJson"; import actionGenerator from "utils/actionGenerator"; +import { + LIST_RECOGNITION, + LIST_RECOGNITION_API, +} from "constants/actionConstants"; export function* getRecognitionList() { - const status = actionGenerator("LIST_RECOGNITION"); + const status = actionGenerator(LIST_RECOGNITION); try { const response = yield call(getJson, { path: "recognitions", @@ -28,7 +32,7 @@ export function* getRecognitionList() { } export function* recognitionApi() { - const status = actionGenerator("LIST_RECOGNITION_API"); + const status = actionGenerator(LIST_RECOGNITION_API); yield takeEvery(status.success, getRecognitionList); } diff --git a/react-frontend/src/sagas/recognitionSaga.test.js b/react-frontend/src/sagas/recognitionSaga.test.js index 7e391f971..f80293651 100644 --- a/react-frontend/src/sagas/recognitionSaga.test.js +++ b/react-frontend/src/sagas/recognitionSaga.test.js @@ -5,10 +5,14 @@ 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"; +import { + LIST_RECOGNITION_API, + LIST_RECOGNITION, +} from "constants/actionConstants.js"; describe("RECOGNITION SAGAS", () => { - const status = actionGenerator("LIST_RECOGNITION"); - const apiStatus = actionGenerator("LIST_RECOGNITION_API"); + const status = actionGenerator(LIST_RECOGNITION); + const apiStatus = actionGenerator(LIST_RECOGNITION_API); const response = { json: () => "success" }; it("should dispatch action 'LIST_RECOGNITION_API' for recognition saga", () => { From a840e5b0d8f18646893bcafe9ac2ccdd0a12e91c Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Thu, 11 Jun 2020 16:43:17 +0530 Subject: [PATCH 33/35] use actionObjectGentrator in saga and there test cases --- react-frontend/src/sagas/recognitionSaga.js | 13 ++++--------- react-frontend/src/sagas/recognitionSaga.test.js | 11 +++-------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/react-frontend/src/sagas/recognitionSaga.js b/react-frontend/src/sagas/recognitionSaga.js index bb43d2cdc..d1f35bbee 100644 --- a/react-frontend/src/sagas/recognitionSaga.js +++ b/react-frontend/src/sagas/recognitionSaga.js @@ -1,6 +1,7 @@ import { put, takeEvery, spawn, call } from "redux-saga/effects"; import getJson from "utils/getJson"; +import actionObjectGenerator from "actions/listRecognitionAction"; import actionGenerator from "utils/actionGenerator"; import { LIST_RECOGNITION, @@ -16,18 +17,12 @@ export function* getRecognitionList() { }); const responseObj = yield response.json(); if (responseObj.data) { - yield put({ - type: status.success, - payload: responseObj.data, - }); + yield put(actionObjectGenerator(status.success, responseObj.data)); } else { - yield put({ - type: status.failure, - payload: responseObj.error, - }); + yield put(actionObjectGenerator(status.failure, responseObj.error)); } } catch (error) { - yield put({ type: status.failure, payload: error }); + yield put(actionObjectGenerator(status.failure, error)); } } diff --git a/react-frontend/src/sagas/recognitionSaga.test.js b/react-frontend/src/sagas/recognitionSaga.test.js index f80293651..a96b35801 100644 --- a/react-frontend/src/sagas/recognitionSaga.test.js +++ b/react-frontend/src/sagas/recognitionSaga.test.js @@ -9,6 +9,7 @@ import { LIST_RECOGNITION_API, LIST_RECOGNITION, } from "constants/actionConstants.js"; +import actionObjectGenerator from "actions/listRecognitionAction"; describe("RECOGNITION SAGAS", () => { const status = actionGenerator(LIST_RECOGNITION); @@ -36,10 +37,7 @@ describe("RECOGNITION SAGAS", () => { ); generator.next(response).value; expect(generator.next(success_mockResponse).value).toEqual( - put({ - type: status.success, - payload: success_mockResponse.data, - }) + put(actionObjectGenerator(status.success, success_mockResponse.data)) ); expect(generator.next().done).toEqual(true); }); @@ -55,10 +53,7 @@ describe("RECOGNITION SAGAS", () => { ); expect(generator.next(response).value).toEqual("success"); expect(generator.next(failure_mockResponse).value).toEqual( - put({ - type: status.failure, - payload: failure_mockResponse.error, - }) + put(actionObjectGenerator(status.failure, failure_mockResponse.error)) ); expect(generator.next().done).toEqual(true); }); From edbc0e9e60ef4afc8ebf7489e83f6079cea0ea23 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Thu, 11 Jun 2020 17:17:28 +0530 Subject: [PATCH 34/35] update success mockResponse json file --- .../recognitions/get_api_call_success_response.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mock-responses/recognitions/get_api_call_success_response.json b/mock-responses/recognitions/get_api_call_success_response.json index 2fe4688d2..5f68e2a87 100644 --- a/mock-responses/recognitions/get_api_call_success_response.json +++ b/mock-responses/recognitions/get_api_call_success_response.json @@ -11,7 +11,7 @@ "id": 4, "first_name": "Avinash", "last_name": "mane", - "profile_image_url": null + "profile_image_url": null }, "givenBy": { "id": 6, @@ -26,7 +26,7 @@ } }, { - "id": 1, + "id": 2, "core_value_id": 2, "text": "good work", "given_for": 4, From 949a94314adbceda1845173b2ae706a48d7f41c6 Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Thu, 11 Jun 2020 17:22:37 +0530 Subject: [PATCH 35/35] correct some code before ready to review --- .../recognitions/get_api_call_success_response.json | 2 +- .../src/recognition-list/RecognitionListContainer.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mock-responses/recognitions/get_api_call_success_response.json b/mock-responses/recognitions/get_api_call_success_response.json index 5f68e2a87..10a860750 100644 --- a/mock-responses/recognitions/get_api_call_success_response.json +++ b/mock-responses/recognitions/get_api_call_success_response.json @@ -51,4 +51,4 @@ } } ] -} \ No newline at end of file +} diff --git a/react-frontend/src/recognition-list/RecognitionListContainer.js b/react-frontend/src/recognition-list/RecognitionListContainer.js index 43fd3570e..478b0cbc2 100644 --- a/react-frontend/src/recognition-list/RecognitionListContainer.js +++ b/react-frontend/src/recognition-list/RecognitionListContainer.js @@ -3,7 +3,7 @@ import { useSelector, useDispatch } from "react-redux"; import SessionTimeoutComponent from "shared-components/SessionTimeoutComponent"; import UnauthorisedErrorComponent from "shared-components/UnauthorisedErrorComponent"; -import actionObject from "actions/listRecognitionAction"; +import actionObjectGenrator from "actions/listRecognitionAction"; import actionGenrator from "utils/actionGenerator"; import { LIST_RECOGNITION_API } from "constants/actionConstants"; @@ -13,7 +13,7 @@ const RecognnitionListContainer = () => { const status = actionGenrator(LIST_RECOGNITION_API); useEffect(() => { - dispatch(actionObject(status.success)); + dispatch(actionObjectGenrator(status.success)); }, [dispatch, status.success]); if (recognitionList.error.code === "invalid_token") {