Skip to content

Commit

Permalink
fix: Final rename of error counting field
Browse files Browse the repository at this point in the history
  • Loading branch information
grmartin committed Jul 7, 2023
1 parent 19cd49a commit 2cada4d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/payment/data/__snapshots__/redux.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Object {
"paymentState": "checkout",
"paymentStatePolling": Object {
"keepPolling": false,
"retryCount": 5,
"retriesLeft": 5,
},
"products": Array [],
"redirect": false,
Expand All @@ -36,7 +36,7 @@ Object {
"paymentState": "checkout",
"paymentStatePolling": Object {
"keepPolling": false,
"retryCount": 5,
"retriesLeft": 5,
},
"products": Array [],
"redirect": false,
Expand All @@ -63,7 +63,7 @@ Object {
"paymentState": "checkout",
"paymentStatePolling": Object {
"keepPolling": false,
"retryCount": 5,
"retriesLeft": 5,
},
"products": Array [],
"redirect": false,
Expand Down
16 changes: 8 additions & 8 deletions src/payment/data/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const paymentStatePollingInitialState = {
* This is replaceable by a configuration value. (`PAYMENT_STATE_POLLING_MAX_ERRORS`),
* however, this is our default.
*/
retryCount: DEFAULT_PAYMENT_STATE_POLLING_MAX_ERRORS,
retriesLeft: DEFAULT_PAYMENT_STATE_POLLING_MAX_ERRORS,
};

/**
Expand Down Expand Up @@ -173,7 +173,7 @@ const clientSecret = (state = clientSecretInitialState, action = null) => {
*/
export const paymentState = (state = basketInitialState, action = null) => {
// noinspection JSUnresolvedReference
const maxErrors = getConfig().PAYMENT_STATE_POLLING_MAX_ERRORS || paymentStatePollingInitialState.retryCount;
const maxErrors = getConfig().PAYMENT_STATE_POLLING_MAX_ERRORS || paymentStatePollingInitialState.retriesLeft;
const shouldPoll = (payState) => POLLING_PAYMENT_STATES.includes(payState);

if (action !== null && action !== undefined) {
Expand All @@ -184,7 +184,7 @@ export const paymentState = (state = basketInitialState, action = null) => {
paymentStatePolling: {
...state.paymentStatePolling,
keepPolling: shouldPoll(state.paymentState),
retryCount: maxErrors,
retriesLeft: maxErrors,
},
};

Expand All @@ -195,7 +195,7 @@ export const paymentState = (state = basketInitialState, action = null) => {
paymentStatePolling: {
...state.paymentStatePolling,
keepPolling: false,
retryCount: maxErrors,
retriesLeft: maxErrors,
},
};

Expand All @@ -205,20 +205,20 @@ export const paymentState = (state = basketInitialState, action = null) => {
paymentStatePolling: {
...state.paymentStatePolling,
keepPolling: false,
retryCount: maxErrors,
retriesLeft: maxErrors,
},
};

case pollPaymentState.RECEIVED: {
const isHttpError = action.payload.state === PAYMENT_STATE.HTTP_ERROR;
const currRetryCnt = (isHttpError ? state.paymentStatePolling.retryCount - 1 : maxErrors);
const currRetriesLeft = (isHttpError ? state.paymentStatePolling.retriesLeft - 1 : maxErrors);
return {
...state,
paymentState: action.payload.state,
paymentStatePolling: {
...state.paymentStatePolling,
keepPolling: currRetryCnt > 0 && shouldPoll(action.payload.state),
retryCount: currRetryCnt,
keepPolling: currRetriesLeft > 0 && shouldPoll(action.payload.state),
retriesLeft: currRetriesLeft,
},
};
}
Expand Down
8 changes: 4 additions & 4 deletions src/payment/data/redux.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('redux tests', () => {
isRedirect: false,
paymentState: PAYMENT_STATE.DEFAULT,
paymentStatePolling: {
retryCount: DEFAULT_PAYMENT_STATE_POLLING_MAX_ERRORS,
retriesLeft: DEFAULT_PAYMENT_STATE_POLLING_MAX_ERRORS,
keepPolling: false,
},
});
Expand All @@ -138,7 +138,7 @@ describe('redux tests', () => {
isRedirect: true, // this is also now true.
paymentState: PAYMENT_STATE.DEFAULT,
paymentStatePolling: {
retryCount: DEFAULT_PAYMENT_STATE_POLLING_MAX_ERRORS,
retriesLeft: DEFAULT_PAYMENT_STATE_POLLING_MAX_ERRORS,
keepPolling: false,
},
});
Expand Down Expand Up @@ -293,12 +293,12 @@ describe('redux tests', () => {
triggerStore.dispatch(pollPaymentState.received({ state: PAYMENT_STATE.HTTP_ERROR }));
expect(triggerStore.getState().payment.basket.paymentStatePolling.keepPolling)
.toBe(expectedCount > 0);
expect(triggerStore.getState().payment.basket.paymentStatePolling.retryCount)
expect(triggerStore.getState().payment.basket.paymentStatePolling.retriesLeft)
.toBe(expectedCount);
}

expect(triggerStore.getState().payment.basket.paymentStatePolling.keepPolling).toBe(false);
expect(triggerStore.getState().payment.basket.paymentStatePolling.retryCount)
expect(triggerStore.getState().payment.basket.paymentStatePolling.retriesLeft)
.toBe(0);

triggerStore.dispatch(pollPaymentState.failure(Error('Too many HTTP errors!')));
Expand Down
4 changes: 2 additions & 2 deletions src/payment/data/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ export function* handlePaymentState() {

yield put(pollPaymentState.received({ state: PAYMENT_STATE.HTTP_ERROR }));

const currentRetryCount = yield select(state => state.payment.basket.paymentStatePolling.retryCount);
const retriesLeft = yield select(state => state.payment.basket.paymentStatePolling.retriesLeft);

if (currentRetryCount === 0) {
if (retriesLeft === 0) {
// noinspection ExceptionCaughtLocallyJS
throw innerError;
}
Expand Down
2 changes: 1 addition & 1 deletion src/payment/data/sagas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ describe('saga tests', () => {
paymentState: inPaymentState,
paymentStatePolling: {
keepPolling: false,
retryCount: DEFAULT_PAYMENT_STATE_POLLING_MAX_ERRORS,
retriesLeft: DEFAULT_PAYMENT_STATE_POLLING_MAX_ERRORS,
},
});

Expand Down

0 comments on commit 2cada4d

Please sign in to comment.