Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexflorisca committed Feb 3, 2023
1 parent bdb273d commit 1dded9e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
15 changes: 5 additions & 10 deletions assets/js/data/checkout/test/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe.only( 'Checkout Store Reducer', () => {
const expectedState = {
...defaultState,
redirectUrl: 'https://example.com',
status: STATUS.IDLE,
};

expect(
Expand Down Expand Up @@ -97,12 +96,15 @@ describe.only( 'Checkout Store Reducer', () => {
} );

it( 'should handle SET_HAS_ERROR when status is anything else', () => {
const initialState = { ...defaultState, status: STATUS.PRISTINE };
const initialState = {
...defaultState,
status: STATUS.AFTER_PROCESSING,
};

const expectedState = {
...defaultState,
hasError: false,
status: STATUS.IDLE,
status: STATUS.AFTER_PROCESSING,
};

expect(
Expand Down Expand Up @@ -135,7 +137,6 @@ describe.only( 'Checkout Store Reducer', () => {
it( 'should handle INCREMENT_CALCULATING', () => {
const expectedState = {
...defaultState,
status: STATUS.IDLE,
calculatingCount: 1,
};

Expand All @@ -152,7 +153,6 @@ describe.only( 'Checkout Store Reducer', () => {

const expectedState = {
...defaultState,
status: STATUS.IDLE,
calculatingCount: 0,
};

Expand All @@ -164,7 +164,6 @@ describe.only( 'Checkout Store Reducer', () => {
it( 'should handle SET_CUSTOMER_ID', () => {
const expectedState = {
...defaultState,
status: STATUS.IDLE,
customerId: 1,
};

Expand All @@ -176,7 +175,6 @@ describe.only( 'Checkout Store Reducer', () => {
it( 'should handle SET_USE_SHIPPING_AS_BILLING', () => {
const expectedState = {
...defaultState,
status: STATUS.IDLE,
useShippingAsBilling: false,
};

Expand All @@ -191,7 +189,6 @@ describe.only( 'Checkout Store Reducer', () => {
it( 'should handle SET_SHOULD_CREATE_ACCOUNT', () => {
const expectedState = {
...defaultState,
status: STATUS.IDLE,
shouldCreateAccount: true,
};

Expand All @@ -206,7 +203,6 @@ describe.only( 'Checkout Store Reducer', () => {
it( 'should handle SET_ORDER_NOTES', () => {
const expectedState = {
...defaultState,
status: STATUS.IDLE,
orderNotes: 'test',
};

Expand All @@ -221,7 +217,6 @@ describe.only( 'Checkout Store Reducer', () => {
};
const expectedState = {
...defaultState,
status: STATUS.IDLE,
extensionData: mockExtensionData,
};

Expand Down
19 changes: 18 additions & 1 deletion assets/js/data/payment/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const __internalEmitPaymentProcessingEvent: emitProcessingEventType = (
const { setBillingAddress, setShippingAddress } =
registry.dispatch( CART_STORE_KEY );

if ( successResponse ) {
if ( successResponse && ! errorResponse ) {
const { paymentMethodData } = successResponse?.meta || {};

if ( billingAddress && isBillingAddress( billingAddress ) ) {
Expand All @@ -135,6 +135,23 @@ export const __internalEmitPaymentProcessingEvent: emitProcessingEventType = (
}
dispatch.__internalSetPaymentMethodData( paymentMethodData );
dispatch.__internalSetPaymentReady();
} else if ( errorResponse && isFailResponse( errorResponse ) ) {
if ( errorResponse.message && errorResponse.message.length ) {
createErrorNotice( errorResponse.message, {
id: 'wc-payment-error',
isDismissible: false,
context:
errorResponse?.messageContext ||
noticeContexts.PAYMENTS,
} );
}

const { paymentMethodData } = errorResponse?.meta || {};
if ( billingAddress && isBillingAddress( billingAddress ) ) {
setBillingAddress( billingAddress );
}
dispatch.__internalSetPaymentError();
dispatch.__internalSetPaymentMethodData( paymentMethodData );
} else if ( errorResponse ) {
if ( errorResponse.message && errorResponse.message.length ) {
createErrorNotice( errorResponse.message, {
Expand Down

0 comments on commit 1dded9e

Please sign in to comment.