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-02-05 23:41:26 +00:00
|
|
|
import { PayPal, PAYPAL_PLUGIN } from '../tasks/payments/paypal';
|
2020-12-16 02:04:56 +00:00
|
|
|
import { getPaymentMethods } from '../tasks/payments/methods';
|
2021-02-16 21:08:35 +00:00
|
|
|
import { setMethodEnabledOption } from '../../task-list/tasks/payments';
|
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 );
|
|
|
|
} );
|
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
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|