Skip to content

Commit

Permalink
fix(applepay): interface changes and error message changes (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimhadri authored and GitHub Enterprise committed Oct 17, 2022
1 parent bd0e8a5 commit 02fa580
Show file tree
Hide file tree
Showing 7 changed files with 344 additions and 67 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"flow": "flow",
"flow:build": "flow gen-flow-files ./src/index.js --out-dir ./dist/module",
"test:unit": "jest src/ --collectCoverage --collectCoverageFrom='src/' --testPathIgnorePatterns=/fixtures/ --no-cache --runInBand",
"lint": "eslint --fix src/ test/ *.js",
"lint": "eslint --fix src/*.js",
"test": "npm run lint && npm run flow && npm run test:unit",
"karma": "cross-env NODE_ENV=test babel-node $(npm bin)/karma start",
"babel": "babel src/ --out-dir dist/module",
Expand All @@ -21,6 +21,7 @@
"jest": {
"coverageDirectory": "./coverage/",
"restoreMocks": true,
"testEnvironment": "jsdom",
"transformIgnorePatterns": [
"node_modules/(?!(@paypal|@krakenjs|get-browser-fingerprint))"
],
Expand Down Expand Up @@ -93,7 +94,9 @@
"btoa": "^1.2.1",
"flow-bin": "0.155.0",
"husky": "^7.0.4",
"isomorphic-fetch": "^3.0.0",
"jest": "^29.0.3",
"jest-environment-jsdom": "^29.2.0",
"jest-fetch-mock": "^3.0.3",
"mocha": "^4",
"standard-version": "^9.3.2"
Expand Down
56 changes: 39 additions & 17 deletions src/__tests__/applepay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import atob from 'atob';

import { Applepay } from '../applepay';


global.fetch = fetch;
global.btoa = btoa;
global.atob = atob;

jest.mock('@paypal/sdk-client/src', () => ({
getClientID: () => 'AdVrVyh_UduEct9CWFHsaHRXKVxbnCDleEJdVOZdb52qSjrWkKDNd6E1CNvd5BvNrGSsXzgQ238dGgZ4',
getMerchantID: () => [ '2V9L63AM2BYKC' ],
getClientID: () => 'AfALq_mQ3SUUltuavn8MnEaXPCPFRl4aOZDTcDTo1I4FsJGN3TPFZ1THvcT39wAF3S250a5oqCUbpJHH',
getMerchantID: () => [ 'HZZ2RQHJM4CE6' ],
getPayPalAPIDomain: () => 'https://www.sandbox.paypal.com',
getBuyerCountry: () => 'US',
getLogger: () => ({
Expand All @@ -26,9 +27,26 @@ jest.mock('@paypal/sdk-client/src', () => ({
flush: () => ({})
})
})
})
}),
getSDKQueryParam: (param) => {
if (param === 'currency') {
return 'USD';
}

return '';
}
}));

jest.mock('.././util', () => {
const originalModule = jest.requireActual('.././util');

return {
...originalModule,
getMerchantDomain: () => 'sandbox-applepay-paypal-js-sdk.herokuapp.com',
getPayPalHost: () => 'msmaster.qa.paypal.com'
};
});

describe('applepay', () => {

describe('Order', () => {
Expand All @@ -44,7 +62,7 @@ describe('applepay', () => {
value: '1.00'
},
payee: {
merchant_id: '2V9L63AM2BYKC'
merchant_id: 'HZZ2RQHJM4CE6'
}
}
]
Expand All @@ -61,15 +79,19 @@ describe('applepay', () => {
describe('Config', () => {
it('GetAppelPayConfig', async () => {
const applepay = Applepay();

expect(await applepay.config()).toEqual({
merchantCountry: 'US',
const config = await applepay.config();
expect(config).toEqual({
merchantCountry: 'US',
countryCode: 'US',
currencyCode: 'USD',
supportedNetworks: [
'masterCard',
'discover',
'visa',
'amex'
]
],
isEligible: true,
merchantCapabilities: [ 'supports3DS', 'supportsCredit', 'supportsDebit' ]
});
});
});
Expand All @@ -84,13 +106,14 @@ describe('applepay', () => {
}
};

try {
await applepay.validateMerchant({
validationUrl: 'https://apple-pay-gateway-cert.apple.com/paymentservices/startSession'
});
} catch (err) {
expect(err.message.includes('NOT_ENABLED_FOR_APPLE_PAY')).toBe(true);
}

const res = await applepay.validateMerchant({
validationUrl: 'https://apple-pay-gateway-cert.apple.com/paymentservices/startSession'
});

expect(res.name).toBe('ERROR_VALIDATING_MERCHANT');
expect(res.message.includes('NOT_ENABLED_FOR_APPLE_PAY')).toBe(true);


});

Expand All @@ -101,7 +124,7 @@ describe('applepay', () => {

global.window = {
location: {
href: 'sandbox-applepay-paypal-js-sdk.herokuapp.com'
href: 'https://sandbox-applepay-paypal-js-sdk.herokuapp.com'
}
};

Expand All @@ -117,4 +140,3 @@ describe('applepay', () => {
});

});

148 changes: 148 additions & 0 deletions src/__tests__/util.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/* @flow */


import { getMerchantDomain, getCurrency, getPayPalHost, getCreateOrderPayLoad, mapGetConfigResponse } from '../util';


global.window = Object.create(window);

const url = 'http://checkout.com';
Object.defineProperty(window, 'location', {
value: {
origin: url,
search: '?customDomain=\'testenv.qa.paypal.com\''
}
});

jest.mock('@paypal/sdk-client/src', () => ({
getPayPalAPIDomain: () => 'https://paypal.com',
getMerchantID: () => 'HZZ2RQHJM4CE6',
getBuyerCountry: () => 'US',
getSDKQueryParam: (param) => {
if (param === 'currency') {
return 'USD';
}

return '';
}
}));

describe('util', () => {
describe('should return merchant domain', () => {
it('validate getMerchantDomain', () => {
const domain = getMerchantDomain();
expect(domain).toBe('checkout.com');
});
});

describe('getCurrency', () => {
it('Should return USD by default', () => {
expect(getCurrency()).toBe('USD');
});
});

describe('getPayPalHost', () => {
it('should return \'paypal.com\'', () => {
expect(getPayPalHost()).toBe('paypal.com');
});
});

describe('getCreateOrderPayLoad', () => {
it('should create order with capture Intent and default payee Information', () => {
const requestPayLoad = {
purchase_units: [
{
amount: {
currency_code: 'USD',
value: '0.99'
}
}
]
};
expect(getCreateOrderPayLoad(requestPayLoad)).toStrictEqual({
intent: 'CAPTURE',
purchase_units: [
{
amount: {
currency_code: 'USD',
value: '0.99'
},
payee: {
merchant_id: 'HZZ2RQHJM4CE6'
}
}
],
payer: undefined,
application_context: undefined
});
});

it('should create order with passed in information', () => {
const requestPayLoad = {
intent: 'AUTHORIZE',
purchase_units: [
{
amount: {
currency_code: 'USD',
value: '0.99'
}
}
]
};
expect(getCreateOrderPayLoad(requestPayLoad)).toStrictEqual({
intent: 'AUTHORIZE',
purchase_units: [
{
amount: {
currency_code: 'USD',
value: '0.99'
},
payee: {
merchant_id: 'HZZ2RQHJM4CE6'
}
}
],
payer: undefined,
application_context: undefined
});
});
});

describe('mapGetConfigResponse', () => {
it('should return config data mapped as per client api spec', () => {
const requestPayLoad = {
'merchantCountry': 'US',
'supportedNetworks': [
'masterCard',
'discover',
'visa',
'amex'
],
'isEligible': true,
'merchantCapabilities': [
'supports3DS',
'supportsCredit',
'supportsDebit'
]
};

expect(mapGetConfigResponse(requestPayLoad)).toStrictEqual({
'merchantCountry': 'US',
'countryCode': 'US',
'currencyCode': 'USD',
'supportedNetworks': [
'masterCard',
'discover',
'visa',
'amex'
],
'isEligible': true,
'merchantCapabilities': [
'supports3DS',
'supportsCredit',
'supportsDebit'
]
});
});
});
});

0 comments on commit 02fa580

Please sign in to comment.