@zoxllc/shopify-checkout-extensions 0.0.2 → 0.0.4
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.
- package/migrate.ts +64 -0
- package/package.json +2 -1
- package/src/common/AndSelector.ts +17 -10
- package/src/common/Campaign.ts +27 -12
- package/src/common/CampaignFactory.ts +103 -51
- package/src/common/CartHasItemQualifier.ts +38 -22
- package/src/common/CartQuantityQualifier.ts +41 -20
- package/src/common/CountryCodeQualifier.ts +49 -0
- package/src/common/CustomerEmailQualifier.ts +14 -7
- package/src/common/CustomerTagQualifier.ts +29 -16
- package/src/common/DiscountCart.ts +78 -54
- package/src/common/DiscountInterface.ts +15 -3
- package/src/common/OrSelector.ts +13 -8
- package/src/common/ProductHandleSelector.ts +5 -3
- package/src/common/ProductIdSelector.ts +10 -4
- package/src/common/ProductTagSelector.ts +19 -10
- package/src/common/ProductTypeSelector.ts +10 -4
- package/src/common/SaleItemSelector.ts +2 -1
- package/src/common/Selector.ts +26 -13
- package/src/common/SubscriptionItemSelector.ts +5 -3
- package/src/index.ts +1 -1
- package/src/{common → lineItem}/BuyXGetY.ts +42 -20
- package/src/lineItem/ConditionalDiscount.ts +1 -1
- package/src/lineItem/FixedItemDiscount.ts +2 -4
- package/src/lineItem/PercentageDiscount.ts +2 -4
- package/src/shipping/FixedDiscount.ts +37 -0
- package/src/shipping/RateNameSelector.ts +54 -0
- package/src/shipping/ShippingDiscount.ts +75 -0
- package/src/shipping/api.ts +2097 -0
- package/tests/AndSelector.test.ts +1 -1
- package/tests/CartQuantityQualifier.test.ts +1 -1
- package/tests/CountryCodeQualifier.test.ts +56 -0
- package/tests/CustomerSubscriberQualifier.test.ts +1 -1
- package/tests/CustomerTagQualifier.test.ts +71 -0
- package/tests/DiscountCart.test.ts +1 -1
- package/tests/OrSelector.test.ts +1 -1
- package/tests/ProductIdSelector.test.ts +83 -0
- package/tests/ProductTagSelector.test.ts +1 -1
- package/tests/Qualifier.test.ts +1 -1
- package/tests/RateNameSelector.test.ts +107 -0
- package/tests/SaleItemSelector.test.ts +1 -1
- package/tests/Selector.test.ts +1 -1
- /package/src/{generated → lineItem}/api.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
2
|
import { DiscountCart } from '../src/common/DiscountCart';
|
|
3
|
-
import { RunInput } from '../src/
|
|
3
|
+
import { RunInput } from '../src/lineItem/api';
|
|
4
4
|
import _ from 'lodash';
|
|
5
5
|
import { NumericalComparisonType } from '../src/common/Qualifier';
|
|
6
6
|
import {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import { CountryCodeQualifier } from '../src/common/CountryCodeQualifier';
|
|
4
|
+
import { QualifierMatchType } from '../src/common/Qualifier';
|
|
5
|
+
import { DiscountCart } from '../src/common/DiscountCart';
|
|
6
|
+
|
|
7
|
+
describe('CountryCodeQualifier', () => {
|
|
8
|
+
it('is true when it matches one of', () => {
|
|
9
|
+
const qualifier = new CountryCodeQualifier(
|
|
10
|
+
QualifierMatchType.DOES,
|
|
11
|
+
['UK', 'AR', 'CA', 'US']
|
|
12
|
+
);
|
|
13
|
+
const result = qualifier.match(discountCart);
|
|
14
|
+
expect(result).toEqual(true);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('is false when subject not found when expected', () => {
|
|
18
|
+
const qualifier = new CountryCodeQualifier(
|
|
19
|
+
QualifierMatchType.DOES,
|
|
20
|
+
['UK', 'AR', 'CA', 'BR']
|
|
21
|
+
);
|
|
22
|
+
const result = qualifier.match(discountCart);
|
|
23
|
+
expect(result).toEqual(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('is true when it does not exist', () => {
|
|
27
|
+
const qualifier = new CountryCodeQualifier(
|
|
28
|
+
QualifierMatchType.DOES_NOT,
|
|
29
|
+
['UK', 'CA']
|
|
30
|
+
);
|
|
31
|
+
const result = qualifier.match(discountCart);
|
|
32
|
+
expect(result).toEqual(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('is false when it does exist and was expected not to', () => {
|
|
36
|
+
const qualifier = new CountryCodeQualifier(
|
|
37
|
+
QualifierMatchType.DOES_NOT,
|
|
38
|
+
['CA', 'AR', 'US', 'BR']
|
|
39
|
+
);
|
|
40
|
+
const result = qualifier.match(discountCart);
|
|
41
|
+
expect(result).toEqual(false);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
const discountCart = {
|
|
46
|
+
cart: {
|
|
47
|
+
deliveryGroups: [
|
|
48
|
+
{
|
|
49
|
+
deliveryAddress: {
|
|
50
|
+
countryCode: 'US',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
} as DiscountCart;
|
|
56
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
2
|
import { DiscountCart } from '../src/common/DiscountCart';
|
|
3
|
-
import { RunInput } from '../src/
|
|
3
|
+
import { RunInput } from '../src/lineItem/api';
|
|
4
4
|
import _ from 'lodash';
|
|
5
5
|
import { CustomerSubscriberQualifier } from '../src/common/CustomerSubscriberQualifier';
|
|
6
6
|
import { QualifierMatchType } from '../src/common/Qualifier';
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import { CustomerTagQualifier } from '../src/common/CustomerTagQualifier';
|
|
4
|
+
import {
|
|
5
|
+
QualifierMatchType,
|
|
6
|
+
StringComparisonType,
|
|
7
|
+
} from '../src/common/Qualifier';
|
|
8
|
+
import { DiscountCart } from '../src/common/DiscountCart';
|
|
9
|
+
|
|
10
|
+
describe('CustomerTagQualifier', () => {
|
|
11
|
+
it('is true when it matches one of', () => {
|
|
12
|
+
const qualifier = new CustomerTagQualifier(
|
|
13
|
+
QualifierMatchType.DOES,
|
|
14
|
+
StringComparisonType.MATCH,
|
|
15
|
+
[
|
|
16
|
+
'tag1',
|
|
17
|
+
'tag2',
|
|
18
|
+
'Active product subscription',
|
|
19
|
+
'TAG4',
|
|
20
|
+
]
|
|
21
|
+
);
|
|
22
|
+
const result = qualifier.match(discountCart);
|
|
23
|
+
expect(result).toEqual(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('is false when it does NOT match one of', () => {
|
|
27
|
+
const qualifier = new CustomerTagQualifier(
|
|
28
|
+
QualifierMatchType.DOES,
|
|
29
|
+
StringComparisonType.MATCH,
|
|
30
|
+
['tag6', 'tag7', 'tag8', 'tag9']
|
|
31
|
+
);
|
|
32
|
+
const result = qualifier.match(discountCart);
|
|
33
|
+
expect(result).toEqual(false);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('is true when it contains one of', () => {
|
|
37
|
+
const qualifier = new CustomerTagQualifier(
|
|
38
|
+
QualifierMatchType.DOES,
|
|
39
|
+
StringComparisonType.CONTAINS,
|
|
40
|
+
['ag', 'product']
|
|
41
|
+
);
|
|
42
|
+
const result = qualifier.match(discountCart);
|
|
43
|
+
expect(result).toEqual(true);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('is false when it does NOT contain one of', () => {
|
|
47
|
+
const qualifier = new CustomerTagQualifier(
|
|
48
|
+
QualifierMatchType.DOES,
|
|
49
|
+
StringComparisonType.CONTAINS,
|
|
50
|
+
['sandwich', 'choir']
|
|
51
|
+
);
|
|
52
|
+
const result = qualifier.match(discountCart);
|
|
53
|
+
expect(result).toEqual(false);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const discountCart = {
|
|
57
|
+
cart: {
|
|
58
|
+
buyerIdentity: {
|
|
59
|
+
customer: {
|
|
60
|
+
hasTags: [
|
|
61
|
+
{
|
|
62
|
+
tag: 'Active product subscription',
|
|
63
|
+
hasTag: true,
|
|
64
|
+
},
|
|
65
|
+
{ tag: 'dev', hasTag: false },
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
} as DiscountCart;
|
|
71
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
2
|
import { DiscountCart } from '../src/common/DiscountCart';
|
|
3
|
-
import { RunInput } from '../src/
|
|
3
|
+
import { RunInput } from '../src/lineItem/api';
|
|
4
4
|
|
|
5
5
|
describe('DiscountCart', () => {
|
|
6
6
|
const discountCart = new DiscountCart(
|
package/tests/OrSelector.test.ts
CHANGED
|
@@ -0,0 +1,83 @@
|
|
|
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,7 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
2
|
import _ from 'lodash';
|
|
3
3
|
import { ProductTagSelector } from '../src/common/ProductTagSelector';
|
|
4
|
-
import { CartLine } from '../src/
|
|
4
|
+
import { CartLine } from '../src/lineItem/api';
|
|
5
5
|
import {
|
|
6
6
|
QualifierMatchType,
|
|
7
7
|
StringComparisonType,
|
package/tests/Qualifier.test.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
Qualifier,
|
|
5
5
|
} from '../src/common/Qualifier';
|
|
6
6
|
import type { DiscountCart } from '../src/common/DiscountCart';
|
|
7
|
-
import type { CartLine } from '../src/
|
|
7
|
+
import type { CartLine } from '../src/lineItem/api';
|
|
8
8
|
import type { Selector } from '../src/common/Selector';
|
|
9
9
|
|
|
10
10
|
export class MockTruthyQualifier extends Qualifier {
|
|
@@ -0,0 +1,107 @@
|
|
|
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
|
+
['edex']
|
|
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
|
+
});
|
package/tests/Selector.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import type { CartLine } from '../src/
|
|
2
|
+
import type { CartLine } from '../src/lineItem/api';
|
|
3
3
|
import { Selector } from '../src/common/Selector';
|
|
4
4
|
import { StringComparisonType } from '../src/common/Qualifier';
|
|
5
5
|
|
|
File without changes
|