@labdigital/commercetools-mock 2.17.1 → 2.18.1
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/dist/index.cjs +4351 -4099
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +266 -413
- package/dist/index.d.ts +266 -413
- package/dist/index.js +4351 -4099
- package/dist/index.js.map +1 -1
- package/package.json +47 -47
- package/src/constants.ts +2 -2
- package/src/ctMock.test.ts +11 -11
- package/src/ctMock.ts +141 -127
- package/src/deprecation.ts +8 -0
- package/src/exceptions.ts +17 -15
- package/src/helpers.ts +32 -32
- package/src/index.test.ts +128 -128
- package/src/index.ts +3 -3
- package/src/lib/expandParser.ts +13 -13
- package/src/lib/haversine.test.ts +9 -9
- package/src/lib/haversine.ts +11 -11
- package/src/lib/masking.ts +11 -11
- package/src/lib/parser.ts +2 -2
- package/src/lib/password.ts +23 -3
- package/src/lib/predicateParser.test.ts +185 -183
- package/src/lib/predicateParser.ts +234 -234
- package/src/lib/projectionSearchFilter.test.ts +103 -101
- package/src/lib/projectionSearchFilter.ts +152 -150
- package/src/lib/proxy.ts +5 -5
- package/src/oauth/errors.ts +4 -4
- package/src/oauth/helpers.ts +6 -6
- package/src/oauth/server.test.ts +86 -86
- package/src/oauth/server.ts +158 -144
- package/src/oauth/store.ts +44 -43
- package/src/priceSelector.test.ts +35 -35
- package/src/priceSelector.ts +30 -30
- package/src/product-projection-search.ts +136 -134
- package/src/projectAPI.test.ts +7 -7
- package/src/projectAPI.ts +24 -22
- package/src/repositories/abstract.ts +168 -116
- package/src/repositories/associate-role.ts +90 -77
- package/src/repositories/attribute-group.ts +51 -40
- package/src/repositories/business-unit.ts +168 -148
- package/src/repositories/cart/actions.ts +489 -0
- package/src/repositories/cart/helpers.ts +30 -0
- package/src/repositories/cart/index.ts +180 -0
- package/src/repositories/cart-discount/actions.ts +148 -0
- package/src/repositories/cart-discount/index.ts +86 -0
- package/src/repositories/category/actions.ts +231 -0
- package/src/repositories/category/index.ts +52 -0
- package/src/repositories/channel.ts +88 -90
- package/src/repositories/custom-object.ts +46 -45
- package/src/repositories/customer/actions.ts +165 -0
- package/src/repositories/customer/index.ts +79 -0
- package/src/repositories/customer-group.ts +66 -55
- package/src/repositories/discount-code/actions.ts +149 -0
- package/src/repositories/discount-code/index.ts +50 -0
- package/src/repositories/errors.ts +10 -10
- package/src/repositories/extension.ts +64 -62
- package/src/repositories/helpers.ts +117 -118
- package/src/repositories/index.ts +80 -79
- package/src/repositories/inventory-entry/actions.ts +84 -0
- package/src/repositories/inventory-entry/index.ts +44 -0
- package/src/repositories/my-customer.ts +114 -0
- package/src/repositories/my-order.ts +8 -8
- package/src/repositories/order/actions.ts +281 -0
- package/src/repositories/{order.test.ts → order/index.test.ts} +77 -77
- package/src/repositories/order/index.ts +260 -0
- package/src/repositories/order-edit.ts +10 -23
- package/src/repositories/payment/actions.ts +305 -0
- package/src/repositories/payment/helpers.ts +17 -0
- package/src/repositories/payment/index.ts +56 -0
- package/src/repositories/product/actions.ts +943 -0
- package/src/repositories/product/helpers.ts +98 -0
- package/src/repositories/product/index.ts +130 -0
- package/src/repositories/product-discount.ts +127 -117
- package/src/repositories/product-projection.ts +56 -62
- package/src/repositories/product-selection.ts +31 -28
- package/src/repositories/product-type.ts +136 -134
- package/src/repositories/project.ts +133 -118
- package/src/repositories/quote-request.ts +7 -19
- package/src/repositories/quote.ts +7 -22
- package/src/repositories/review.ts +13 -26
- package/src/repositories/shipping-method/actions.ts +198 -0
- package/src/repositories/shipping-method/helpers.ts +10 -0
- package/src/repositories/shipping-method/index.ts +138 -0
- package/src/repositories/shopping-list/actions.ts +295 -0
- package/src/repositories/shopping-list/index.ts +122 -0
- package/src/repositories/staged-quote.ts +7 -20
- package/src/repositories/standalone-price.ts +57 -44
- package/src/repositories/state.ts +113 -68
- package/src/repositories/store.ts +106 -94
- package/src/repositories/subscription.ts +46 -22
- package/src/repositories/tax-category/actions.ts +94 -0
- package/src/repositories/tax-category/helpers.ts +8 -0
- package/src/repositories/tax-category/index.ts +25 -0
- package/src/repositories/type/actions.ts +162 -0
- package/src/repositories/type/index.ts +24 -0
- package/src/repositories/zone.ts +62 -58
- package/src/schemas/update-request.ts +12 -0
- package/src/server.ts +9 -9
- package/src/services/abstract.ts +85 -72
- package/src/services/associate-roles.test.ts +27 -27
- package/src/services/associate-roles.ts +7 -7
- package/src/services/attribute-group.ts +7 -7
- package/src/services/business-units.test.ts +28 -28
- package/src/services/business-units.ts +7 -7
- package/src/services/cart-discount.test.ts +199 -199
- package/src/services/cart-discount.ts +7 -7
- package/src/services/cart.test.ts +261 -261
- package/src/services/cart.ts +22 -21
- package/src/services/category.test.ts +121 -121
- package/src/services/category.ts +7 -7
- package/src/services/channel.ts +7 -7
- package/src/services/custom-object.test.ts +130 -130
- package/src/services/custom-object.ts +34 -31
- package/src/services/customer-group.ts +7 -7
- package/src/services/customer.test.ts +205 -205
- package/src/services/customer.ts +23 -36
- package/src/services/discount-code.ts +7 -7
- package/src/services/extension.ts +7 -7
- package/src/services/index.ts +85 -81
- package/src/services/inventory-entry.test.ts +106 -106
- package/src/services/inventory-entry.ts +7 -7
- package/src/services/my-cart.test.ts +56 -56
- package/src/services/my-cart.ts +20 -20
- package/src/services/my-customer.test.ts +155 -104
- package/src/services/my-customer.ts +66 -75
- package/src/services/my-order.ts +16 -16
- package/src/services/my-payment.test.ts +40 -40
- package/src/services/my-payment.ts +7 -7
- package/src/services/my-shopping-list.ts +7 -7
- package/src/services/order.test.ts +243 -243
- package/src/services/order.ts +23 -18
- package/src/services/payment.test.ts +40 -40
- package/src/services/payment.ts +7 -7
- package/src/services/product-discount.ts +7 -7
- package/src/services/product-projection.test.ts +190 -190
- package/src/services/product-projection.ts +34 -32
- package/src/services/product-selection.test.ts +19 -19
- package/src/services/product-selection.ts +7 -7
- package/src/services/product-type.test.ts +38 -38
- package/src/services/product-type.ts +7 -7
- package/src/services/product.test.ts +658 -656
- package/src/services/product.ts +7 -7
- package/src/services/project.test.ts +29 -24
- package/src/services/project.ts +22 -17
- package/src/services/reviews.ts +7 -7
- package/src/services/shipping-method.test.ts +78 -78
- package/src/services/shipping-method.ts +16 -16
- package/src/services/shopping-list.test.ts +170 -170
- package/src/services/shopping-list.ts +7 -7
- package/src/services/standalone-price.test.ts +112 -112
- package/src/services/standalone-price.ts +7 -7
- package/src/services/state.test.ts +30 -30
- package/src/services/state.ts +7 -7
- package/src/services/store.test.ts +40 -40
- package/src/services/store.ts +7 -7
- package/src/services/subscription.ts +7 -7
- package/src/services/tax-category.test.ts +43 -43
- package/src/services/tax-category.ts +7 -7
- package/src/services/type.ts +7 -7
- package/src/services/zone.ts +7 -7
- package/src/shippingCalculator.test.ts +43 -43
- package/src/shippingCalculator.ts +23 -23
- package/src/storage/abstract.ts +36 -34
- package/src/storage/in-memory.ts +237 -233
- package/src/storage/index.ts +2 -2
- package/src/types.ts +91 -91
- package/src/validate.ts +18 -0
- package/src/repositories/cart-discount.ts +0 -219
- package/src/repositories/cart.ts +0 -659
- package/src/repositories/category.ts +0 -256
- package/src/repositories/customer.ts +0 -228
- package/src/repositories/discount-code.ts +0 -181
- package/src/repositories/inventory-entry.ts +0 -109
- package/src/repositories/order.ts +0 -514
- package/src/repositories/payment.ts +0 -342
- package/src/repositories/product.ts +0 -1106
- package/src/repositories/shipping-method.ts +0 -312
- package/src/repositories/shopping-list.ts +0 -392
- package/src/repositories/tax-category.ts +0 -111
- package/src/repositories/type.ts +0 -172
|
@@ -1,176 +1,178 @@
|
|
|
1
|
-
import type { ProductProjection } from
|
|
2
|
-
import { describe, expect, test } from
|
|
3
|
-
import { cloneObject } from
|
|
4
|
-
import { applyPriceSelector } from
|
|
5
|
-
import { parseFilterExpression } from
|
|
1
|
+
import type { ProductProjection } from "@commercetools/platform-sdk";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
|
+
import { cloneObject } from "../helpers";
|
|
4
|
+
import { applyPriceSelector } from "../priceSelector";
|
|
5
|
+
import { parseFilterExpression } from "./projectionSearchFilter";
|
|
6
6
|
|
|
7
|
-
describe(
|
|
7
|
+
describe("Search filter", () => {
|
|
8
8
|
const exampleProduct: ProductProjection = {
|
|
9
|
-
id:
|
|
9
|
+
id: "7401d82f-1378-47ba-996a-85beeb87ac87",
|
|
10
10
|
version: 2,
|
|
11
|
-
createdAt:
|
|
12
|
-
lastModifiedAt:
|
|
13
|
-
key:
|
|
11
|
+
createdAt: "2022-07-22T10:02:40.851Z",
|
|
12
|
+
lastModifiedAt: "2022-07-22T10:02:44.427Z",
|
|
13
|
+
key: "test-product",
|
|
14
14
|
productType: {
|
|
15
|
-
typeId:
|
|
16
|
-
id:
|
|
15
|
+
typeId: "product-type",
|
|
16
|
+
id: "b9b4b426-938b-4ccb-9f36-c6f933e8446e",
|
|
17
17
|
},
|
|
18
18
|
name: {
|
|
19
|
-
|
|
19
|
+
"nl-NL": "test",
|
|
20
20
|
},
|
|
21
21
|
slug: {
|
|
22
|
-
|
|
22
|
+
"nl-NL": "test",
|
|
23
23
|
},
|
|
24
24
|
variants: [],
|
|
25
25
|
searchKeywords: {},
|
|
26
26
|
categories: [],
|
|
27
27
|
masterVariant: {
|
|
28
28
|
id: 1,
|
|
29
|
-
sku:
|
|
29
|
+
sku: "MYSKU",
|
|
30
30
|
attributes: [
|
|
31
31
|
{
|
|
32
|
-
name:
|
|
32
|
+
name: "Country",
|
|
33
33
|
value: {
|
|
34
|
-
key:
|
|
34
|
+
key: "NL",
|
|
35
35
|
label: {
|
|
36
|
-
de:
|
|
37
|
-
en:
|
|
38
|
-
nl:
|
|
36
|
+
de: "niederlande",
|
|
37
|
+
en: "netherlands",
|
|
38
|
+
nl: "nederland",
|
|
39
39
|
},
|
|
40
40
|
},
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
|
-
name:
|
|
43
|
+
name: "number",
|
|
44
44
|
value: 4,
|
|
45
45
|
},
|
|
46
46
|
],
|
|
47
47
|
prices: [
|
|
48
48
|
{
|
|
49
|
-
id:
|
|
49
|
+
id: "dummy-uuid",
|
|
50
50
|
value: {
|
|
51
|
-
type:
|
|
52
|
-
currencyCode:
|
|
51
|
+
type: "centPrecision",
|
|
52
|
+
currencyCode: "EUR",
|
|
53
53
|
centAmount: 1789,
|
|
54
54
|
fractionDigits: 2,
|
|
55
55
|
},
|
|
56
56
|
},
|
|
57
57
|
],
|
|
58
58
|
},
|
|
59
|
-
}
|
|
59
|
+
};
|
|
60
60
|
|
|
61
61
|
const match = (pattern: string, product?: ProductProjection) => {
|
|
62
|
-
const matchFunc = parseFilterExpression(pattern)
|
|
63
|
-
const clone = cloneObject(product ?? exampleProduct)
|
|
62
|
+
const matchFunc = parseFilterExpression(pattern);
|
|
63
|
+
const clone = cloneObject(product ?? exampleProduct);
|
|
64
64
|
return {
|
|
65
65
|
isMatch: matchFunc(clone, false),
|
|
66
66
|
product: clone,
|
|
67
|
-
}
|
|
68
|
-
}
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
69
|
|
|
70
|
-
test(
|
|
71
|
-
expect(match(`key:exists`).isMatch).toBeTruthy()
|
|
72
|
-
expect(match(`key:missing`).isMatch).toBeFalsy()
|
|
73
|
-
expect(match(`key:"test-product"`).isMatch).toBeTruthy()
|
|
74
|
-
})
|
|
70
|
+
test("by product key", async () => {
|
|
71
|
+
expect(match(`key:exists`).isMatch).toBeTruthy();
|
|
72
|
+
expect(match(`key:missing`).isMatch).toBeFalsy();
|
|
73
|
+
expect(match(`key:"test-product"`).isMatch).toBeTruthy();
|
|
74
|
+
});
|
|
75
75
|
|
|
76
|
-
test(
|
|
76
|
+
test("by product type id", async () => {
|
|
77
77
|
expect(
|
|
78
|
-
match(`productType.id:"b9b4b426-938b-4ccb-9f36-c6f933e8446e"`).isMatch
|
|
79
|
-
).toBeTruthy()
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
test(
|
|
83
|
-
expect(match(`variants.sku:exists`).isMatch).toBeTruthy()
|
|
84
|
-
expect(match(`variants.sku:missing`).isMatch).toBeFalsy()
|
|
85
|
-
expect(match(`variants.sku:"MYSKU"`).isMatch).toBeTruthy()
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
test(
|
|
89
|
-
expect(match(`variants.attributes.number:4`).isMatch).toBeTruthy()
|
|
90
|
-
expect(match(`variants.attributes.number:3,4`).isMatch).toBeTruthy()
|
|
91
|
-
expect(match(`variants.attributes.number:3,4,5`).isMatch).toBeTruthy()
|
|
92
|
-
expect(match(`variants.attributes.number:1,2,3,5`).isMatch).toBeFalsy()
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
test(
|
|
78
|
+
match(`productType.id:"b9b4b426-938b-4ccb-9f36-c6f933e8446e"`).isMatch,
|
|
79
|
+
).toBeTruthy();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("by SKU", async () => {
|
|
83
|
+
expect(match(`variants.sku:exists`).isMatch).toBeTruthy();
|
|
84
|
+
expect(match(`variants.sku:missing`).isMatch).toBeFalsy();
|
|
85
|
+
expect(match(`variants.sku:"MYSKU"`).isMatch).toBeTruthy();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("by attribute value", async () => {
|
|
89
|
+
expect(match(`variants.attributes.number:4`).isMatch).toBeTruthy();
|
|
90
|
+
expect(match(`variants.attributes.number:3,4`).isMatch).toBeTruthy();
|
|
91
|
+
expect(match(`variants.attributes.number:3,4,5`).isMatch).toBeTruthy();
|
|
92
|
+
expect(match(`variants.attributes.number:1,2,3,5`).isMatch).toBeFalsy();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("by attribute range", async () => {
|
|
96
96
|
expect(
|
|
97
|
-
match(`variants.attributes.number:range (0 TO 5)`).isMatch
|
|
98
|
-
).toBeTruthy()
|
|
97
|
+
match(`variants.attributes.number:range (0 TO 5)`).isMatch,
|
|
98
|
+
).toBeTruthy();
|
|
99
99
|
|
|
100
100
|
expect(
|
|
101
|
-
match(`variants.attributes.number:range (* TO 5)`).isMatch
|
|
102
|
-
).toBeTruthy()
|
|
101
|
+
match(`variants.attributes.number:range (* TO 5)`).isMatch,
|
|
102
|
+
).toBeTruthy();
|
|
103
103
|
|
|
104
104
|
expect(
|
|
105
|
-
match(`variants.attributes.number:range (* TO *)`).isMatch
|
|
106
|
-
).toBeTruthy()
|
|
107
|
-
})
|
|
105
|
+
match(`variants.attributes.number:range (* TO *)`).isMatch,
|
|
106
|
+
).toBeTruthy();
|
|
107
|
+
});
|
|
108
108
|
|
|
109
|
-
test(
|
|
110
|
-
expect(match(`variants.attributes.Country.key:"NL"`).isMatch).toBeTruthy()
|
|
111
|
-
expect(match(`variants.attributes.Country.key:"DE"`).isMatch).toBeFalsy()
|
|
112
|
-
})
|
|
109
|
+
test("by attribute enum key", async () => {
|
|
110
|
+
expect(match(`variants.attributes.Country.key:"NL"`).isMatch).toBeTruthy();
|
|
111
|
+
expect(match(`variants.attributes.Country.key:"DE"`).isMatch).toBeFalsy();
|
|
112
|
+
});
|
|
113
113
|
|
|
114
|
-
test(
|
|
115
|
-
expect(match(`variants.attributes.Country.key:"NL"`).isMatch).toBeTruthy()
|
|
116
|
-
expect(match(`variants.attributes.Country.key:"DE"`).isMatch).toBeFalsy()
|
|
117
|
-
})
|
|
114
|
+
test("by attribute enum key", async () => {
|
|
115
|
+
expect(match(`variants.attributes.Country.key:"NL"`).isMatch).toBeTruthy();
|
|
116
|
+
expect(match(`variants.attributes.Country.key:"DE"`).isMatch).toBeFalsy();
|
|
117
|
+
});
|
|
118
118
|
|
|
119
|
-
test(
|
|
119
|
+
test("by price range", async () => {
|
|
120
120
|
expect(
|
|
121
|
-
match(`variants.price.centAmount:range (1500 TO 2000)`).isMatch
|
|
122
|
-
).toBeTruthy()
|
|
123
|
-
})
|
|
121
|
+
match(`variants.price.centAmount:range (1500 TO 2000)`).isMatch,
|
|
122
|
+
).toBeTruthy();
|
|
123
|
+
});
|
|
124
124
|
|
|
125
|
-
test(
|
|
125
|
+
test("by price range - or", async () => {
|
|
126
126
|
expect(
|
|
127
127
|
match(
|
|
128
|
-
`variants.price.centAmount:range (2 TO 1500 ), (1500 TO 3000), (3000 TO 6000)
|
|
129
|
-
).isMatch
|
|
130
|
-
).toBeTruthy()
|
|
131
|
-
})
|
|
128
|
+
`variants.price.centAmount:range (2 TO 1500 ), (1500 TO 3000), (3000 TO 6000)`,
|
|
129
|
+
).isMatch,
|
|
130
|
+
).toBeTruthy();
|
|
131
|
+
});
|
|
132
132
|
|
|
133
|
-
test(
|
|
134
|
-
let result
|
|
135
|
-
let products: ProductProjection[]
|
|
133
|
+
test("by scopedPrice range", async () => {
|
|
134
|
+
let result;
|
|
135
|
+
let products: ProductProjection[];
|
|
136
136
|
|
|
137
137
|
// No currency given
|
|
138
|
-
result = match(
|
|
139
|
-
|
|
138
|
+
result = match(
|
|
139
|
+
`variants.scopedPrice.value.centAmount:range (1500 TO 2000)`,
|
|
140
|
+
);
|
|
141
|
+
expect(result.isMatch).toBeFalsy();
|
|
140
142
|
|
|
141
143
|
// Currency match
|
|
142
|
-
products = [cloneObject(exampleProduct)]
|
|
143
|
-
applyPriceSelector(products, { currency:
|
|
144
|
+
products = [cloneObject(exampleProduct)];
|
|
145
|
+
applyPriceSelector(products, { currency: "EUR" });
|
|
144
146
|
|
|
145
147
|
result = match(
|
|
146
148
|
`variants.scopedPrice.value.centAmount:range (1500 TO 2000)`,
|
|
147
|
-
products[0]
|
|
148
|
-
)
|
|
149
|
-
expect(result.isMatch).toBeTruthy()
|
|
149
|
+
products[0],
|
|
150
|
+
);
|
|
151
|
+
expect(result.isMatch).toBeTruthy();
|
|
150
152
|
expect(result.product).toMatchObject({
|
|
151
153
|
masterVariant: {
|
|
152
|
-
sku:
|
|
154
|
+
sku: "MYSKU",
|
|
153
155
|
scopedPrice: { value: { centAmount: 1789 } },
|
|
154
156
|
},
|
|
155
|
-
})
|
|
157
|
+
});
|
|
156
158
|
|
|
157
159
|
// Currency mismatch
|
|
158
|
-
products = [cloneObject(exampleProduct)]
|
|
159
|
-
applyPriceSelector(products, { currency:
|
|
160
|
+
products = [cloneObject(exampleProduct)];
|
|
161
|
+
applyPriceSelector(products, { currency: "USD" });
|
|
160
162
|
|
|
161
163
|
result = match(
|
|
162
164
|
`variants.scopedPrice.value.centAmount:range (1500 TO 2000)`,
|
|
163
|
-
products[0]
|
|
164
|
-
)
|
|
165
|
-
expect(result.isMatch).toBeFalsy()
|
|
165
|
+
products[0],
|
|
166
|
+
);
|
|
167
|
+
expect(result.isMatch).toBeFalsy();
|
|
166
168
|
|
|
167
169
|
// Price has no country so mismatch
|
|
168
|
-
products = [cloneObject(exampleProduct)]
|
|
169
|
-
applyPriceSelector(products, { currency:
|
|
170
|
+
products = [cloneObject(exampleProduct)];
|
|
171
|
+
applyPriceSelector(products, { currency: "EUR", country: "NL" });
|
|
170
172
|
result = match(
|
|
171
173
|
`variants.scopedPrice.value.centAmount:range (1500 TO 2000)`,
|
|
172
|
-
products[0]
|
|
173
|
-
)
|
|
174
|
-
expect(result.isMatch).toBeFalsy()
|
|
175
|
-
})
|
|
176
|
-
})
|
|
174
|
+
products[0],
|
|
175
|
+
);
|
|
176
|
+
expect(result.isMatch).toBeFalsy();
|
|
177
|
+
});
|
|
178
|
+
});
|