Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix removal of express payment method from state #44633

Merged
merged 7 commits into from
Feb 16, 2024
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.