Skip to content

Commit

Permalink
Fix removal of express payment method from state (#44633)
Browse files Browse the repository at this point in the history
* Fix removal of express payment method from state

- Correct the logic for removing an express payment method from the availableExpressPaymentMethods state object.
- Previously, the deletion targeted the incorrect object, leading to incorrect change in state. Now, the correct entry is removed using destructuring and rest parameters, ensuring the express payment method is properly deleted.

* Revert "Fix removal of express payment method from state"

This reverts commit 8e24553.

* Fix typo error in the reducer

* Add unit to make sure correct express payment method is removed

* Add changefile(s) from automation for the following project(s): woocommerce-blocks

* Remove payment method descriptions from express and fix changelog

---------

Co-authored-by: github-actions <github-actions@github.com>
  • Loading branch information
tarunvijwani and github-actions committed Feb 16, 2024
1 parent ea50305 commit 7528a7d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const reducer: Reducer< PaymentState > = (

case ACTION_TYPES.REMOVE_AVAILABLE_EXPRESS_PAYMENT_METHOD:
const previousAvailableExpressPaymentMethods = {
...state.availablePaymentMethods,
...state.availableExpressPaymentMethods,
};
delete previousAvailableExpressPaymentMethods[ action.name ];
newState = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ describe( 'paymentMethodDataReducer', () => {
isSuccessful: false,
},
availablePaymentMethods: {},
availableExpressPaymentMethods: [ 'my-new-method' ],
availableExpressPaymentMethods: {
'my-new-method': {
name: 'My New Method',
},
},
paymentMethodData: {},
paymentMethodsInitialized: false,
expressPaymentMethodsInitialized: false,
Expand Down Expand Up @@ -187,6 +191,69 @@ describe( 'paymentMethodDataReducer', () => {
incompatiblePaymentMethods: {},
} );
} );
it( 'removes the correct express payment method', () => {
const stateWithRegisteredMethod = deepFreeze( {
currentStatus: {
isPristine: true,
isStarted: false,
isProcessing: false,
isFinished: false,
hasError: false,
hasFailed: false,
isSuccessful: false,
},
availablePaymentMethods: {},
availableExpressPaymentMethods: {
'my-new-method': {
name: 'My New Method',
},
'my-other-method': {
name: 'My Other Method',
},
},
paymentMethodData: {},
paymentMethodsInitialized: false,
expressPaymentMethodsInitialized: false,
shouldSavePaymentMethod: false,
errorMessage: '',
activePaymentMethod: '',
activeSavedToken: '',
incompatiblePaymentMethods: {},
} );
const nextState = reducer( stateWithRegisteredMethod, {
type: ACTION_TYPES.REMOVE_AVAILABLE_EXPRESS_PAYMENT_METHOD,
name: 'my-new-method',
} );
expect( nextState.availableExpressPaymentMethods ).not.toHaveProperty(
'my-new-method'
);

expect( nextState ).toEqual( {
currentStatus: {
isPristine: true,
isStarted: false,
isProcessing: false,
isFinished: false,
hasError: false,
hasFailed: false,
isSuccessful: false,
},
availablePaymentMethods: {},
availableExpressPaymentMethods: {
'my-other-method': {
name: 'My Other Method',
},
},
paymentMethodData: {},
paymentMethodsInitialized: false,
expressPaymentMethodsInitialized: false,
shouldSavePaymentMethod: false,
errorMessage: '',
activePaymentMethod: '',
activeSavedToken: '',
incompatiblePaymentMethods: {},
} );
} );

it( 'should handle SET_PAYMENT_RESULT', () => {
const mockResponse = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Fixed a bug where express payment methods could not be removed from the wc/store/payment data store.

0 comments on commit 7528a7d

Please sign in to comment.