@@ -103,6 +103,7 @@ describe('PayPalCommerceButtonStrategy', () => {
103
103
} ;
104
104
105
105
const storeConfig = getConfig ( ) . storeConfig ;
106
+ const resumeMock = jest . fn ( ) ;
106
107
107
108
beforeEach ( ( ) => {
108
109
buyNowCart = getBuyNowCart ( ) ;
@@ -244,6 +245,8 @@ describe('PayPalCommerceButtonStrategy', () => {
244
245
isEligible : jest . fn ( ( ) => true ) ,
245
246
render : jest . fn ( ) ,
246
247
close : jest . fn ( ) ,
248
+ hasReturned : jest . fn ( ) . mockReturnValue ( true ) ,
249
+ resume : resumeMock ,
247
250
} ;
248
251
} ,
249
252
) ;
@@ -371,17 +374,46 @@ describe('PayPalCommerceButtonStrategy', () => {
371
374
372
375
describe ( '#renderButton' , ( ) => {
373
376
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
+ } ) ;
374
389
await strategy . initialize ( initializationOptions ) ;
375
390
376
391
expect ( paypalSdk . Buttons ) . toHaveBeenCalledWith ( {
377
- appSwitchWhenAvailable : true ,
378
392
fundingSource : paypalSdk . FUNDING . PAYPAL ,
379
393
style : paypalCommerceOptions . style ,
380
394
createOrder : expect . any ( Function ) ,
381
395
onApprove : expect . any ( Function ) ,
382
396
} ) ;
383
397
} ) ;
384
398
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
+
385
417
it ( 'initializes PayPal button to render (buy now flow)' , async ( ) => {
386
418
await strategy . initialize ( buyNowInitializationOptions ) ;
387
419
@@ -413,7 +445,6 @@ describe('PayPalCommerceButtonStrategy', () => {
413
445
await strategy . initialize ( initializationOptions ) ;
414
446
415
447
expect ( paypalSdk . Buttons ) . toHaveBeenCalledWith ( {
416
- appSwitchWhenAvailable : true ,
417
448
fundingSource : paypalSdk . FUNDING . PAYPAL ,
418
449
style : paypalCommerceOptions . style ,
419
450
createOrder : expect . any ( Function ) ,
@@ -486,6 +517,30 @@ describe('PayPalCommerceButtonStrategy', () => {
486
517
defaultButtonContainerId ,
487
518
) ;
488
519
} ) ;
520
+
521
+ it ( 'initializes PayPal button to render with appSwitch flag' , async ( ) => {
522
+ jest . spyOn (
523
+ paymentIntegrationService . getState ( ) ,
524
+ 'getStoreConfigOrThrow' ,
525
+ ) . mockReturnValue ( {
526
+ ...storeConfig ,
527
+ checkoutSettings : {
528
+ ...storeConfig . checkoutSettings ,
529
+ features : {
530
+ 'PAYPAL-5716.app_switch_functionality' : true ,
531
+ } ,
532
+ } ,
533
+ } ) ;
534
+ await strategy . initialize ( initializationOptions ) ;
535
+
536
+ expect ( paypalSdk . Buttons ) . toHaveBeenCalledWith ( {
537
+ appSwitchWhenAvailable : true ,
538
+ fundingSource : paypalSdk . FUNDING . PAYPAL ,
539
+ style : paypalCommerceOptions . style ,
540
+ createOrder : expect . any ( Function ) ,
541
+ onApprove : expect . any ( Function ) ,
542
+ } ) ;
543
+ } ) ;
489
544
} ) ;
490
545
491
546
describe ( '#createOrder' , ( ) => {
@@ -512,6 +567,35 @@ describe('PayPalCommerceButtonStrategy', () => {
512
567
'paypalcommerce' ,
513
568
) ;
514
569
} ) ;
570
+
571
+ it ( 'creates paypal order with user agent' , async ( ) => {
572
+ Object . defineProperty ( window . navigator , 'userAgent' , {
573
+ value : 'Mozilla' ,
574
+ configurable : true ,
575
+ } ) ;
576
+ jest . spyOn (
577
+ paymentIntegrationService . getState ( ) ,
578
+ 'getStoreConfigOrThrow' ,
579
+ ) . mockReturnValue ( {
580
+ ...storeConfig ,
581
+ checkoutSettings : {
582
+ ...storeConfig . checkoutSettings ,
583
+ features : {
584
+ 'PAYPAL-5716.app_switch_functionality' : true ,
585
+ } ,
586
+ } ,
587
+ } ) ;
588
+ await strategy . initialize ( initializationOptions ) ;
589
+
590
+ eventEmitter . emit ( 'createOrder' ) ;
591
+
592
+ await new Promise ( ( resolve ) => process . nextTick ( resolve ) ) ;
593
+
594
+ expect ( paypalCommerceIntegrationService . createOrder ) . toHaveBeenCalledWith (
595
+ 'paypalcommerce' ,
596
+ { userAgent : 'Mozilla' } ,
597
+ ) ;
598
+ } ) ;
515
599
} ) ;
516
600
517
601
describe ( '#handleClick' , ( ) => {
0 commit comments