@ordergroove/offers 2.47.2-alpha-PR-1352-2.29 → 2.47.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,5 @@
1
1
  import * as constants from '../../core/constants';
2
- import { autoshipEligible, inStock, offer, optedin, price, productOffer, productPlans } from '../shopifyReducer';
3
- import { DEFAULT_PAY_AS_YOU_GO_GROUP_NAME } from '../utils';
2
+ import { autoshipEligible, inStock, offer, price, productOffer, productPlans } from '../shopifyReducer';
4
3
 
5
4
  describe('autoshipEligible', () => {
6
5
  it('should return null for each key in items given action SETUP_CART', () => {
@@ -233,824 +232,6 @@ describe('offer', () => {
233
232
  });
234
233
  });
235
234
 
236
- describe('optedin', () => {
237
- it('should return optins given action SETUP_CART', () => {
238
- const actual = optedin([], {
239
- type: constants.SETUP_CART,
240
- payload: {
241
- items: [
242
- {
243
- key: 'yum item key 1',
244
- selling_plan_allocation: {
245
- selling_plan: {
246
- id: 'yum selling plan id 1',
247
- options: [
248
- {
249
- name: 'Deliver every',
250
- value: '2 months'
251
- }
252
- ]
253
- }
254
- }
255
- },
256
- {
257
- key: 'yum item key 2',
258
- selling_plan_allocation: {
259
- selling_plan: {
260
- id: 'yum selling plan id 2',
261
- options: [
262
- {
263
- name: 'Deliver every',
264
- value: '2 months'
265
- }
266
- ]
267
- }
268
- }
269
- },
270
- {
271
- key: 'prepaid yum item',
272
- selling_plan_allocation: {
273
- selling_plan: {
274
- id: 'prepaid yum selling plan id',
275
- options: [
276
- {
277
- name: 'Deliver every',
278
- value: '1 month'
279
- },
280
- {
281
- name: 'Shipment amount',
282
- value: '3 shipments'
283
- }
284
- ]
285
- }
286
- }
287
- }
288
- ]
289
- }
290
- });
291
-
292
- expect(actual).toEqual([
293
- {
294
- id: 'yum item key 1',
295
- frequency: 'yum selling plan id 1'
296
- },
297
- {
298
- id: 'yum item key 2',
299
- frequency: 'yum selling plan id 2'
300
- },
301
- {
302
- id: 'prepaid yum item',
303
- frequency: 'prepaid yum selling plan id',
304
- prepaidShipments: 3
305
- }
306
- ]);
307
- });
308
-
309
- describe('given action RECEIVE_OFFER', () => {
310
- describe('given optin already in state', () => {
311
- describe('given optin does not have selling plan', () => {
312
- it('should set frequency to the selling plan given there is a matching selling plan', () => {
313
- const actual = optedin(
314
- [
315
- {
316
- id: 'yum product id 1',
317
- frequency: '1_2'
318
- }
319
- ],
320
- {
321
- type: constants.RECEIVE_OFFER,
322
- payload: {
323
- offer: {},
324
- frequencyConfig: {
325
- frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
326
- frequenciesEveryPeriod: ['1_1', '1_2']
327
- }
328
- }
329
- }
330
- );
331
-
332
- expect(actual).toEqual([
333
- {
334
- id: 'yum product id 1',
335
- frequency: 'yum selling plan id 2'
336
- }
337
- ]);
338
- });
339
-
340
- it('should set frequency to default selling plan given there is not a matching selling plan but there is a matching default sellin gplan', () => {
341
- const actual = optedin(
342
- [
343
- {
344
- id: 'yum product id 1',
345
- frequency: '1_2'
346
- }
347
- ],
348
- {
349
- type: constants.RECEIVE_OFFER,
350
- payload: {
351
- offer: {
352
- defaultFrequency: '3_2'
353
- },
354
- frequencyConfig: {
355
- frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
356
- frequenciesEveryPeriod: ['3_1', '3_2']
357
- }
358
- }
359
- }
360
- );
361
-
362
- expect(actual).toEqual([
363
- {
364
- id: 'yum product id 1',
365
- frequency: 'yum selling plan id 2'
366
- }
367
- ]);
368
- });
369
-
370
- it('should set frequency to first selling plan given there is not a matching selling plan or default selling plan', () => {
371
- const actual = optedin(
372
- [
373
- {
374
- id: 'yum product id 1',
375
- frequency: '1_2'
376
- }
377
- ],
378
- {
379
- type: constants.RECEIVE_OFFER,
380
- payload: {
381
- offer: {},
382
- frequencyConfig: {
383
- frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
384
- frequenciesEveryPeriod: ['3_1', '3_2']
385
- }
386
- }
387
- }
388
- );
389
-
390
- expect(actual).toEqual([
391
- {
392
- id: 'yum product id 1',
393
- frequency: 'yum selling plan id 1'
394
- }
395
- ]);
396
- });
397
- });
398
-
399
- it('should not change frequency given optin already has a selling plan', () => {
400
- const actual = optedin(
401
- [
402
- {
403
- id: 'yum product id 1',
404
- frequency: 'yum selling plan id 1'
405
- }
406
- ],
407
- {
408
- type: constants.RECEIVE_OFFER,
409
- payload: {
410
- offer: {},
411
- frequencyConfig: {
412
- frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
413
- frequenciesEveryPeriod: ['1_1', '1_2']
414
- }
415
- }
416
- }
417
- );
418
-
419
- expect(actual).toEqual([
420
- {
421
- id: 'yum product id 1',
422
- frequency: 'yum selling plan id 1'
423
- }
424
- ]);
425
- });
426
- });
427
-
428
- describe('given optin not already in state', () => {
429
- describe('given offer is eligible for autoship by default', () => {
430
- describe('given offer has PSDF', () => {
431
- describe('given selling plans are set', () => {
432
- it('should set frequency to the selling plan given there is a matching selling plan', () => {
433
- const actual = optedin([], {
434
- type: constants.RECEIVE_OFFER,
435
- payload: {
436
- autoship: {
437
- 'yum product id 1': true
438
- },
439
- autoship_by_default: {
440
- 'yum product id 1': true
441
- },
442
- default_frequencies: {
443
- 'yum product id 1': {
444
- every: 1,
445
- every_period: 2
446
- }
447
- },
448
- in_stock: {
449
- 'yum product id 1': true
450
- },
451
- offer: {
452
- defaultFrequency: 'yum offer default frequency'
453
- },
454
- frequencyConfig: {
455
- frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
456
- frequenciesEveryPeriod: ['1_1', '1_2']
457
- }
458
- }
459
- });
460
- expect(actual).toEqual([
461
- {
462
- id: 'yum product id 1',
463
- frequency: 'yum selling plan id 2'
464
- }
465
- ]);
466
- });
467
-
468
- describe('given there is no matching selling plan for PSDF', () => {
469
- it('should set frequency to offer element default frequency given offer element default frequency is a selling plan', () => {
470
- const actual = optedin([], {
471
- type: constants.RECEIVE_OFFER,
472
- payload: {
473
- autoship: {
474
- 'yum product id 1': true
475
- },
476
- autoship_by_default: {
477
- 'yum product id 1': true
478
- },
479
- default_frequencies: {
480
- 'yum product id 1': {
481
- every: 1,
482
- every_period: 2
483
- }
484
- },
485
- in_stock: {
486
- 'yum product id 1': true
487
- },
488
- offer: {
489
- defaultFrequency: 'yum offer default selling plan'
490
- },
491
- frequencyConfig: {
492
- frequencies: ['yum selling plan id 1'],
493
- frequenciesEveryPeriod: ['1_1']
494
- }
495
- }
496
- });
497
- expect(actual).toEqual([
498
- {
499
- id: 'yum product id 1',
500
- frequency: 'yum offer default selling plan'
501
- }
502
- ]);
503
- });
504
-
505
- it('should set frequency to the selling plan of the offer element default frequency given the offer element default frequency has a matching selling plan', () => {
506
- const actual = optedin([], {
507
- type: constants.RECEIVE_OFFER,
508
- payload: {
509
- autoship: {
510
- 'yum product id 1': true
511
- },
512
- autoship_by_default: {
513
- 'yum product id 1': true
514
- },
515
- default_frequencies: {
516
- 'yum product id 1': {
517
- every: 1,
518
- every_period: 2
519
- }
520
- },
521
- in_stock: {
522
- 'yum product id 1': true
523
- },
524
- offer: {
525
- defaultFrequency: '1_3'
526
- },
527
- frequencyConfig: {
528
- frequencies: ['yum selling plan id 1', 'yum selling plan id 3'],
529
- frequenciesEveryPeriod: ['1_1', '1_3']
530
- }
531
- }
532
- });
533
- expect(actual).toEqual([
534
- {
535
- id: 'yum product id 1',
536
- frequency: 'yum selling plan id 3'
537
- }
538
- ]);
539
- });
540
-
541
- it('should set frequency to the first selling plan given the offer element default frequency is not a selling plan and does not have a matching selling plan', () => {
542
- const actual = optedin([], {
543
- type: constants.RECEIVE_OFFER,
544
- payload: {
545
- autoship: {
546
- 'yum product id 1': true
547
- },
548
- autoship_by_default: {
549
- 'yum product id 1': true
550
- },
551
- default_frequencies: {
552
- 'yum product id 1': {
553
- every: 1,
554
- every_period: 2
555
- }
556
- },
557
- in_stock: {
558
- 'yum product id 1': true
559
- },
560
- offer: {
561
- defaultFrequency: '1_3'
562
- },
563
- frequencyConfig: {
564
- frequencies: ['yum selling plan id 1', 'yum selling plan id 4'],
565
- frequenciesEveryPeriod: ['1_1', '1_4']
566
- }
567
- }
568
- });
569
- expect(actual).toEqual([
570
- {
571
- id: 'yum product id 1',
572
- frequency: 'yum selling plan id 1'
573
- }
574
- ]);
575
- });
576
- });
577
- });
578
-
579
- it('should set frequency to every_everyPeriod psdf given selling plans are not set', () => {
580
- const actual = optedin([], {
581
- type: constants.RECEIVE_OFFER,
582
- payload: {
583
- autoship: {
584
- 'yum product id 1': true
585
- },
586
- autoship_by_default: {
587
- 'yum product id 1': true
588
- },
589
- default_frequencies: {
590
- 'yum product id 1': {
591
- every: 1,
592
- every_period: 2
593
- }
594
- },
595
- in_stock: {
596
- 'yum product id 1': true
597
- },
598
- offer: {
599
- defaultFrequency: 'yum offer default frequency'
600
- },
601
- frequencyConfig: {}
602
- }
603
- });
604
- expect(actual).toEqual([
605
- {
606
- id: 'yum product id 1',
607
- frequency: '1_2'
608
- }
609
- ]);
610
- });
611
- });
612
-
613
- describe('given offer does not have PSDF', () => {
614
- it('should set frequency to offer element default frequency given offer element default frequency is selling plan', () => {
615
- const actual = optedin([], {
616
- type: constants.RECEIVE_OFFER,
617
- payload: {
618
- autoship: {
619
- 'yum product id 1': true
620
- },
621
- autoship_by_default: {
622
- 'yum product id 1': true
623
- },
624
- in_stock: {
625
- 'yum product id 1': true
626
- },
627
- offer: {
628
- defaultFrequency: 'yum offer default selling plan'
629
- },
630
- frequencyConfig: {
631
- frequencies: ['yum selling plan id 1'],
632
- frequenciesEveryPeriod: ['1_1']
633
- }
634
- }
635
- });
636
- expect(actual).toEqual([
637
- {
638
- id: 'yum product id 1',
639
- frequency: 'yum offer default selling plan'
640
- }
641
- ]);
642
- });
643
-
644
- describe('given selling plans are set', () => {
645
- it('should set frequency to the selling plan of offer element default frequency given there is a matching selling plan for offer element default frequency', () => {
646
- const actual = optedin([], {
647
- type: constants.RECEIVE_OFFER,
648
- payload: {
649
- autoship: {
650
- 'yum product id 1': true
651
- },
652
- autoship_by_default: {
653
- 'yum product id 1': true
654
- },
655
- in_stock: {
656
- 'yum product id 1': true
657
- },
658
- offer: {
659
- defaultFrequency: '1_2'
660
- },
661
- frequencyConfig: {
662
- frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
663
- frequenciesEveryPeriod: ['1_1', '1_2']
664
- }
665
- }
666
- });
667
- expect(actual).toEqual([
668
- {
669
- id: 'yum product id 1',
670
- frequency: 'yum selling plan id 2'
671
- }
672
- ]);
673
- });
674
-
675
- describe('given there is no matching selling plan for every_everyPeriod default frequency of offer element', () => {
676
- it('should set frequency to offer element default frequency given offer element default frequency is a selling plan', () => {
677
- const actual = optedin([], {
678
- type: constants.RECEIVE_OFFER,
679
- payload: {
680
- autoship: {
681
- 'yum product id 1': true
682
- },
683
- autoship_by_default: {
684
- 'yum product id 1': true
685
- },
686
- in_stock: {
687
- 'yum product id 1': true
688
- },
689
- offer: {
690
- defaultFrequency: 'yum offer default selling plan'
691
- },
692
- frequencyConfig: {
693
- frequencies: ['yum selling plan id 1'],
694
- frequenciesEveryPeriod: ['1_1']
695
- }
696
- }
697
- });
698
- expect(actual).toEqual([
699
- {
700
- id: 'yum product id 1',
701
- frequency: 'yum offer default selling plan'
702
- }
703
- ]);
704
- });
705
-
706
- it('should set frequency to the selling plan of the offer element default frequency given the offer element default frequency has a matching selling plan', () => {
707
- const actual = optedin([], {
708
- type: constants.RECEIVE_OFFER,
709
- payload: {
710
- autoship: {
711
- 'yum product id 1': true
712
- },
713
- autoship_by_default: {
714
- 'yum product id 1': true
715
- },
716
- in_stock: {
717
- 'yum product id 1': true
718
- },
719
- offer: {
720
- defaultFrequency: '1_3'
721
- },
722
- frequencyConfig: {
723
- frequencies: ['yum selling plan id 1', 'yum selling plan id 3'],
724
- frequenciesEveryPeriod: ['1_1', '1_3']
725
- }
726
- }
727
- });
728
- expect(actual).toEqual([
729
- {
730
- id: 'yum product id 1',
731
- frequency: 'yum selling plan id 3'
732
- }
733
- ]);
734
- });
735
-
736
- it('should set frequency to the first selling plan given the offer element default frequency is not a selling plan and does not have a matching selling plan', () => {
737
- const actual = optedin([], {
738
- type: constants.RECEIVE_OFFER,
739
- payload: {
740
- autoship: {
741
- 'yum product id 1': true
742
- },
743
- autoship_by_default: {
744
- 'yum product id 1': true
745
- },
746
- in_stock: {
747
- 'yum product id 1': true
748
- },
749
- offer: {
750
- defaultFrequency: '1_3'
751
- },
752
- frequencyConfig: {
753
- frequencies: ['yum selling plan id 1', 'yum selling plan id 4'],
754
- frequenciesEveryPeriod: ['1_1', '1_4']
755
- }
756
- }
757
- });
758
- expect(actual).toEqual([
759
- {
760
- id: 'yum product id 1',
761
- frequency: 'yum selling plan id 1'
762
- }
763
- ]);
764
- });
765
- });
766
- });
767
- });
768
-
769
- it('should map frequency to selling plan given selling plan exists', () => {
770
- const actual = optedin(
771
- [
772
- {
773
- id: 'yum product id 1',
774
- frequency: '1_2'
775
- }
776
- ],
777
- {
778
- type: constants.RECEIVE_OFFER,
779
- payload: {
780
- offer: {},
781
- frequencyConfig: {
782
- frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
783
- frequenciesEveryPeriod: ['1_1', '1_2']
784
- }
785
- }
786
- }
787
- );
788
- expect(actual).toEqual([
789
- {
790
- id: 'yum product id 1',
791
- frequency: 'yum selling plan id 2'
792
- }
793
- ]);
794
- });
795
-
796
- it('should return unmodified state given state already contains optin with a selling plan', () => {
797
- const actual = optedin(
798
- [
799
- {
800
- id: 'yum product id 1',
801
- frequency: 'yum existing frequency'
802
- }
803
- ],
804
- {
805
- type: constants.RECEIVE_OFFER,
806
- payload: {}
807
- }
808
- );
809
- expect(actual).toEqual([
810
- {
811
- id: 'yum product id 1',
812
- frequency: 'yum existing frequency'
813
- }
814
- ]);
815
- });
816
- });
817
- });
818
- });
819
-
820
- describe('given action is SETUP_PRODUCT', () => {
821
- it('should return unmodified state given frequeny is already a selling plan', () => {
822
- const actual = optedin(
823
- [
824
- {
825
- id: 'yum product id 1',
826
- frequency: 'yum selling plan id 1'
827
- }
828
- ],
829
- {
830
- type: constants.SETUP_PRODUCT,
831
- payload: {
832
- product: {
833
- selling_plan_groups: [
834
- {
835
- name: DEFAULT_PAY_AS_YOU_GO_GROUP_NAME,
836
- selling_plans: [
837
- {
838
- id: 'yum selling plan id 1',
839
- options: [
840
- {
841
- value: '1 day'
842
- }
843
- ]
844
- },
845
- {
846
- id: 'yum selling plan id 2',
847
- options: [
848
- {
849
- value: '1 week1'
850
- }
851
- ]
852
- }
853
- ]
854
- }
855
- ]
856
- }
857
- }
858
- }
859
- );
860
-
861
- expect(actual).toEqual([
862
- {
863
- id: 'yum product id 1',
864
- frequency: 'yum selling plan id 1'
865
- }
866
- ]);
867
- });
868
-
869
- it('should set frequency to selling plan given matching selling plan', () => {
870
- const actual = optedin(
871
- [
872
- {
873
- id: 'yum product id 1',
874
- frequency: '1_2'
875
- }
876
- ],
877
- {
878
- type: constants.SETUP_PRODUCT,
879
- payload: {
880
- product: {
881
- selling_plan_groups: [
882
- {
883
- name: DEFAULT_PAY_AS_YOU_GO_GROUP_NAME,
884
- selling_plans: [
885
- {
886
- id: 'yum selling plan id 1',
887
- options: [
888
- {
889
- value: '1 day'
890
- }
891
- ]
892
- },
893
- {
894
- id: 'yum selling plan id 2',
895
- options: [
896
- {
897
- value: '1 week'
898
- }
899
- ]
900
- }
901
- ]
902
- }
903
- ]
904
- }
905
- }
906
- }
907
- );
908
-
909
- expect(actual).toEqual([
910
- {
911
- id: 'yum product id 1',
912
- frequency: 'yum selling plan id 2'
913
- }
914
- ]);
915
- });
916
-
917
- it('should set frequency to first selling plan given no matching selling plan', () => {
918
- const actual = optedin(
919
- [
920
- {
921
- id: 'yum product id 1',
922
- frequency: '1_3'
923
- }
924
- ],
925
- {
926
- type: constants.SETUP_PRODUCT,
927
- payload: {
928
- product: {
929
- selling_plan_groups: [
930
- {
931
- name: DEFAULT_PAY_AS_YOU_GO_GROUP_NAME,
932
- selling_plans: [
933
- {
934
- id: 'yum selling plan id 1',
935
- options: [
936
- {
937
- value: '1 day'
938
- }
939
- ]
940
- },
941
- {
942
- id: 'yum selling plan id 2',
943
- options: [
944
- {
945
- value: '1 week'
946
- }
947
- ]
948
- }
949
- ]
950
- }
951
- ]
952
- }
953
- }
954
- }
955
- );
956
-
957
- expect(actual).toEqual([
958
- {
959
- id: 'yum product id 1',
960
- frequency: 'yum selling plan id 1'
961
- }
962
- ]);
963
- });
964
-
965
- it('should not error and not change state if there are no selling plan groups', () => {
966
- const actual = optedin(
967
- [
968
- {
969
- id: 'yum product id 1',
970
- frequency: '1_3'
971
- }
972
- ],
973
- {
974
- type: constants.SETUP_PRODUCT,
975
- payload: {
976
- product: {
977
- selling_plan_groups: []
978
- }
979
- }
980
- }
981
- );
982
-
983
- expect(actual).toEqual([
984
- {
985
- id: 'yum product id 1',
986
- frequency: '1_3'
987
- }
988
- ]);
989
- });
990
- });
991
-
992
- describe('given action is PRODUCT_CHANGE_PREPAID_SHIPMENTS', () => {
993
- function getPayload(prepaidShipments, frequency) {
994
- return {
995
- product: {
996
- id: 'yum prepaid id'
997
- },
998
- prepaidShipments: prepaidShipments,
999
- offer: {},
1000
- frequency
1001
- };
1002
- }
1003
-
1004
- it('opts into the given frequency and shipments', () => {
1005
- const actual = optedin([], {
1006
- type: constants.PRODUCT_CHANGE_PREPAID_SHIPMENTS,
1007
- payload: getPayload(4, 'yum prepaid selling plan id 2')
1008
- });
1009
- expect(actual).toEqual([
1010
- {
1011
- id: 'yum prepaid id',
1012
- frequency: 'yum prepaid selling plan id 2',
1013
- prepaidShipments: 4
1014
- }
1015
- ]);
1016
- });
1017
-
1018
- it('updates existing opted in state', () => {
1019
- const actual = optedin(
1020
- [
1021
- {
1022
- id: 'yum prepaid id',
1023
- frequency: 'yum selling plan id 1'
1024
- }
1025
- ],
1026
- {
1027
- type: constants.PRODUCT_CHANGE_PREPAID_SHIPMENTS,
1028
- payload: getPayload(4, 'yum prepaid selling plan id 2')
1029
- }
1030
- );
1031
- expect(actual).toEqual([
1032
- {
1033
- id: 'yum prepaid id',
1034
- frequency: 'yum prepaid selling plan id 2',
1035
- prepaidShipments: 4
1036
- }
1037
- ]);
1038
- });
1039
- });
1040
-
1041
- it('should return unmodified state given unsupported action', () => {
1042
- const actual = optedin(
1043
- { 'yum existing key': 'yum existing value' },
1044
- {
1045
- type: 'yum unsupported action',
1046
- payload: {}
1047
- }
1048
- );
1049
-
1050
- expect(actual).toEqual({ 'yum existing key': 'yum existing value' });
1051
- });
1052
- });
1053
-
1054
235
  describe('price', () => {
1055
236
  it('should return price for each variant given action SETUP_PRODUCT', () => {
1056
237
  const actual = price(