@zoxllc/shopify-checkout-extensions 0.0.8 → 0.1.0

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.
Files changed (161) hide show
  1. package/CLAUDE.md +136 -0
  2. package/EXAMPLES.md +384 -0
  3. package/INTEGRATION.md +482 -0
  4. package/README.md +5 -1
  5. package/dist/common/AndSelector.d.ts +11 -0
  6. package/dist/common/AndSelector.d.ts.map +1 -0
  7. package/dist/common/AndSelector.js +30 -0
  8. package/dist/common/Campaign.d.ts +24 -0
  9. package/dist/common/Campaign.d.ts.map +1 -0
  10. package/dist/common/Campaign.js +41 -0
  11. package/dist/common/CampaignConfiguration.d.ts +10 -0
  12. package/dist/common/CampaignConfiguration.d.ts.map +1 -0
  13. package/dist/common/CampaignConfiguration.js +7 -0
  14. package/dist/common/CampaignFactory.d.ts +22 -0
  15. package/dist/common/CampaignFactory.d.ts.map +1 -0
  16. package/dist/common/CampaignFactory.js +95 -0
  17. package/dist/common/CartAmountQualifier.d.ts +22 -0
  18. package/dist/common/CartAmountQualifier.d.ts.map +1 -0
  19. package/dist/common/CartAmountQualifier.js +46 -0
  20. package/dist/common/CartHasItemQualifier.d.ts +21 -0
  21. package/dist/common/CartHasItemQualifier.d.ts.map +1 -0
  22. package/dist/common/CartHasItemQualifier.js +54 -0
  23. package/dist/common/CartQuantityQualifier.d.ts +22 -0
  24. package/dist/common/CartQuantityQualifier.d.ts.map +1 -0
  25. package/dist/common/CartQuantityQualifier.js +62 -0
  26. package/dist/common/ConfigSchema.d.ts +71 -0
  27. package/dist/common/ConfigSchema.d.ts.map +1 -0
  28. package/dist/common/ConfigSchema.js +69 -0
  29. package/dist/common/ConfigValidator.d.ts +29 -0
  30. package/dist/common/ConfigValidator.d.ts.map +1 -0
  31. package/dist/common/ConfigValidator.js +84 -0
  32. package/dist/common/CountryCodeQualifier.d.ts +15 -0
  33. package/dist/common/CountryCodeQualifier.d.ts.map +1 -0
  34. package/dist/common/CountryCodeQualifier.js +30 -0
  35. package/dist/common/CustomerEmailQualifier.d.ts +16 -0
  36. package/dist/common/CustomerEmailQualifier.d.ts.map +1 -0
  37. package/dist/common/CustomerEmailQualifier.js +52 -0
  38. package/dist/common/CustomerSubscriberQualifier.d.ts +18 -0
  39. package/dist/common/CustomerSubscriberQualifier.d.ts.map +1 -0
  40. package/dist/common/CustomerSubscriberQualifier.js +28 -0
  41. package/dist/common/CustomerTagQualifier.d.ts +16 -0
  42. package/dist/common/CustomerTagQualifier.d.ts.map +1 -0
  43. package/dist/common/CustomerTagQualifier.js +45 -0
  44. package/dist/common/DiscountCart.d.ts +23 -0
  45. package/dist/common/DiscountCart.d.ts.map +1 -0
  46. package/dist/common/DiscountCart.js +103 -0
  47. package/dist/common/DiscountInterface.d.ts +17 -0
  48. package/dist/common/DiscountInterface.d.ts.map +1 -0
  49. package/dist/common/DiscountInterface.js +2 -0
  50. package/dist/common/OrSelector.d.ts +11 -0
  51. package/dist/common/OrSelector.d.ts.map +1 -0
  52. package/dist/common/OrSelector.js +30 -0
  53. package/dist/common/PostCartAmountQualifier.d.ts +9 -0
  54. package/dist/common/PostCartAmountQualifier.d.ts.map +1 -0
  55. package/dist/common/PostCartAmountQualifier.js +17 -0
  56. package/dist/common/ProductHandleSelector.d.ts +8 -0
  57. package/dist/common/ProductHandleSelector.d.ts.map +1 -0
  58. package/dist/common/ProductHandleSelector.js +22 -0
  59. package/dist/common/ProductIdSelector.d.ts +8 -0
  60. package/dist/common/ProductIdSelector.d.ts.map +1 -0
  61. package/dist/common/ProductIdSelector.js +22 -0
  62. package/dist/common/ProductTagSelector.d.ts +10 -0
  63. package/dist/common/ProductTagSelector.d.ts.map +1 -0
  64. package/dist/common/ProductTagSelector.js +39 -0
  65. package/dist/common/ProductTypeSelector.d.ts +8 -0
  66. package/dist/common/ProductTypeSelector.d.ts.map +1 -0
  67. package/dist/common/ProductTypeSelector.js +25 -0
  68. package/dist/common/Qualifier.d.ts +30 -0
  69. package/dist/common/Qualifier.d.ts.map +1 -0
  70. package/dist/common/Qualifier.js +61 -0
  71. package/dist/common/SaleItemSelector.d.ts +11 -0
  72. package/dist/common/SaleItemSelector.d.ts.map +1 -0
  73. package/dist/common/SaleItemSelector.js +30 -0
  74. package/dist/common/Selector.d.ts +27 -0
  75. package/dist/common/Selector.d.ts.map +1 -0
  76. package/dist/common/Selector.js +51 -0
  77. package/dist/common/SubscriptionItemSelector.d.ts +7 -0
  78. package/dist/common/SubscriptionItemSelector.d.ts.map +1 -0
  79. package/dist/common/SubscriptionItemSelector.js +19 -0
  80. package/dist/form/CampaignForm.d.ts +1 -0
  81. package/dist/form/CampaignForm.d.ts.map +1 -0
  82. package/dist/form/CampaignForm.js +1 -0
  83. package/{src/index.ts → dist/index.d.ts} +22 -27
  84. package/dist/index.d.ts.map +1 -0
  85. package/dist/index.js +78 -0
  86. package/dist/lineItem/BuyXGetY.d.ts +18 -0
  87. package/dist/lineItem/BuyXGetY.d.ts.map +1 -0
  88. package/dist/lineItem/BuyXGetY.js +85 -0
  89. package/dist/lineItem/ConditionalDiscount.d.ts +14 -0
  90. package/dist/lineItem/ConditionalDiscount.d.ts.map +1 -0
  91. package/dist/lineItem/ConditionalDiscount.js +81 -0
  92. package/dist/lineItem/FixedItemDiscount.d.ts +9 -0
  93. package/dist/lineItem/FixedItemDiscount.d.ts.map +1 -0
  94. package/dist/lineItem/FixedItemDiscount.js +35 -0
  95. package/dist/lineItem/PercentageDiscount.d.ts +8 -0
  96. package/dist/lineItem/PercentageDiscount.d.ts.map +1 -0
  97. package/dist/lineItem/PercentageDiscount.js +32 -0
  98. package/dist/lineItem/api.d.ts +2026 -0
  99. package/dist/lineItem/api.d.ts.map +1 -0
  100. package/dist/lineItem/api.js +1157 -0
  101. package/dist/shipping/FixedDiscount.d.ts +8 -0
  102. package/dist/shipping/FixedDiscount.d.ts.map +1 -0
  103. package/dist/shipping/FixedDiscount.js +30 -0
  104. package/dist/shipping/RateNameSelector.d.ts +10 -0
  105. package/dist/shipping/RateNameSelector.d.ts.map +1 -0
  106. package/dist/shipping/RateNameSelector.js +45 -0
  107. package/dist/shipping/ShippingDiscount.d.ts +14 -0
  108. package/dist/shipping/ShippingDiscount.d.ts.map +1 -0
  109. package/dist/shipping/ShippingDiscount.js +48 -0
  110. package/dist/shipping/api.d.ts +2019 -0
  111. package/dist/shipping/api.d.ts.map +1 -0
  112. package/dist/shipping/api.js +1147 -0
  113. package/package.json +26 -7
  114. package/migrate.ts +0 -64
  115. package/src/common/AndSelector.ts +0 -42
  116. package/src/common/Campaign.ts +0 -70
  117. package/src/common/CampaignConfiguration.ts +0 -10
  118. package/src/common/CampaignFactory.ts +0 -233
  119. package/src/common/CartAmountQualifier.ts +0 -64
  120. package/src/common/CartHasItemQualifier.ts +0 -80
  121. package/src/common/CartQuantityQualifier.ts +0 -94
  122. package/src/common/CountryCodeQualifier.ts +0 -49
  123. package/src/common/CustomerEmailQualifier.ts +0 -67
  124. package/src/common/CustomerSubscriberQualifier.ts +0 -32
  125. package/src/common/CustomerTagQualifier.ts +0 -69
  126. package/src/common/DiscountCart.ts +0 -161
  127. package/src/common/DiscountInterface.ts +0 -26
  128. package/src/common/OrSelector.ts +0 -40
  129. package/src/common/PostCartAmountQualifier.ts +0 -21
  130. package/src/common/ProductHandleSelector.ts +0 -32
  131. package/src/common/ProductIdSelector.ts +0 -34
  132. package/src/common/ProductTagSelector.ts +0 -63
  133. package/src/common/ProductTypeSelector.ts +0 -40
  134. package/src/common/Qualifier.ts +0 -67
  135. package/src/common/SaleItemSelector.ts +0 -36
  136. package/src/common/Selector.ts +0 -66
  137. package/src/common/SubscriptionItemSelector.ts +0 -23
  138. package/src/lineItem/BuyXGetY.ts +0 -131
  139. package/src/lineItem/ConditionalDiscount.ts +0 -102
  140. package/src/lineItem/FixedItemDiscount.ts +0 -51
  141. package/src/lineItem/PercentageDiscount.ts +0 -44
  142. package/src/lineItem/api.ts +0 -2103
  143. package/src/shipping/FixedDiscount.ts +0 -37
  144. package/src/shipping/RateNameSelector.ts +0 -54
  145. package/src/shipping/ShippingDiscount.ts +0 -75
  146. package/src/shipping/api.ts +0 -2014
  147. package/tests/AndSelector.test.ts +0 -27
  148. package/tests/CartQuantityQualifier.test.ts +0 -381
  149. package/tests/CountryCodeQualifier.test.ts +0 -55
  150. package/tests/CustomerSubscriberQualifier.test.ts +0 -101
  151. package/tests/CustomerTagQualifier.test.ts +0 -71
  152. package/tests/DiscountCart.test.ts +0 -115
  153. package/tests/OrSelector.test.ts +0 -27
  154. package/tests/ProductIdSelector.test.ts +0 -83
  155. package/tests/ProductTagSelector.test.ts +0 -75
  156. package/tests/Qualifier.test.ts +0 -193
  157. package/tests/RateNameSelector.test.ts +0 -107
  158. package/tests/SaleItemSelector.test.ts +0 -113
  159. package/tests/Selector.test.ts +0 -83
  160. package/tests/ShippingDiscount.test.ts +0 -147
  161. package/tsconfig.json +0 -25
@@ -1,115 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { DiscountCart } from '../src/common/DiscountCart';
3
- import { RunInput } from '../src/lineItem/api';
4
-
5
- describe('DiscountCart', () => {
6
- const discountCart = new DiscountCart(
7
- ONE_GWP_BULK_DISCOUNT_8_PLUS.cart as RunInput['cart']
8
- );
9
-
10
- it('Contains correct amounts', () => {
11
- expect(discountCart.discounts.length).toBe(0);
12
- expect(discountCart.subtotalAmount).toBe(64);
13
- expect(discountCart.appliedDiscountTotal).toBe(0);
14
-
15
- discountCart.addDiscount({
16
- targets: [
17
- {
18
- productVariant: {
19
- id: 'gid://shopify/ProductVariant/43900890579178',
20
- },
21
- },
22
- ],
23
- value: {
24
- fixedAmount: {
25
- amount: 2,
26
- appliesToEachItem: true,
27
- },
28
- },
29
- });
30
-
31
- expect(discountCart.discounts.length).toBe(1);
32
- expect(discountCart.appliedDiscountTotal).toBe(16);
33
- });
34
- });
35
-
36
- const ONE_GWP_BULK_DISCOUNT_8_PLUS = {
37
- cart: {
38
- cost: {
39
- subtotalAmount: {
40
- amount: '164.0',
41
- },
42
- totalAmount: {
43
- amount: '164.0',
44
- },
45
- },
46
- lines: [
47
- {
48
- gwp: null,
49
- cost: {
50
- amountPerQuantity: {
51
- amount: '8.0',
52
- },
53
- subtotalAmount: {
54
- amount: '64.0',
55
- },
56
- totalAmount: {
57
- amount: '64.0',
58
- },
59
- compareAtAmountPerQuantity: null,
60
- },
61
- quantity: 8,
62
- merchandise: {
63
- __typename: 'ProductVariant',
64
- id: 'gid://shopify/ProductVariant/43900890579178',
65
- product: {
66
- id: 'gid://shopify/Product/8069766840554',
67
- productType: 'Wristband - Single',
68
- hasTags: [
69
- {
70
- tag: 'meta-exclude-gift',
71
- hasTag: false,
72
- },
73
- ],
74
- },
75
- },
76
- },
77
- {
78
- gwp: null,
79
- cost: {
80
- amountPerQuantity: {
81
- amount: '100.0',
82
- },
83
- subtotalAmount: {
84
- amount: '100.0',
85
- },
86
- totalAmount: {
87
- amount: '100.0',
88
- },
89
- compareAtAmountPerQuantity: null,
90
- },
91
- quantity: 1,
92
- merchandise: {
93
- __typename: 'ProductVariant',
94
- id: 'gid://shopify/ProductVariant/43137443692778',
95
- product: {
96
- id: 'gid://shopify/Product/7803814379754',
97
- productType: 'Gift',
98
- hasTags: [
99
- {
100
- tag: 'meta-exclude-gift',
101
- hasTag: true,
102
- },
103
- ],
104
- },
105
- },
106
- },
107
- ],
108
- },
109
- discountNode: {
110
- metafield: {
111
- value:
112
- '{"campaigns":[{"__type":"BuyXGetY","inputs":[":all",[],{"__type":"FixedItemDiscount","inputs":[2,true,"Bulky functions discount!"]},{"__type":"ProductTypeSelector","inputs":[":is_one",["Wristband - Single","Wristband - Strap"]]},{"__type":"ProductTypeSelector","inputs":[":is_one",["Wristband - Single","Wristband - Strap"]]},8,null,null]},{"__type":"ConditionalDiscount","inputs":[":all",[{"__type":"AndSelector","inputs":[{"__type":"PostCartAmountQualifier","inputs":[":greater_than_or_equal",50]},{"__type":"CartAmountQualifier","inputs":[":cart",":greater_than_or_equal",50]}]}],{"__type":"PercentageDiscount","inputs":[100,"Now you\'re family! :)"]},{"__type":"ProductIdSelector","inputs":[":is_one",["gid://shopify/Product/7803814379754"]]}]}], "discountApplicationStrategy": "ALL"}',
113
- },
114
- },
115
- };
@@ -1,27 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { OrSelector } from '../src/common/OrSelector';
3
- import { CartLine } from '../src/lineItem/api';
4
- import {
5
- MockFalseyQualifier,
6
- MockTruthyQualifier,
7
- } from './Qualifier.test';
8
-
9
- describe('OrSelector', () => {
10
- it('Returns true if any conditions are met', () => {
11
- const selector = new OrSelector([
12
- new MockFalseyQualifier(),
13
- new MockTruthyQualifier(),
14
- ]);
15
-
16
- expect(selector.match({} as CartLine)).toBeTruthy();
17
- });
18
-
19
- it('Returns false if all conditions are not met', () => {
20
- const selector = new OrSelector([
21
- new MockFalseyQualifier(),
22
- new MockFalseyQualifier(),
23
- ]);
24
-
25
- expect(selector.match({} as CartLine)).toBeFalsy();
26
- });
27
- });
@@ -1,83 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import _ from 'lodash';
3
- import { ProductIdSelector } from '../src/common/ProductIdSelector';
4
- import { CartLine } from '../src/lineItem/api';
5
- import {
6
- QualifierMatchType,
7
- StringComparisonType,
8
- } from '../src/common/Qualifier';
9
- import { MatchType } from '../src/common/Selector';
10
-
11
- describe('ProductIdSelector', () => {
12
- it('is true when it matches one of', () => {
13
- const selector = new ProductIdSelector(
14
- MatchType.IS_ONE,
15
- [
16
- 'tag1',
17
- 'gid://shopify/Product/1234567890',
18
- 'tag3',
19
- 'TAG4',
20
- ]
21
- );
22
- const result = selector.match(lineItem);
23
- expect(result).toEqual(true);
24
- });
25
-
26
- it('is true when it does NOT match one of', () => {
27
- const selector = new ProductIdSelector(
28
- MatchType.NOT_ONE,
29
- [
30
- 'gid://shopify/Product/1111',
31
- 'gid://shopify/Product/2222',
32
- 'gid://shopify/Product/3333',
33
- 'gid://shopify/Product/4444',
34
- ]
35
- );
36
- const result = selector.match(lineItem);
37
- expect(result).toEqual(true);
38
- });
39
-
40
- it('is false when it is not found', () => {
41
- const selector = new ProductIdSelector(
42
- MatchType.IS_ONE,
43
- ['gid://shopify/Product/111111', 'a']
44
- );
45
- const result = selector.match(lineItem);
46
- expect(result).toEqual(false);
47
- });
48
-
49
- it('is false when it is present but it is not expected to', () => {
50
- const selector = new ProductIdSelector(
51
- MatchType.NOT_ONE,
52
- ['gid://shopify/Product/1234567890', 'a']
53
- );
54
- const result = selector.match(lineItem);
55
- expect(result).toEqual(false);
56
- });
57
-
58
- const lineItem = {
59
- merchandise: {
60
- product: {
61
- id: 'gid://shopify/Product/1234567890',
62
- hasTags: [
63
- {
64
- tag: 'tag1',
65
- hasTag: true,
66
- },
67
- {
68
- tag: 'tag2',
69
- hasTag: true,
70
- },
71
- {
72
- tag: 'tag3',
73
- hasTag: true,
74
- },
75
- {
76
- tag: 'tag4',
77
- hasTag: true,
78
- },
79
- ],
80
- },
81
- },
82
- } as CartLine;
83
- });
@@ -1,75 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import _ from 'lodash';
3
- import { ProductTagSelector } from '../src/common/ProductTagSelector';
4
- import { CartLine } from '../src/lineItem/api';
5
- import {
6
- QualifierMatchType,
7
- StringComparisonType,
8
- } from '../src/common/Qualifier';
9
-
10
- describe('ProductTagSelector', () => {
11
- it('is true when it matches one of', () => {
12
- const selector = new ProductTagSelector(
13
- QualifierMatchType.DOES,
14
- StringComparisonType.MATCH,
15
- ['tag1', 'tag2', 'tag3', 'TAG4']
16
- );
17
- const result = selector.match(lineItem);
18
- expect(result).toEqual(true);
19
- });
20
-
21
- it('is false when it does NOT match one of', () => {
22
- const selector = new ProductTagSelector(
23
- QualifierMatchType.DOES,
24
- StringComparisonType.MATCH,
25
- ['tag6', 'tag7', 'tag8', 'tag9']
26
- );
27
- const result = selector.match(lineItem);
28
- expect(result).toEqual(false);
29
- });
30
-
31
- it('is true when it contains one of', () => {
32
- const selector = new ProductTagSelector(
33
- QualifierMatchType.DOES,
34
- StringComparisonType.CONTAINS,
35
- ['ag', 'a']
36
- );
37
- const result = selector.match(lineItem);
38
- expect(result).toEqual(true);
39
- });
40
-
41
- it('is false when it does NOT contain one of', () => {
42
- const selector = new ProductTagSelector(
43
- QualifierMatchType.DOES,
44
- StringComparisonType.CONTAINS,
45
- ['sandwich', 'choir']
46
- );
47
- const result = selector.match(lineItem);
48
- expect(result).toEqual(false);
49
- });
50
-
51
- const lineItem = {
52
- merchandise: {
53
- product: {
54
- hasTags: [
55
- {
56
- tag: 'tag1',
57
- hasTag: true,
58
- },
59
- {
60
- tag: 'tag2',
61
- hasTag: true,
62
- },
63
- {
64
- tag: 'tag3',
65
- hasTag: true,
66
- },
67
- {
68
- tag: 'tag4',
69
- hasTag: true,
70
- },
71
- ],
72
- },
73
- },
74
- } as CartLine;
75
- });
@@ -1,193 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import {
3
- NumericalComparisonType,
4
- Qualifier,
5
- } from '../src/common/Qualifier';
6
- import type { DiscountCart } from '../src/common/DiscountCart';
7
- import type { CartLine } from '../src/lineItem/api';
8
- import type { Selector } from '../src/common/Selector';
9
-
10
- export class MockTruthyQualifier extends Qualifier {
11
- match(
12
- subject: DiscountCart | CartLine,
13
- selector?: Selector | undefined
14
- ): boolean {
15
- return true;
16
- }
17
- }
18
-
19
- export class MockFalseyQualifier extends Qualifier {
20
- match(
21
- subject: DiscountCart | CartLine,
22
- selector?: Selector | undefined
23
- ): boolean {
24
- return false;
25
- }
26
- }
27
-
28
- describe('Qualifier', () => {
29
- const qualifier = new Qualifier();
30
- it('Contains a root compareAmounts method', () => {
31
- expect(qualifier.compareAmounts).toBeDefined();
32
- });
33
-
34
- it('Compares amounts properly for all cases', () => {
35
- // EQUAL_TO
36
- expect(
37
- qualifier.compareAmounts(
38
- 10,
39
- NumericalComparisonType.EQUAL_TO,
40
- 10
41
- ),
42
- 'Must be TRUE when 10 EQUAL_TO 10'
43
- ).toEqual(true);
44
- expect(
45
- qualifier.compareAmounts(
46
- 1,
47
- NumericalComparisonType.EQUAL_TO,
48
- 10
49
- ),
50
- 'Must be FALSE when 1 EQUAL_TO 10'
51
- ).toEqual(false);
52
- expect(
53
- qualifier.compareAmounts(
54
- 10,
55
- NumericalComparisonType.EQUAL_TO,
56
- 1
57
- ),
58
- 'Must be FALSE when 10 EQUAL_TO 1'
59
- ).toEqual(false);
60
-
61
- // GREATER_THAN
62
- expect(
63
- qualifier.compareAmounts(
64
- 11,
65
- NumericalComparisonType.GREATER_THAN,
66
- 10
67
- ),
68
- 'Must be TRUE when 11 GREATER_THAN 10'
69
- ).toEqual(true);
70
- expect(
71
- qualifier.compareAmounts(
72
- 1,
73
- NumericalComparisonType.GREATER_THAN,
74
- 10
75
- ),
76
- 'Must be FALSE when 1 GREATER_THAN 10'
77
- ).toEqual(false);
78
- expect(
79
- qualifier.compareAmounts(
80
- 10,
81
- NumericalComparisonType.GREATER_THAN,
82
- 1
83
- ),
84
- 'Must be TRUE when 10 GREATER_THAN 1'
85
- ).toEqual(true);
86
-
87
- // GREATER_THAN_OR_EQUAL
88
- expect(
89
- qualifier.compareAmounts(
90
- 11,
91
- NumericalComparisonType.GREATER_THAN_OR_EQUAL,
92
- 10
93
- ),
94
- 'Must be TRUE when 11 GREATER_THAN_OR_EQUAL 10'
95
- ).toEqual(true);
96
- expect(
97
- qualifier.compareAmounts(
98
- 10,
99
- NumericalComparisonType.GREATER_THAN_OR_EQUAL,
100
- 10
101
- ),
102
- 'Must be TRUE when 10 GREATER_THAN_OR_EQUAL 10'
103
- ).toEqual(true);
104
- expect(
105
- qualifier.compareAmounts(
106
- 1,
107
- NumericalComparisonType.GREATER_THAN_OR_EQUAL,
108
- 10
109
- ),
110
- 'Must be FALSE when 1 GREATER_THAN_OR_EQUAL 10'
111
- ).toEqual(false);
112
- expect(
113
- qualifier.compareAmounts(
114
- 10,
115
- NumericalComparisonType.GREATER_THAN_OR_EQUAL,
116
- 1
117
- ),
118
- 'Must be TRUE when 10 GREATER_THAN_OR_EQUAL 1'
119
- ).toEqual(true);
120
-
121
- // LESS_THAN
122
- expect(
123
- qualifier.compareAmounts(
124
- 11,
125
- NumericalComparisonType.LESS_THAN,
126
- 10
127
- ),
128
- 'Must be FALSE when 11 LESS_THAN 10'
129
- ).toEqual(false);
130
- expect(
131
- qualifier.compareAmounts(
132
- 1,
133
- NumericalComparisonType.LESS_THAN,
134
- 10
135
- ),
136
- 'Must be TRUE when 1 LESS_THAN 10'
137
- ).toEqual(true);
138
- expect(
139
- qualifier.compareAmounts(
140
- 10,
141
- NumericalComparisonType.LESS_THAN,
142
- 1
143
- ),
144
- 'Must be FALSE when 10 LESS_THAN 1'
145
- ).toEqual(false);
146
- expect(
147
- qualifier.compareAmounts(
148
- 1,
149
- NumericalComparisonType.LESS_THAN,
150
- 1
151
- ),
152
- 'Must be FALSE when 1 LESS_THAN 1'
153
- ).toEqual(false);
154
-
155
- // LESS_THAN_OR_EQUAL
156
- expect(
157
- qualifier.compareAmounts(
158
- 11,
159
- NumericalComparisonType.LESS_THAN_OR_EQUAL,
160
- 10
161
- ),
162
- 'Must be FALSE when 11 LESS_THAN_OR_EQUAL 10'
163
- ).toEqual(false);
164
- expect(
165
- qualifier.compareAmounts(
166
- 10,
167
- NumericalComparisonType.LESS_THAN_OR_EQUAL,
168
- 10
169
- ),
170
- 'Must be TRUE when 10 LESS_THAN_OR_EQUAL 10'
171
- ).toEqual(true);
172
- expect(
173
- qualifier.compareAmounts(
174
- 1,
175
- NumericalComparisonType.LESS_THAN_OR_EQUAL,
176
- 10
177
- ),
178
- 'Must be TRUE when 1 LESS_THAN_OR_EQUAL 10'
179
- ).toEqual(true);
180
- expect(
181
- qualifier.compareAmounts(
182
- 10,
183
- NumericalComparisonType.LESS_THAN_OR_EQUAL,
184
- 1
185
- ),
186
- 'Must be FALSE when 10 LESS_THAN_OR_EQUAL 1'
187
- ).toEqual(false);
188
- });
189
-
190
- it('Will always return false when calling match()', () => {
191
- expect(qualifier.match({} as DiscountCart)).toBeFalsy();
192
- });
193
- });
@@ -1,107 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import _ from 'lodash';
3
- import {
4
- CartDeliveryOption,
5
- DeliveryMethod,
6
- } from '../src/shipping/api';
7
- import { RateNameSelector } from '../src/shipping/RateNameSelector';
8
- import { MatchType } from '../src/common/Selector';
9
- import { StringComparisonType } from '../src/common/Qualifier';
10
-
11
- describe('RateNameSelector', () => {
12
- it('is true when it matches one of', () => {
13
- const selector = new RateNameSelector(
14
- MatchType.DOES,
15
- StringComparisonType.MATCH,
16
- ['Fedex - 10% Shipping', 'UPS - Domestic']
17
- );
18
- const result = selector.match(cartDeliveryOption);
19
- expect(result).toEqual(true);
20
- });
21
-
22
- it('is true when it does NOT match one of', () => {
23
- const selector = new RateNameSelector(
24
- MatchType.DOES_NOT,
25
- StringComparisonType.MATCH,
26
- ['Fedex', 'UPS']
27
- );
28
- const result = selector.match(cartDeliveryOption);
29
- expect(result).toEqual(true);
30
- });
31
-
32
- it('is true when it contains one of', () => {
33
- const selector = new RateNameSelector(
34
- MatchType.DOES,
35
- StringComparisonType.CONTAINS,
36
- ['FedEx']
37
- );
38
- const result = selector.match(cartDeliveryOption);
39
- expect(result).toEqual(true);
40
- });
41
-
42
- it('is true when it does NOT contain one of', () => {
43
- const selector = new RateNameSelector(
44
- MatchType.DOES_NOT,
45
- StringComparisonType.CONTAINS,
46
- ['Monkey']
47
- );
48
- const result = selector.match(cartDeliveryOption);
49
- expect(result).toEqual(true);
50
- });
51
-
52
- it('is false when it does contain one of with DOES_NOT', () => {
53
- const selector = new RateNameSelector(
54
- MatchType.DOES_NOT,
55
- StringComparisonType.CONTAINS,
56
- ['Fedex']
57
- );
58
- const result = selector.match(cartDeliveryOption);
59
- expect(result).toEqual(false);
60
- });
61
-
62
- it('is true when it starts with', () => {
63
- const selector = new RateNameSelector(
64
- MatchType.DOES,
65
- StringComparisonType.START_WITH,
66
- ['Fedex']
67
- );
68
- const result = selector.match(cartDeliveryOption);
69
- expect(result).toEqual(true);
70
- });
71
-
72
- it('is true when it does not start with', () => {
73
- const selector = new RateNameSelector(
74
- MatchType.DOES_NOT,
75
- StringComparisonType.START_WITH,
76
- ['UPS']
77
- );
78
- const result = selector.match(cartDeliveryOption);
79
- expect(result).toEqual(true);
80
- });
81
-
82
- it('is true when it contains one of', () => {
83
- const selector = new RateNameSelector(
84
- MatchType.DOES,
85
- StringComparisonType.END_WITH,
86
- ['Shipping']
87
- );
88
- const result = selector.match(cartDeliveryOption);
89
- expect(result).toEqual(true);
90
- });
91
-
92
- it('is true when it contains one of', () => {
93
- const selector = new RateNameSelector(
94
- MatchType.DOES_NOT,
95
- StringComparisonType.END_WITH,
96
- ['Fedex']
97
- );
98
- const result = selector.match(cartDeliveryOption);
99
- expect(result).toEqual(true);
100
- });
101
-
102
- const cartDeliveryOption = {
103
- deliveryMethodType: DeliveryMethod.Shipping,
104
- handle: 'test-handle',
105
- title: 'FedEx - 10% Shipping',
106
- } as CartDeliveryOption;
107
- });