Skip to content

Commit 5691b81

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

File tree

1 file changed

+86
-1
lines changed

1 file changed

+86
-1
lines changed

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

Lines changed: 86 additions & 1 deletion
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,17 +374,46 @@ 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

@@ -486,6 +518,30 @@ describe('PayPalCommerceButtonStrategy', () => {
486518
defaultButtonContainerId,
487519
);
488520
});
521+
522+
it('initializes PayPal button to render with appSwitch flag', async () => {
523+
jest.spyOn(
524+
paymentIntegrationService.getState(),
525+
'getStoreConfigOrThrow',
526+
).mockReturnValue({
527+
...storeConfig,
528+
checkoutSettings: {
529+
...storeConfig.checkoutSettings,
530+
features: {
531+
'PAYPAL-5716.app_switch_functionality': true,
532+
},
533+
},
534+
});
535+
await strategy.initialize(initializationOptions);
536+
537+
expect(paypalSdk.Buttons).toHaveBeenCalledWith({
538+
appSwitchWhenAvailable: true,
539+
fundingSource: paypalSdk.FUNDING.PAYPAL,
540+
style: paypalCommerceOptions.style,
541+
createOrder: expect.any(Function),
542+
onApprove: expect.any(Function),
543+
});
544+
});
489545
});
490546

491547
describe('#createOrder', () => {
@@ -512,6 +568,35 @@ describe('PayPalCommerceButtonStrategy', () => {
512568
'paypalcommerce',
513569
);
514570
});
571+
572+
it('creates paypal order with user agent', async () => {
573+
Object.defineProperty(window.navigator, 'userAgent', {
574+
value: 'Mozilla',
575+
configurable: true,
576+
});
577+
jest.spyOn(
578+
paymentIntegrationService.getState(),
579+
'getStoreConfigOrThrow',
580+
).mockReturnValue({
581+
...storeConfig,
582+
checkoutSettings: {
583+
...storeConfig.checkoutSettings,
584+
features: {
585+
'PAYPAL-5716.app_switch_functionality': true,
586+
},
587+
},
588+
});
589+
await strategy.initialize(initializationOptions);
590+
591+
eventEmitter.emit('createOrder');
592+
593+
await new Promise((resolve) => process.nextTick(resolve));
594+
595+
expect(paypalCommerceIntegrationService.createOrder).toHaveBeenCalledWith(
596+
'paypalcommerce',
597+
{ userAgent: 'Mozilla' },
598+
);
599+
});
515600
});
516601

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

0 commit comments

Comments
 (0)