2020-07-15 12:10:21 +00:00
|
|
|
/**
|
2020-08-13 02:05:22 +00:00
|
|
|
* External dependencies
|
2020-07-15 12:10:21 +00:00
|
|
|
*/
|
2021-02-05 23:41:26 +00:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2020-07-15 12:10:21 +00:00
|
|
|
import '@testing-library/jest-dom/extend-expect';
|
|
|
|
import apiFetch from '@wordpress/api-fetch';
|
|
|
|
|
|
|
|
/**
|
2020-08-13 02:05:22 +00:00
|
|
|
* Internal dependencies
|
2020-07-15 12:10:21 +00:00
|
|
|
*/
|
2021-04-14 19:26:50 +00:00
|
|
|
import { PayPal, PAYPAL_PLUGIN } from '../tasks/payments/methods/paypal';
|
2020-12-16 02:04:56 +00:00
|
|
|
import { getPaymentMethods } from '../tasks/payments/methods';
|
2021-04-27 15:14:42 +00:00
|
|
|
import { setMethodEnabledOption } from '../../task-list/tasks/payments/LocalPayments';
|
2021-03-18 20:30:17 +00:00
|
|
|
import { GenericPaymentStep } from '../tasks/payments/generic-payment-step';
|
2020-07-15 12:10:21 +00:00
|
|
|
|
2020-08-13 02:05:22 +00:00
|
|
|
jest.mock( '@wordpress/api-fetch' );
|
|
|
|
|
2020-07-15 12:10:21 +00:00
|
|
|
describe( 'TaskList > Payments', () => {
|
2021-02-16 21:08:35 +00:00
|
|
|
describe( 'Payments', () => {
|
|
|
|
const optionName = 'woocommerce_mollie_payments_settings';
|
|
|
|
|
|
|
|
it( 'does not update an option if the value is the same as the current one', async () => {
|
|
|
|
const mockProps = {
|
|
|
|
clearTaskStatusCache: jest.fn(),
|
|
|
|
updateOptions: jest.fn(),
|
|
|
|
options: {
|
|
|
|
woocommerce_klarna_payments_settings: false,
|
|
|
|
woocommerce_mollie_payments_settings: { enabled: 'yes' },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
await setMethodEnabledOption( optionName, 'yes', mockProps );
|
|
|
|
expect( mockProps.updateOptions ).not.toHaveBeenCalled();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'does update an option if the value is different to the current one', async () => {
|
|
|
|
const mockProps = {
|
|
|
|
clearTaskStatusCache: jest.fn(),
|
|
|
|
updateOptions: jest.fn(),
|
|
|
|
options: {
|
|
|
|
woocommerce_klarna_payments_settings: false,
|
|
|
|
woocommerce_mollie_payments_settings: { enabled: 'no' },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
await setMethodEnabledOption( optionName, 'yes', mockProps );
|
|
|
|
|
|
|
|
expect( mockProps.updateOptions ).toHaveBeenCalledWith( {
|
|
|
|
woocommerce_mollie_payments_settings: { enabled: 'yes' },
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2020-12-16 02:04:56 +00:00
|
|
|
describe( 'Methods', () => {
|
|
|
|
const params = {
|
|
|
|
activePlugins: [],
|
|
|
|
countryCode: 'SE',
|
|
|
|
onboardingStatus: {},
|
|
|
|
options: [],
|
2021-02-05 03:41:55 +00:00
|
|
|
profileItems: { industry: [] },
|
2020-12-16 02:04:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
it( 'includes Klarna Checkout for SE, NO, and FI', () => {
|
|
|
|
[ 'SE', 'NO', 'FI' ].forEach( ( countryCode ) => {
|
|
|
|
params.countryCode = countryCode;
|
|
|
|
const methods = getPaymentMethods( params );
|
|
|
|
expect(
|
|
|
|
methods.some(
|
|
|
|
( method ) => method.key === 'klarna_checkout'
|
|
|
|
)
|
|
|
|
).toBe( true );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'includes Klarna Payment for EU countries', () => {
|
|
|
|
const supportedCountryCodes = [
|
|
|
|
'DK',
|
|
|
|
'DE',
|
|
|
|
'AT',
|
|
|
|
'NL',
|
|
|
|
'CH',
|
|
|
|
'BE',
|
|
|
|
'SP',
|
|
|
|
'PL',
|
|
|
|
'FR',
|
|
|
|
'IT',
|
2021-02-05 03:41:55 +00:00
|
|
|
'GB',
|
2020-12-16 02:04:56 +00:00
|
|
|
];
|
|
|
|
supportedCountryCodes.forEach( ( countryCode ) => {
|
|
|
|
params.countryCode = countryCode;
|
|
|
|
const methods = getPaymentMethods( params );
|
|
|
|
expect(
|
|
|
|
methods.some( ( e ) => e.key === 'klarna_payments' )
|
|
|
|
).toBe( true );
|
|
|
|
} );
|
|
|
|
} );
|
2021-02-05 03:41:55 +00:00
|
|
|
|
|
|
|
describe( 'Mollie', () => {
|
|
|
|
it( 'Detects the plugin is enabled based on the options passed', () => {
|
|
|
|
const mollieParams = {
|
|
|
|
...params,
|
|
|
|
options: {
|
|
|
|
woocommerce_mollie_payments_settings: {
|
|
|
|
enabled: 'yes',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const mollieMethod = getPaymentMethods( mollieParams ).find(
|
|
|
|
( method ) => method.key === 'mollie'
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( mollieMethod.isEnabled ).toBe( true );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'is enabled for supported countries', () => {
|
|
|
|
[
|
|
|
|
'FR',
|
|
|
|
'DE',
|
|
|
|
'GB',
|
|
|
|
'AT',
|
|
|
|
'CH',
|
|
|
|
'ES',
|
|
|
|
'IT',
|
|
|
|
'PL',
|
|
|
|
'FI',
|
|
|
|
'NL',
|
|
|
|
'BE',
|
|
|
|
].forEach( ( countryCode ) => {
|
|
|
|
const methods = getPaymentMethods( {
|
|
|
|
...params,
|
|
|
|
countryCode,
|
|
|
|
} );
|
|
|
|
|
|
|
|
expect(
|
|
|
|
methods.filter( ( method ) => method.key === 'mollie' )
|
|
|
|
.length
|
|
|
|
).toBe( 1 );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'is marked as `isConfigured` if the plugin is active', () => {
|
|
|
|
expect(
|
|
|
|
getPaymentMethods( {
|
|
|
|
...params,
|
|
|
|
activePlugins: [ 'mollie-payments-for-woocommerce' ],
|
|
|
|
} ).find( ( method ) => method.key === 'mollie' ).isConfigured
|
|
|
|
).toBe( true );
|
|
|
|
} );
|
2021-03-22 18:57:43 +00:00
|
|
|
|
|
|
|
describe( 'MercadoPago', () => {
|
|
|
|
it( 'Is enabled for supported countries', () => {
|
|
|
|
[ 'AR', 'BR', 'CL', 'CO', 'MX', 'PE', 'UY' ].forEach(
|
|
|
|
( countryCode ) => {
|
|
|
|
params.countryCode = countryCode;
|
|
|
|
const methods = getPaymentMethods( params );
|
|
|
|
expect(
|
|
|
|
methods.some(
|
|
|
|
( method ) => method.key === 'mercadopago'
|
|
|
|
)
|
|
|
|
).toBe( true );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'Detects whether the plugin is enabled based on the received options', () => {
|
|
|
|
const mercadoPagoParams = {
|
|
|
|
...params,
|
2021-03-25 21:01:37 +00:00
|
|
|
options: {
|
|
|
|
...params.options,
|
|
|
|
'woocommerce_woo-mercado-pago-basic_settings': {
|
|
|
|
enabled: 'yes',
|
|
|
|
},
|
2021-03-22 18:57:43 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const mercadoPagoMethod = getPaymentMethods(
|
|
|
|
mercadoPagoParams
|
|
|
|
).find( ( method ) => method.key === 'mercadopago' );
|
|
|
|
|
|
|
|
expect( mercadoPagoMethod.isEnabled ).toBe( true );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'If the plugin is active `mercadopago` is marked as `isConfigured`', () => {
|
|
|
|
expect(
|
|
|
|
getPaymentMethods( {
|
|
|
|
...params,
|
|
|
|
activePlugins: [ 'woocommerce-mercadopago' ],
|
|
|
|
} ).find( ( method ) => method.key === 'mercadopago' )
|
|
|
|
.isConfigured
|
|
|
|
).toBe( true );
|
|
|
|
} );
|
2020-12-16 02:04:56 +00:00
|
|
|
} );
|
|
|
|
|
2020-07-15 12:10:21 +00:00
|
|
|
describe( 'PayPal', () => {
|
|
|
|
afterEach( () => jest.clearAllMocks() );
|
|
|
|
|
|
|
|
const mockInstallStep = {
|
|
|
|
isComplete: true,
|
|
|
|
key: 'install',
|
|
|
|
label: 'Install',
|
|
|
|
};
|
|
|
|
|
2021-02-05 23:41:26 +00:00
|
|
|
it( 'shows API credential inputs when "create account" opted out and OAuth fetch fails', async () => {
|
|
|
|
apiFetch.mockResolvedValue( false );
|
2020-07-15 12:10:21 +00:00
|
|
|
|
|
|
|
render(
|
|
|
|
<PayPal
|
|
|
|
activePlugins={ [
|
|
|
|
'jetpack',
|
2021-02-05 23:41:26 +00:00
|
|
|
PAYPAL_PLUGIN,
|
2020-07-15 12:10:21 +00:00
|
|
|
'woocommerce-services',
|
|
|
|
] }
|
2021-02-05 23:41:26 +00:00
|
|
|
isRequestingOptions={ false }
|
|
|
|
options={ {} }
|
2020-07-15 12:10:21 +00:00
|
|
|
installStep={ mockInstallStep }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2021-02-05 23:41:26 +00:00
|
|
|
// Since the oauth response failed, we should have the API credentials form.
|
2020-07-28 02:32:58 +00:00
|
|
|
expect(
|
2021-02-05 23:41:26 +00:00
|
|
|
await screen.findByText( 'Proceed', { selector: 'button' } )
|
2020-07-28 02:32:58 +00:00
|
|
|
).toBeDefined();
|
|
|
|
expect(
|
|
|
|
screen.queryByLabelText( 'Email address', {
|
|
|
|
selector: 'input',
|
|
|
|
} )
|
|
|
|
).toBeDefined();
|
|
|
|
expect(
|
2021-02-05 23:41:26 +00:00
|
|
|
screen.getByLabelText( 'Merchant Id', { selector: 'input' } )
|
2020-07-28 02:32:58 +00:00
|
|
|
).toBeDefined();
|
|
|
|
expect(
|
2021-02-05 23:41:26 +00:00
|
|
|
screen.getByLabelText( 'Client Id', { selector: 'input' } )
|
2020-07-28 02:32:58 +00:00
|
|
|
).toBeDefined();
|
|
|
|
expect(
|
2021-02-05 23:41:26 +00:00
|
|
|
screen.getByLabelText( 'Secret Key', { selector: 'input' } )
|
2020-07-28 02:32:58 +00:00
|
|
|
).toBeDefined();
|
2020-07-15 12:10:21 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'shows OAuth connect button', async () => {
|
2021-02-05 23:41:26 +00:00
|
|
|
global.ppcp_onboarding = {
|
|
|
|
reload: () => {},
|
|
|
|
};
|
2020-07-15 12:10:21 +00:00
|
|
|
const mockConnectUrl = 'https://connect.woocommerce.test/paypal';
|
|
|
|
apiFetch.mockResolvedValue( {
|
2021-02-05 23:41:26 +00:00
|
|
|
signupLink: mockConnectUrl,
|
2020-07-15 12:10:21 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
render(
|
|
|
|
<PayPal
|
2021-02-05 23:41:26 +00:00
|
|
|
activePlugins={ [ PAYPAL_PLUGIN ] }
|
2020-07-15 12:10:21 +00:00
|
|
|
installStep={ mockInstallStep }
|
2021-02-05 23:41:26 +00:00
|
|
|
isRequestingOptions={ false }
|
|
|
|
options={ {} }
|
2020-07-15 12:10:21 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
// Since the oauth response was mocked, we should have a "connect" button.
|
2020-07-28 02:32:58 +00:00
|
|
|
const oauthButton = await screen.findByText( 'Connect', {
|
|
|
|
selector: 'a',
|
|
|
|
} );
|
2020-07-15 12:10:21 +00:00
|
|
|
expect( oauthButton ).toBeDefined();
|
|
|
|
expect( oauthButton.href ).toEqual( mockConnectUrl );
|
2021-02-05 23:41:26 +00:00
|
|
|
expect( oauthButton.dataset.paypalButton ).toEqual( 'true' );
|
|
|
|
expect( oauthButton.dataset.paypalOnboardButton ).toEqual( 'true' );
|
2020-07-15 12:10:21 +00:00
|
|
|
} );
|
|
|
|
} );
|
2021-03-18 20:30:17 +00:00
|
|
|
|
|
|
|
describe( 'Payfast', () => {
|
|
|
|
const params = {
|
|
|
|
activePlugins: [],
|
|
|
|
countryCode: 'ZA',
|
|
|
|
onboardingStatus: {},
|
|
|
|
options: [],
|
|
|
|
profileItems: { industry: [] },
|
|
|
|
};
|
|
|
|
const mockInstallStep = {
|
|
|
|
isComplete: true,
|
|
|
|
key: 'install',
|
|
|
|
label: 'Install',
|
|
|
|
};
|
|
|
|
it( 'Detects the plugin is enabled based on the options passed', () => {
|
|
|
|
const payfastParams = {
|
|
|
|
...params,
|
|
|
|
options: {
|
|
|
|
woocommerce_payfast_settings: {
|
|
|
|
enabled: 'yes',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const payfastMethod = getPaymentMethods( payfastParams ).find(
|
|
|
|
( method ) => method.key === 'payfast'
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( payfastMethod.isEnabled ).toBe( true );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'is enabled for supported countries', () => {
|
|
|
|
[ 'ZA' ].forEach( ( countryCode ) => {
|
|
|
|
const methods = getPaymentMethods( {
|
|
|
|
...params,
|
|
|
|
countryCode,
|
|
|
|
} );
|
|
|
|
|
|
|
|
expect(
|
|
|
|
methods.filter( ( method ) => method.key === 'payfast' )
|
|
|
|
.length
|
|
|
|
).toBe( 1 );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'shows API credential inputs', async () => {
|
|
|
|
const payfastMethod = getPaymentMethods( params ).find(
|
|
|
|
( method ) => method.key === 'payfast'
|
|
|
|
);
|
|
|
|
|
|
|
|
render(
|
|
|
|
<GenericPaymentStep
|
|
|
|
isRequestingOptions={ false }
|
|
|
|
options={ {} }
|
|
|
|
installStep={ mockInstallStep }
|
|
|
|
methodConfig={ payfastMethod }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
// Since the oauth response failed, we should have the API credentials form.
|
|
|
|
expect(
|
|
|
|
await screen.findByText( 'Proceed', { selector: 'button' } )
|
|
|
|
).toBeDefined();
|
|
|
|
expect(
|
|
|
|
screen.getByLabelText( 'Merchant ID', { selector: 'input' } )
|
|
|
|
).toBeDefined();
|
|
|
|
expect(
|
|
|
|
screen.getByLabelText( 'Merchant Key', { selector: 'input' } )
|
|
|
|
).toBeDefined();
|
|
|
|
expect(
|
|
|
|
screen.getByLabelText( 'Passphrase', { selector: 'input' } )
|
|
|
|
).toBeDefined();
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
describe( 'Paystack', () => {
|
|
|
|
const params = {
|
|
|
|
activePlugins: [],
|
|
|
|
countryCode: 'ZA',
|
|
|
|
onboardingStatus: {},
|
|
|
|
options: [],
|
|
|
|
profileItems: { industry: [] },
|
|
|
|
};
|
|
|
|
const mockInstallStep = {
|
|
|
|
isComplete: true,
|
|
|
|
key: 'install',
|
|
|
|
label: 'Install',
|
|
|
|
};
|
|
|
|
it( 'Detects the plugin is enabled based on the enabled gateways', () => {
|
|
|
|
const paystackParams = {
|
|
|
|
...params,
|
|
|
|
onboardingStatus: {
|
|
|
|
enabledPaymentGateways: [ 'paystack' ],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const paystackMethod = getPaymentMethods( paystackParams ).find(
|
|
|
|
( method ) => method.key === 'paystack'
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( paystackMethod.isEnabled ).toBe( true );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'is enabled for supported countries', () => {
|
|
|
|
[ 'ZA', 'GH', 'NG' ].forEach( ( countryCode ) => {
|
|
|
|
const methods = getPaymentMethods( {
|
|
|
|
...params,
|
|
|
|
countryCode,
|
|
|
|
} );
|
|
|
|
|
|
|
|
expect(
|
|
|
|
methods.filter( ( method ) => method.key === 'paystack' )
|
|
|
|
.length
|
|
|
|
).toBe( 1 );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'shows API credential inputs', async () => {
|
|
|
|
const payfastMethod = getPaymentMethods( params ).find(
|
|
|
|
( method ) => method.key === 'paystack'
|
|
|
|
);
|
|
|
|
|
|
|
|
render(
|
|
|
|
<GenericPaymentStep
|
|
|
|
isRequestingOptions={ false }
|
|
|
|
options={ {} }
|
|
|
|
installStep={ mockInstallStep }
|
|
|
|
methodConfig={ payfastMethod }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
// Since the oauth response failed, we should have the API credentials form.
|
|
|
|
expect(
|
|
|
|
await screen.findByText( 'Proceed', { selector: 'button' } )
|
|
|
|
).toBeDefined();
|
|
|
|
expect(
|
|
|
|
screen.getByLabelText( 'Live Public Key', {
|
|
|
|
selector: 'input',
|
|
|
|
} )
|
|
|
|
).toBeDefined();
|
|
|
|
expect(
|
|
|
|
screen.getByLabelText( 'Live Secret Key', {
|
|
|
|
selector: 'input',
|
|
|
|
} )
|
|
|
|
).toBeDefined();
|
|
|
|
} );
|
|
|
|
} );
|
2020-07-15 12:10:21 +00:00
|
|
|
} );
|