Skip to content

Commit debd180

Browse files
feat(payment): PAYPAL-5717 Added AppSwitch to PPCP button strategy
1 parent 6f76c78 commit debd180

File tree

1 file changed

+85
-3
lines changed

1 file changed

+85
-3
lines changed

packages/paypal-commerce-integration/src/paypal-commerce/paypal-commerce-button-strategy.spec.ts

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ describe('PayPalCommerceButtonStrategy', () => {
103103
};
104104

105105
const storeConfig = getConfig().storeConfig;
106+
const resumeMock = jest.fn();
106107

107108
beforeEach(() => {
108109
buyNowCart = getBuyNowCart();
@@ -244,6 +245,8 @@ describe('PayPalCommerceButtonStrategy', () => {
244245
isEligible: jest.fn(() => true),
245246
render: jest.fn(),
246247
close: jest.fn(),
248+
hasReturned: jest.fn().mockReturnValue(true),
249+
resume: resumeMock,
247250
};
248251
},
249252
);
@@ -371,22 +374,50 @@ describe('PayPalCommerceButtonStrategy', () => {
371374

372375
describe('#renderButton', () => {
373376
it('initializes PayPal button to render (default flow)', async () => {
377+
jest.spyOn(
378+
paymentIntegrationService.getState(),
379+
'getStoreConfigOrThrow',
380+
).mockReturnValue({
381+
...storeConfig,
382+
checkoutSettings: {
383+
...storeConfig.checkoutSettings,
384+
features: {
385+
'PAYPAL-5716.app_switch_functionality': false,
386+
},
387+
},
388+
});
374389
await strategy.initialize(initializationOptions);
375390

376391
expect(paypalSdk.Buttons).toHaveBeenCalledWith({
377-
appSwitchWhenAvailable: true,
378392
fundingSource: paypalSdk.FUNDING.PAYPAL,
379393
style: paypalCommerceOptions.style,
380394
createOrder: expect.any(Function),
381395
onApprove: expect.any(Function),
382396
});
383397
});
384398

399+
it('calls PayPal button resume', async () => {
400+
jest.spyOn(
401+
paymentIntegrationService.getState(),
402+
'getStoreConfigOrThrow',
403+
).mockReturnValue({
404+
...storeConfig,
405+
checkoutSettings: {
406+
...storeConfig.checkoutSettings,
407+
features: {
408+
'PAYPAL-5716.app_switch_functionality': true,
409+
},
410+
},
411+
});
412+
await strategy.initialize(initializationOptions);
413+
414+
expect(resumeMock).toHaveBeenCalled();
415+
});
416+
385417
it('initializes PayPal button to render (buy now flow)', async () => {
386418
await strategy.initialize(buyNowInitializationOptions);
387419

388420
expect(paypalSdk.Buttons).toHaveBeenCalledWith({
389-
appSwitchWhenAvailable: true,
390421
fundingSource: paypalSdk.FUNDING.PAYPAL,
391422
style: paypalCommerceOptions.style,
392423
createOrder: expect.any(Function),
@@ -413,7 +444,6 @@ describe('PayPalCommerceButtonStrategy', () => {
413444
await strategy.initialize(initializationOptions);
414445

415446
expect(paypalSdk.Buttons).toHaveBeenCalledWith({
416-
appSwitchWhenAvailable: true,
417447
fundingSource: paypalSdk.FUNDING.PAYPAL,
418448
style: paypalCommerceOptions.style,
419449
createOrder: expect.any(Function),
@@ -486,6 +516,30 @@ describe('PayPalCommerceButtonStrategy', () => {
486516
defaultButtonContainerId,
487517
);
488518
});
519+
520+
it('initializes PayPal button to render with appSwitch flag', async () => {
521+
jest.spyOn(
522+
paymentIntegrationService.getState(),
523+
'getStoreConfigOrThrow',
524+
).mockReturnValue({
525+
...storeConfig,
526+
checkoutSettings: {
527+
...storeConfig.checkoutSettings,
528+
features: {
529+
'PAYPAL-5716.app_switch_functionality': true,
530+
},
531+
},
532+
});
533+
await strategy.initialize(initializationOptions);
534+
535+
expect(paypalSdk.Buttons).toHaveBeenCalledWith({
536+
appSwitchWhenAvailable: true,
537+
fundingSource: paypalSdk.FUNDING.PAYPAL,
538+
style: paypalCommerceOptions.style,
539+
createOrder: expect.any(Function),
540+
onApprove: expect.any(Function),
541+
});
542+
});
489543
});
490544

491545
describe('#createOrder', () => {
@@ -512,6 +566,34 @@ describe('PayPalCommerceButtonStrategy', () => {
512566
'paypalcommerce',
513567
);
514568
});
569+
570+
it('creates paypal order with user agent', async () => {
571+
jest.spyOn(
572+
paymentIntegrationService.getState(),
573+
'getStoreConfigOrThrow',
574+
).mockReturnValue({
575+
...storeConfig,
576+
checkoutSettings: {
577+
...storeConfig.checkoutSettings,
578+
features: {
579+
'PAYPAL-5716.app_switch_functionality': true,
580+
},
581+
},
582+
});
583+
await strategy.initialize(initializationOptions);
584+
585+
eventEmitter.emit('createOrder');
586+
587+
await new Promise((resolve) => process.nextTick(resolve));
588+
589+
expect(paypalCommerceIntegrationService.createOrder).toHaveBeenCalledWith(
590+
'paypalcommerce',
591+
{
592+
userAgent:
593+
'Mozilla/5.0 (darwin) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/16.7.0',
594+
},
595+
);
596+
});
515597
});
516598

517599
describe('#handleClick', () => {

0 commit comments

Comments
 (0)