diff --git a/src/store/api/reducer.js b/src/store/api/reducer.js index 1f189cd..9fa82b8 100644 --- a/src/store/api/reducer.js +++ b/src/store/api/reducer.js @@ -70,13 +70,13 @@ const APIReducer = (state = INIT_STATE, action) => { newState = modifyNode(newState, ["calls", action.call_key], (call) => { if (call !== undefined && call.state === "LOADED" && call.retries === undefined && call.value === action.value) return call; - return { state: "LOADED", value: action.value, code: action.code }; + return { state: "LOADED", value: action.value, code: action.code, error_detail: null }; }); break; case API_CALL_FAIL: newState = modifyNode(state, ["calls", action.call_key], (x) => { - return { ...x, state: "ERROR", value: action.value, code: action.code }; + return { ...x, state: "ERROR", error_detail: action.value, code: action.code }; }); break; diff --git a/src/store/api/reducer.test.js b/src/store/api/reducer.test.js index 048f613..db02263 100644 --- a/src/store/api/reducer.test.js +++ b/src/store/api/reducer.test.js @@ -158,12 +158,13 @@ describe("API Reducer tests", () => { type: "API_CALL_SUCCESS", call_key: call_key, value: 912, + code: 200, timestamp: 1703683845252, }; const expectedState = { ...state, - calls: { [call_key]: { state: "LOADED", value: 912 } }, + calls: { [call_key]: { state: "LOADED", value: 912, code: 200, error_detail: null } }, call_metadata: { [call_key]: { timestamp: 1703683845252 } }, }; expect(APIReducer(initialState, action)).toEqual(expectedState); @@ -182,12 +183,12 @@ describe("API Reducer tests", () => { call_metadata: { [call_key]: { timestamp: 1703683845252 } }, }; - const action = { type: "API_CALL_SUCCESS", call_key: call_key2, value: 10, timestamp: 1703683849000 }; + const action = { type: "API_CALL_SUCCESS", call_key: call_key2, value: 10, timestamp: 1703683849000, code: 200 }; const expectedState = { ...state, calls: { [call_key]: { state: "LOADED", value: 912 }, - [call_key2]: { state: "LOADED", value: 10 }, + [call_key2]: { state: "LOADED", value: 10, code: 200, error_detail: null }, }, call_metadata: { [call_key]: { timestamp: 1703683845252 }, diff --git a/src/store/api/saga.test.js b/src/store/api/saga.test.js index bf204fa..7b1a342 100644 --- a/src/store/api/saga.test.js +++ b/src/store/api/saga.test.js @@ -71,6 +71,7 @@ test("API_CALL with simple method", async () => { state: "LOADED", value: Big(api_calls.getFieldSumByChar("apy")), code: 200, + error_detail: null, }, }); assert.ok( @@ -120,6 +121,7 @@ test("API_CALL method with parameters", async () => { state: "LOADED", value: `ret${rkAddress}activePremiums`, code: 200, + error_detail: null, }, }); @@ -160,6 +162,7 @@ test("API_CALL POST new user success", async () => { state: "LOADED", value: "withPersonaReferenceID", code: 200, + error_detail: null, }, }); }); @@ -254,6 +257,7 @@ test("API_ADD_SUBSCRIPTION and API_DISPATCH_CLOCK with one ethCall", async () => state: "LOADED", value: Big(api_calls.getFieldSumByChar("apy")), code: 200, + error_detail: null, }, }); assert.ok( @@ -306,11 +310,13 @@ test("API_ADD_SUBSCRIPTION and API_DISPATCH_CLOCK with two apiCall", async () => state: "LOADED", value: Big(api_calls.getFieldSumByChar("apy")), code: 200, + error_detail: null, }, [active_premiums_call_key]: { state: "LOADED", value: `ret${rkAddress}activePremiums`, code: 200, + error_detail: null, }, }); @@ -356,6 +362,7 @@ test("ONE call and remove the subscription", async () => { state: "LOADED", value: Big(api_calls.getFieldSumByChar("apy")), code: 200, + error_detail: null, }, }); assert.ok( diff --git a/src/store/api/selector.test.js b/src/store/api/selector.test.js index 4d580fd..ba138b8 100644 --- a/src/store/api/selector.test.js +++ b/src/store/api/selector.test.js @@ -8,6 +8,7 @@ import MockAdapter from "axios-mock-adapter"; import * as api_calls from "../../utils/helpers/api_calls"; import * as mock_helper from "../../helpers/mock_helper"; import axios from "axios"; +import { error } from "console"; const sinon = require("sinon"); @@ -66,9 +67,15 @@ describe("selectAPICallMultiple with activePremiums and apy", () => { let result = selectAPICallMultiple(store.getState().APIReducer, [{ apiName: "apy", args: [currencyAddress] }]); expect(result).toEqual([{ state: "LOADING" }]); - store.dispatch({ type: "API_CALL_SUCCESS", call_key: call_key, value: 1000, timestamp: new Date().getTime() }); + store.dispatch({ + type: "API_CALL_SUCCESS", + call_key: call_key, + value: 1000, + timestamp: new Date().getTime(), + code: 200, + }); result = selectAPICallMultiple(store.getState().APIReducer, [{ apiName: "apy", args: [currencyAddress] }]); - expect(result).toEqual([{ state: "LOADED", value: 1000 }]); + expect(result).toEqual([{ state: "LOADED", value: 1000, code: 200, error_detail: null }]); let result2 = selectAPICallMultiple(store.getState().APIReducer, [{ apiName: "apy", args: [currencyAddress] }]); assert.strictEqual(result[0], result2[0]); @@ -90,13 +97,16 @@ describe("selectAPICallMultiple with activePremiums and apy", () => { call_key: call_key, value: `ret${currencyAddress}activePremiums`, timestamp: new Date().getTime(), + code: 200, }); result = selectAPICallMultiple(store.getState().APIReducer, [ { apiName: "activePremiums", args: [currencyAddress] }, ]); - expect(result).toEqual([{ state: "LOADED", value: `ret${currencyAddress}activePremiums` }]); + expect(result).toEqual([ + { state: "LOADED", value: `ret${currencyAddress}activePremiums`, code: 200, error_detail: null }, + ]); }); test("should handle multiple calls with different states for apy and activePremiums", async () => { @@ -129,6 +139,7 @@ describe("selectAPICallMultiple with activePremiums and apy", () => { call_key: apyCallKey, value: 1000, timestamp: new Date().getTime(), + code: 200, }); result = selectAPICallMultiple(store.getState().APIReducer, [ @@ -136,13 +147,14 @@ describe("selectAPICallMultiple with activePremiums and apy", () => { { apiName: "activePremiums", args: [currencyAddress] }, ]); - expect(result).toEqual([{ state: "LOADED", value: 1000 }, { state: "LOADING" }]); + expect(result).toEqual([{ state: "LOADED", value: 1000, code: 200, error_detail: null }, { state: "LOADING" }]); store.dispatch({ type: "API_CALL_SUCCESS", call_key: activePremiumsCallKey, value: `ret${currencyAddress}activePremiums`, timestamp: new Date().getTime(), + code: 200, }); result = selectAPICallMultiple(store.getState().APIReducer, [ @@ -151,8 +163,8 @@ describe("selectAPICallMultiple with activePremiums and apy", () => { ]); expect(result).toEqual([ - { state: "LOADED", value: 1000 }, - { state: "LOADED", value: `ret${currencyAddress}activePremiums` }, + { state: "LOADED", value: 1000, code: 200, error_detail: null }, + { state: "LOADED", value: `ret${currencyAddress}activePremiums`, code: 200, error_detail: null }, ]); }); });