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

paypal express unit tests #1121

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions jest/__mocks__/dw/order/BasketMgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export const getTotalGrossPrice = jest.fn(() => ({
isAvailable,
}));

export const getAdjustedMerchandizeTotalGrossPrice = jest.fn(() => ({
currencyCode: 'EUR',
isAvailable,
}));

export const getCreditCardToken = jest.fn(() => 'mockedCreditCardToken');
export const getPaymentMethod = jest.fn(() => 'mockedPaymentMethod');

Expand All @@ -47,8 +52,14 @@ export const setCreditCardToken = jest.fn();

export const toArray = jest.fn(() => [
{
custom: {},
paymentTransaction: { paymentProcessor: 'mocked_payment_processor' },
custom: { adyenPaymentMethod: '' },
paymentTransaction: {
paymentProcessor: 'mocked_payment_processor',
amount: {
value: 'mockedValue',
currencyCode: 'mockedValue',
},
},
setCreditCardNumber,
setCreditCardType,
setCreditCardExpirationMonth,
Expand All @@ -73,7 +84,6 @@ export const getDefaultShipment = jest.fn(() => ({
}));
export const getBillingAddress = jest.fn(() => 'mocked_billing_address');


function formatCustomerObject(shopperDetails) {
return {
addressBook: {
Expand Down Expand Up @@ -121,7 +131,9 @@ export const getCurrentBasket = jest.fn(() => ({
setCustomerEmail: jest.fn(),
getAllProductLineItems,
getTotalGrossPrice,
getAdjustedMerchandizeTotalGrossPrice,
getPaymentInstruments,
removeAllPaymentInstruments: jest.fn(),
removePaymentInstrument: jest.fn(),
custom: {
amazonExpressShopperDetails: JSON.stringify({
Expand All @@ -138,15 +150,15 @@ export const getCurrentBasket = jest.fn(() => ({
},
addressBook: {
preferredAddress: {
address1: 'address1',
address2: 'mocked address2',
phone: 'mocked phone',
postalCode: 'mocked postalCode',
countryCode: 'mocked CC',
city: 'mocked city',
lastName: 'mocked name',
firstName: 'mocked name',
stateCode: 'mocked state',
address1: 'address1',
address2: 'mocked address2',
phone: 'mocked phone',
postalCode: 'mocked postalCode',
countryCode: 'mocked CC',
city: 'mocked city',
lastName: 'mocked name',
firstName: 'mocked name',
stateCode: 'mocked state',
},
},
profile: {
Expand All @@ -158,7 +170,7 @@ export const getCurrentBasket = jest.fn(() => ({
}),
},
getUUID: jest.fn(),
createBillingAddress,
createBillingAddress: jest.fn(() => createBillingAddress),
createPaymentInstrument: jest.fn(() => toArray()[0]),
defaultShipment: getDefaultShipment(),
getDefaultShipment,
Expand Down
29 changes: 20 additions & 9 deletions jest/__mocks__/dw/order/OrderMgr.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const paymentInstrument = () => [
{
custom: {
adyenPaymentData: "{ \"paymentMethod\": { \"type\": \"mocked_type\" } }",
adyenPaymentData: '{ "paymentMethod": { "type": "mocked_type" } }',
adyenRedirectURL: 'https://some_mocked_url/signature',
adyenMD: 'mocked_adyen_MD',
adyenAction: 'mocked_adyen_action',
},
paymentTransaction: {
custom: {
Adyen_merchantSig: 'mocked_signature',
Adyen_authResult: "{ \"data\": \"mock\"}",
},
custom: {
Adyen_merchantSig: 'mocked_signature',
Adyen_authResult: '{ "data": "mock"}',
},
},
},
];
Expand All @@ -36,20 +36,31 @@ export const getPaymentInstruments = jest.fn(() => ({
0: toArray()[0],
}));



export const getOrder = jest.fn((statusValue="4"/* orderNo */) => ({
export const getOrder = jest.fn((statusValue = '4' /* orderNo */) => ({
getPaymentInstruments,
setPaymentStatus: jest.fn(),
setExportStatus: jest.fn(),
orderNo: 'mocked_orderNo',
orderToken: 'mocked_orderToken',
getUUID: jest.fn(),
custom: { Adyen_pspReference: 'mocked_pspRef' },
status: { value: statusValue}
status: { value: statusValue },
}));

export const failOrder = jest.fn((orderNo, bool) => ({
orderNo,
bool,
}));

export const createOrderNo = jest.fn(() => 'mocked_orderNo');

export const createOrder = jest.fn(() => ({
getPaymentInstruments,
setPaymentStatus: jest.fn(),
setExportStatus: jest.fn(),
orderNo: 'mocked_orderNo',
orderToken: 'mocked_orderToken',
getUUID: jest.fn(),
custom: { Adyen_pspReference: 'mocked_pspRef' },
status: { value: 'Created' },
}));
6 changes: 5 additions & 1 deletion jest/__mocks__/dw/order/ShippingLocation.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export const ShippingLocation = jest.fn();
function ShippingLocation() {
return jest.fn();
}

module.exports = ShippingLocation;
44 changes: 39 additions & 5 deletions jest/__mocks__/dw/order/ShippingMgr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
const Money = require('../value/Money');

export const getShipmentShippingModel = jest.fn((shipment) => ({
getApplicableShippingMethods: jest.fn(() => ({
})),
}));

const shippingMethods = [
{
description: 'Order received within 7-10 business days',
displayName: 'Ground',
ID: '001',
custom: {
estimatedArrivalTime: '7-10 Business Days',
},
getTaxClassID: jest.fn(),
},
{
description: 'Order received in 2 business days',
displayName: '2-Day Express',
ID: '002',
shippingCost: '$0.00',
custom: {
estimatedArrivalTime: '2 Business Days',
},
getTaxClassID: jest.fn(),
},
];
const shippingCost = Money();
const shipmentShippingModel = {
getApplicableShippingMethods: jest.fn(() => ({
toArray: jest.fn(() => shippingMethods),
})),
getShippingCost: jest.fn(() => ({
getAmount: jest.fn(() => shippingCost),
})),
};
const productShippingModel = {
getApplicableShippingMethods: jest.fn(() => ({})),
getShippingCost: jest.fn(() => ({
getAmount: jest.fn(() => shippingCost),
})),
};
export const getShipmentShippingModel = jest.fn(() => shipmentShippingModel);
export const getProductShippingModel = jest.fn(() => productShippingModel);
35 changes: 30 additions & 5 deletions jest/__mocks__/dw/value/Money.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
export class Money {
constructor() {
return {value: 10, currency: 'TEST'};
}
}
function Money(isAvailable) {
return {
available: isAvailable,
value: '10.99',
currency: 'USD',
getDecimalValue() {
return '10.99';
},
getValue() {
return '10.99';
},
getCurrencyCode() {
return 'USD';
},
subtract() {
return new Money(isAvailable);
},
multiply() {
return new Money(isAvailable);
},
add() {
return new Money(isAvailable);
},
addRate() {
return new Money(isAvailable);
},
};
}

module.exports = Money;
34 changes: 23 additions & 11 deletions jest/sfccCartridgeMocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ jest.mock('*/cartridge/models/cart', () => jest.fn(), { virtual: true });

jest.mock('*/cartridge/models/account', () => jest.fn(), { virtual: true });

jest.mock('*/cartridge/models/shipping/shippingMethod', () => jest.fn(), { virtual: true });
jest.mock('*/cartridge/models/shipping/shippingMethod', () => jest.fn(), {
virtual: true,
});

jest.mock(
'*/cartridge/scripts/checkout/shippingHelpers',
Expand All @@ -28,6 +30,9 @@ jest.mock(
jest.mock(
'*/cartridge/adyen/scripts/payments/adyenCheckout',
() => ({
doPaymentsCall: jest.fn(() => ({
pspReference: 'mocked_pspReference',
})),
doPaymentsDetailsCall: jest.fn((payload) => {
let resultCode;
if (payload.paymentData) {
Expand All @@ -36,7 +41,7 @@ jest.mock(
resultCode =
payload.details.MD === 'mocked_md' ? 'Authorised' : 'Not_Authorised';
}
return { resultCode };
return { resultCode, paymentMethod: { type: 'mocked_type' } };
}),
createPaymentRequest: jest.fn(() => ({
resultCode: 'Authorised',
Expand Down Expand Up @@ -71,15 +76,6 @@ jest.mock(
{ virtual: true },
);

jest.mock(
'*/cartridge/adyen/scripts/payments/adyenGetPaymentMethods',
() => ({
getMethods: jest.fn(() => ({
paymentMethods: [{ type: 'visa' }],
})),
}),
{ virtual: true },
);
jest.mock(
'*/cartridge/adyen/scripts/payments/adyenTerminalApi',
() => ({
Expand Down Expand Up @@ -453,6 +449,22 @@ jest.mock(
},
],
})),
setBillingAndShippingAddress: jest.fn(),
}),
{ virtual: true },
);

jest.mock(
'*/cartridge/client/default/js/adyen_checkout/helpers',
() => ({
setOrderFormData: jest.fn(),
assignPaymentMethodValue: jest.fn(),
paymentFromComponent: jest.fn(),
resetPaymentMethod: jest.fn(),
displaySelectedMethod: jest.fn(),
showValidation: jest.fn(),
createShowConfirmationForm: jest.fn(),
getInstallmentValues: jest.fn(),
}),
{ virtual: true },
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`paypal express getPaypalButtonConfig should return config when review page is enabled 1`] = `
{
"configuration": {},
"isExpress": true,
"onAdditionalDetails": [Function],
"onError": [Function],
"onShippingAddressChange": [Function],
"onShippingOptionsChange": [Function],
"onShopperDetails": [Function],
"onSubmit": [Function],
"returnUrl": "test_returnUrl",
"showPayButton": true,
"userAction": "continue",
}
`;

exports[`paypal express getPaypalButtonConfig should return config when review page is not enabled 1`] = `
{
"configuration": {},
"isExpress": true,
"onAdditionalDetails": [Function],
"onError": [Function],
"onShippingAddressChange": [Function],
"onShippingOptionsChange": [Function],
"onShopperDetails": [Function],
"onSubmit": [Function],
"returnUrl": "test_returnUrl",
"showPayButton": true,
}
`;
Loading
Loading