Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/store/api/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 4 additions & 3 deletions src/store/api/reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 },
Expand Down
7 changes: 7 additions & 0 deletions src/store/api/saga.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -120,6 +121,7 @@ test("API_CALL method with parameters", async () => {
state: "LOADED",
value: `ret${rkAddress}activePremiums`,
code: 200,
error_detail: null,
},
});

Expand Down Expand Up @@ -160,6 +162,7 @@ test("API_CALL POST new user success", async () => {
state: "LOADED",
value: "withPersonaReferenceID",
code: 200,
error_detail: null,
},
});
});
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
},
});

Expand Down Expand Up @@ -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(
Expand Down
24 changes: 18 additions & 6 deletions src/store/api/selector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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]);
Expand All @@ -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 () => {
Expand Down Expand Up @@ -129,20 +139,22 @@ describe("selectAPICallMultiple with activePremiums and apy", () => {
call_key: apyCallKey,
value: 1000,
timestamp: new Date().getTime(),
code: 200,
});

result = selectAPICallMultiple(store.getState().APIReducer, [
{ apiName: "apy", args: [currencyAddress] },
{ 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, [
Expand All @@ -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 },
]);
});
});
Loading