@labdigital/commercetools-mock 2.17.1 → 2.18.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.
- package/dist/index.cjs +4186 -3974
- 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 +4186 -3974
- package/dist/index.js.map +1 -1
- package/package.json +44 -46
- 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/server.ts +9 -9
- package/src/services/abstract.ts +75 -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 +61 -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 +24 -24
- package/src/services/project.ts +17 -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/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
|
@@ -5,156 +5,156 @@ import type {
|
|
|
5
5
|
ProductProjectionPagedSearchResponse,
|
|
6
6
|
ProductType,
|
|
7
7
|
ProductTypeDraft,
|
|
8
|
-
} from
|
|
9
|
-
import supertest from
|
|
10
|
-
import * as timekeeper from
|
|
11
|
-
import { afterEach, beforeEach, describe, expect, test } from
|
|
12
|
-
import { CommercetoolsMock } from
|
|
13
|
-
import { Writable } from
|
|
8
|
+
} from "@commercetools/platform-sdk";
|
|
9
|
+
import supertest from "supertest";
|
|
10
|
+
import * as timekeeper from "timekeeper";
|
|
11
|
+
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
12
|
+
import { CommercetoolsMock } from "../index";
|
|
13
|
+
import { Writable } from "../types";
|
|
14
14
|
|
|
15
|
-
const ctMock = new CommercetoolsMock()
|
|
15
|
+
const ctMock = new CommercetoolsMock();
|
|
16
16
|
|
|
17
|
-
let productType: ProductType
|
|
18
|
-
let productProjection: ProductProjection
|
|
19
|
-
let publishedProduct: Product
|
|
20
|
-
let unpublishedProduct: Product
|
|
17
|
+
let productType: ProductType;
|
|
18
|
+
let productProjection: ProductProjection;
|
|
19
|
+
let publishedProduct: Product;
|
|
20
|
+
let unpublishedProduct: Product;
|
|
21
21
|
|
|
22
22
|
beforeEach(async () => {
|
|
23
|
-
timekeeper.freeze(new Date(
|
|
23
|
+
timekeeper.freeze(new Date("2022-07-22T13:31:49.840Z"));
|
|
24
24
|
|
|
25
25
|
// Create the product type
|
|
26
26
|
{
|
|
27
27
|
const draft: ProductTypeDraft = {
|
|
28
|
-
name:
|
|
29
|
-
description:
|
|
30
|
-
}
|
|
28
|
+
name: "Default Product Type",
|
|
29
|
+
description: "Product type for testing",
|
|
30
|
+
};
|
|
31
31
|
const response = await supertest(ctMock.app)
|
|
32
|
-
.post(
|
|
33
|
-
.send(draft)
|
|
32
|
+
.post("/dummy/product-types")
|
|
33
|
+
.send(draft);
|
|
34
34
|
|
|
35
|
-
expect(response.ok).toBe(true)
|
|
36
|
-
productType = response.body
|
|
35
|
+
expect(response.ok).toBe(true);
|
|
36
|
+
productType = response.body;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// Create an unpublished product
|
|
40
40
|
{
|
|
41
41
|
const productDraft: Writable<ProductDraft> = {
|
|
42
42
|
publish: false,
|
|
43
|
-
key:
|
|
43
|
+
key: "my-unpublished-product",
|
|
44
44
|
masterVariant: {
|
|
45
|
-
sku:
|
|
45
|
+
sku: "my-unpub-sku",
|
|
46
46
|
prices: [
|
|
47
47
|
{
|
|
48
48
|
value: {
|
|
49
|
-
currencyCode:
|
|
49
|
+
currencyCode: "EUR",
|
|
50
50
|
centAmount: 189,
|
|
51
51
|
},
|
|
52
52
|
},
|
|
53
53
|
],
|
|
54
54
|
attributes: [
|
|
55
55
|
{
|
|
56
|
-
name:
|
|
56
|
+
name: "number",
|
|
57
57
|
value: 1 as any,
|
|
58
58
|
},
|
|
59
59
|
],
|
|
60
60
|
},
|
|
61
61
|
name: {
|
|
62
|
-
|
|
62
|
+
"nl-NL": "test unpublished product",
|
|
63
63
|
},
|
|
64
64
|
productType: {
|
|
65
|
-
typeId:
|
|
65
|
+
typeId: "product-type",
|
|
66
66
|
id: productType.id,
|
|
67
67
|
},
|
|
68
68
|
slug: {
|
|
69
|
-
|
|
69
|
+
"nl-NL": "test-unpublished-product",
|
|
70
70
|
},
|
|
71
|
-
}
|
|
71
|
+
};
|
|
72
72
|
|
|
73
73
|
const response = await supertest(ctMock.app)
|
|
74
|
-
.post(
|
|
75
|
-
.send(productDraft)
|
|
76
|
-
expect(response.ok).toBe(true)
|
|
77
|
-
unpublishedProduct = response.body
|
|
74
|
+
.post("/dummy/products")
|
|
75
|
+
.send(productDraft);
|
|
76
|
+
expect(response.ok).toBe(true);
|
|
77
|
+
unpublishedProduct = response.body;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
// Create a published product
|
|
81
81
|
{
|
|
82
82
|
const productDraft: Writable<ProductDraft> = {
|
|
83
83
|
publish: true,
|
|
84
|
-
key:
|
|
84
|
+
key: "my-product-key",
|
|
85
85
|
masterVariant: {
|
|
86
|
-
sku:
|
|
86
|
+
sku: "my-sku",
|
|
87
87
|
prices: [
|
|
88
88
|
{
|
|
89
89
|
value: {
|
|
90
|
-
currencyCode:
|
|
90
|
+
currencyCode: "EUR",
|
|
91
91
|
centAmount: 1789,
|
|
92
92
|
},
|
|
93
93
|
},
|
|
94
94
|
],
|
|
95
95
|
attributes: [
|
|
96
96
|
{
|
|
97
|
-
name:
|
|
97
|
+
name: "number",
|
|
98
98
|
value: 4 as any,
|
|
99
99
|
},
|
|
100
100
|
],
|
|
101
101
|
},
|
|
102
102
|
variants: [
|
|
103
103
|
{
|
|
104
|
-
sku:
|
|
104
|
+
sku: "my-other-sku",
|
|
105
105
|
prices: [
|
|
106
106
|
{
|
|
107
107
|
value: {
|
|
108
|
-
currencyCode:
|
|
108
|
+
currencyCode: "EUR",
|
|
109
109
|
centAmount: 91789,
|
|
110
110
|
},
|
|
111
111
|
},
|
|
112
112
|
],
|
|
113
113
|
attributes: [
|
|
114
114
|
{
|
|
115
|
-
name:
|
|
115
|
+
name: "number",
|
|
116
116
|
value: 50 as any,
|
|
117
117
|
},
|
|
118
118
|
],
|
|
119
119
|
},
|
|
120
120
|
],
|
|
121
121
|
name: {
|
|
122
|
-
|
|
122
|
+
"nl-NL": "test product",
|
|
123
123
|
},
|
|
124
124
|
productType: {
|
|
125
|
-
typeId:
|
|
125
|
+
typeId: "product-type",
|
|
126
126
|
id: productType.id,
|
|
127
127
|
},
|
|
128
128
|
slug: {
|
|
129
|
-
|
|
129
|
+
"nl-NL": "test-product",
|
|
130
130
|
},
|
|
131
|
-
}
|
|
131
|
+
};
|
|
132
132
|
|
|
133
133
|
const response = await supertest(ctMock.app)
|
|
134
|
-
.post(
|
|
135
|
-
.send(productDraft)
|
|
136
|
-
expect(response.ok).toBe(true)
|
|
137
|
-
const product = response.body
|
|
138
|
-
publishedProduct = response.body
|
|
134
|
+
.post("/dummy/products")
|
|
135
|
+
.send(productDraft);
|
|
136
|
+
expect(response.ok).toBe(true);
|
|
137
|
+
const product = response.body;
|
|
138
|
+
publishedProduct = response.body;
|
|
139
139
|
|
|
140
140
|
// Create the expected ProductProjection object
|
|
141
141
|
productProjection = {
|
|
142
142
|
id: product.id,
|
|
143
|
-
createdAt:
|
|
144
|
-
lastModifiedAt:
|
|
143
|
+
createdAt: "2022-07-22T13:31:49.840Z",
|
|
144
|
+
lastModifiedAt: "2022-07-22T13:31:49.840Z",
|
|
145
145
|
version: 1,
|
|
146
|
-
key:
|
|
146
|
+
key: "my-product-key",
|
|
147
147
|
published: true,
|
|
148
148
|
hasStagedChanges: false,
|
|
149
149
|
masterVariant: {
|
|
150
150
|
id: 1,
|
|
151
|
-
sku:
|
|
151
|
+
sku: "my-sku",
|
|
152
152
|
prices: [
|
|
153
153
|
{
|
|
154
154
|
id: product.masterData.current.masterVariant.prices[0].id,
|
|
155
155
|
value: {
|
|
156
|
-
type:
|
|
157
|
-
currencyCode:
|
|
156
|
+
type: "centPrecision",
|
|
157
|
+
currencyCode: "EUR",
|
|
158
158
|
centAmount: 1789,
|
|
159
159
|
fractionDigits: 2,
|
|
160
160
|
},
|
|
@@ -167,13 +167,13 @@ beforeEach(async () => {
|
|
|
167
167
|
variants: [
|
|
168
168
|
{
|
|
169
169
|
id: 2,
|
|
170
|
-
sku:
|
|
170
|
+
sku: "my-other-sku",
|
|
171
171
|
prices: [
|
|
172
172
|
{
|
|
173
173
|
id: product.masterData.current.variants[0].prices[0].id,
|
|
174
174
|
value: {
|
|
175
|
-
type:
|
|
176
|
-
currencyCode:
|
|
175
|
+
type: "centPrecision",
|
|
176
|
+
currencyCode: "EUR",
|
|
177
177
|
centAmount: 91789,
|
|
178
178
|
fractionDigits: 2,
|
|
179
179
|
},
|
|
@@ -188,103 +188,103 @@ beforeEach(async () => {
|
|
|
188
188
|
slug: productDraft.slug,
|
|
189
189
|
categories: [],
|
|
190
190
|
productType: {
|
|
191
|
-
typeId:
|
|
191
|
+
typeId: "product-type",
|
|
192
192
|
id: productType.id,
|
|
193
193
|
},
|
|
194
|
-
}
|
|
194
|
+
};
|
|
195
195
|
}
|
|
196
|
-
})
|
|
196
|
+
});
|
|
197
197
|
|
|
198
198
|
afterEach(async () => {
|
|
199
|
-
timekeeper.reset()
|
|
200
|
-
ctMock.clear()
|
|
201
|
-
})
|
|
199
|
+
timekeeper.reset();
|
|
200
|
+
ctMock.clear();
|
|
201
|
+
});
|
|
202
202
|
// Test the general product projection implementation
|
|
203
|
-
describe(
|
|
204
|
-
test(
|
|
203
|
+
describe("Product Projection Get By ID", () => {
|
|
204
|
+
test("Get By ID", async () => {
|
|
205
205
|
const response = await supertest(ctMock.app).get(
|
|
206
|
-
`/dummy/product-projections/${publishedProduct.id}
|
|
207
|
-
)
|
|
206
|
+
`/dummy/product-projections/${publishedProduct.id}`,
|
|
207
|
+
);
|
|
208
208
|
|
|
209
|
-
const result: ProductProjection = response.body
|
|
210
|
-
expect(result).toBeDefined()
|
|
211
|
-
expect(result.id).toBe(publishedProduct.id)
|
|
212
|
-
})
|
|
213
|
-
})
|
|
209
|
+
const result: ProductProjection = response.body;
|
|
210
|
+
expect(result).toBeDefined();
|
|
211
|
+
expect(result.id).toBe(publishedProduct.id);
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
214
|
|
|
215
215
|
// Test the general product projection implementation
|
|
216
|
-
describe(
|
|
217
|
-
test(
|
|
216
|
+
describe("Product Projection Query - Generic", () => {
|
|
217
|
+
test("Filter out staged", async () => {
|
|
218
218
|
const response = await supertest(ctMock.app)
|
|
219
|
-
.get(
|
|
219
|
+
.get("/dummy/product-projections")
|
|
220
220
|
.query({
|
|
221
221
|
limit: 50,
|
|
222
|
-
})
|
|
222
|
+
});
|
|
223
223
|
|
|
224
|
-
const result: ProductProjectionPagedSearchResponse = response.body
|
|
224
|
+
const result: ProductProjectionPagedSearchResponse = response.body;
|
|
225
225
|
expect(result).toEqual({
|
|
226
226
|
count: 1,
|
|
227
227
|
limit: 50,
|
|
228
228
|
offset: 0,
|
|
229
229
|
total: 1,
|
|
230
230
|
results: [productProjection],
|
|
231
|
-
})
|
|
232
|
-
})
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
233
|
|
|
234
|
-
test(
|
|
234
|
+
test("Filter on valid slug", async () => {
|
|
235
235
|
{
|
|
236
236
|
const response = await supertest(ctMock.app)
|
|
237
|
-
.get(
|
|
237
|
+
.get("/dummy/product-projections")
|
|
238
238
|
.query({
|
|
239
|
-
limit: 50,
|
|
240
|
-
where: [
|
|
241
|
-
|
|
242
|
-
})
|
|
239
|
+
"limit": 50,
|
|
240
|
+
"where": ["slug(nl-NL=:slug)"],
|
|
241
|
+
"var.slug": "test-product",
|
|
242
|
+
});
|
|
243
243
|
|
|
244
|
-
const result: ProductProjectionPagedSearchResponse = response.body
|
|
244
|
+
const result: ProductProjectionPagedSearchResponse = response.body;
|
|
245
245
|
expect(result).toEqual({
|
|
246
246
|
count: 1,
|
|
247
247
|
limit: 50,
|
|
248
248
|
offset: 0,
|
|
249
249
|
total: 1,
|
|
250
250
|
results: [productProjection],
|
|
251
|
-
})
|
|
251
|
+
});
|
|
252
252
|
}
|
|
253
|
-
})
|
|
253
|
+
});
|
|
254
254
|
|
|
255
|
-
test(
|
|
255
|
+
test("Filter on invalid slug", async () => {
|
|
256
256
|
{
|
|
257
257
|
const response = await supertest(ctMock.app)
|
|
258
|
-
.get(
|
|
258
|
+
.get("/dummy/product-projections")
|
|
259
259
|
.query({
|
|
260
|
-
limit: 50,
|
|
261
|
-
where: [
|
|
262
|
-
|
|
263
|
-
})
|
|
260
|
+
"limit": 50,
|
|
261
|
+
"where": ["slug(nl-NL=:slug)"],
|
|
262
|
+
"var.slug": "missing-product",
|
|
263
|
+
});
|
|
264
264
|
|
|
265
|
-
const result: ProductProjectionPagedSearchResponse = response.body
|
|
265
|
+
const result: ProductProjectionPagedSearchResponse = response.body;
|
|
266
266
|
expect(result).toEqual({
|
|
267
267
|
count: 0,
|
|
268
268
|
limit: 50,
|
|
269
269
|
offset: 0,
|
|
270
270
|
total: 0,
|
|
271
271
|
results: [],
|
|
272
|
-
})
|
|
272
|
+
});
|
|
273
273
|
}
|
|
274
|
-
})
|
|
275
|
-
})
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
276
|
|
|
277
277
|
// Test the general product projection implementation
|
|
278
|
-
describe(
|
|
279
|
-
test(
|
|
278
|
+
describe("Product Projection Search - Generic", () => {
|
|
279
|
+
test("Pagination", async () => {
|
|
280
280
|
{
|
|
281
281
|
const response = await supertest(ctMock.app)
|
|
282
|
-
.get(
|
|
282
|
+
.get("/dummy/product-projections/search")
|
|
283
283
|
.query({
|
|
284
284
|
limit: 50,
|
|
285
|
-
})
|
|
285
|
+
});
|
|
286
286
|
|
|
287
|
-
const result: ProductProjectionPagedSearchResponse = response.body
|
|
287
|
+
const result: ProductProjectionPagedSearchResponse = response.body;
|
|
288
288
|
expect(result).toEqual({
|
|
289
289
|
count: 1,
|
|
290
290
|
limit: 50,
|
|
@@ -292,17 +292,17 @@ describe('Product Projection Search - Generic', () => {
|
|
|
292
292
|
total: 1,
|
|
293
293
|
facets: {},
|
|
294
294
|
results: [productProjection],
|
|
295
|
-
})
|
|
295
|
+
});
|
|
296
296
|
}
|
|
297
297
|
{
|
|
298
298
|
const response = await supertest(ctMock.app)
|
|
299
|
-
.get(
|
|
299
|
+
.get("/dummy/product-projections/search")
|
|
300
300
|
.query({
|
|
301
301
|
limit: 50,
|
|
302
302
|
offset: 50,
|
|
303
|
-
})
|
|
303
|
+
});
|
|
304
304
|
|
|
305
|
-
const projection: ProductProjection = response.body
|
|
305
|
+
const projection: ProductProjection = response.body;
|
|
306
306
|
expect(projection).toEqual({
|
|
307
307
|
count: 1,
|
|
308
308
|
limit: 50,
|
|
@@ -310,20 +310,20 @@ describe('Product Projection Search - Generic', () => {
|
|
|
310
310
|
total: 0,
|
|
311
311
|
facets: {},
|
|
312
312
|
results: [],
|
|
313
|
-
})
|
|
313
|
+
});
|
|
314
314
|
}
|
|
315
|
-
})
|
|
315
|
+
});
|
|
316
316
|
|
|
317
|
-
test(
|
|
317
|
+
test("Search - unpublished", async () => {
|
|
318
318
|
{
|
|
319
319
|
const response = await supertest(ctMock.app)
|
|
320
|
-
.get(
|
|
320
|
+
.get("/dummy/product-projections/search")
|
|
321
321
|
.query({
|
|
322
322
|
limit: 50,
|
|
323
323
|
staged: true,
|
|
324
|
-
})
|
|
324
|
+
});
|
|
325
325
|
|
|
326
|
-
const result: ProductProjectionPagedSearchResponse = response.body
|
|
326
|
+
const result: ProductProjectionPagedSearchResponse = response.body;
|
|
327
327
|
|
|
328
328
|
expect(result).toMatchObject({
|
|
329
329
|
count: 2,
|
|
@@ -335,97 +335,97 @@ describe('Product Projection Search - Generic', () => {
|
|
|
335
335
|
{ id: unpublishedProduct.id, published: false },
|
|
336
336
|
{ id: publishedProduct.id, published: true },
|
|
337
337
|
],
|
|
338
|
-
})
|
|
338
|
+
});
|
|
339
339
|
}
|
|
340
|
-
})
|
|
340
|
+
});
|
|
341
341
|
|
|
342
|
-
test(
|
|
342
|
+
test("Get 404 when not found by key with expand", async () => {
|
|
343
343
|
const response = await supertest(ctMock.app)
|
|
344
|
-
.get(
|
|
344
|
+
.get("/dummy/product-projections/key=DOESNOTEXIST")
|
|
345
345
|
.query({
|
|
346
|
-
expand: [
|
|
347
|
-
})
|
|
346
|
+
expand: ["categories[*]"],
|
|
347
|
+
});
|
|
348
348
|
|
|
349
|
-
expect(response.status).toBe(404)
|
|
350
|
-
})
|
|
351
|
-
})
|
|
349
|
+
expect(response.status).toBe(404);
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
352
|
|
|
353
|
-
describe(
|
|
354
|
-
test(
|
|
353
|
+
describe("Product Projection Search - Filters", () => {
|
|
354
|
+
test("variants.sku", async () => {
|
|
355
355
|
const response = await supertest(ctMock.app)
|
|
356
|
-
.get(
|
|
356
|
+
.get("/dummy/product-projections/search")
|
|
357
357
|
.query({
|
|
358
358
|
filter: ['variants.sku:"my-sku"'],
|
|
359
|
-
})
|
|
359
|
+
});
|
|
360
360
|
|
|
361
|
-
const result: ProductProjectionPagedSearchResponse = response.body
|
|
361
|
+
const result: ProductProjectionPagedSearchResponse = response.body;
|
|
362
362
|
expect(result).toMatchObject({
|
|
363
363
|
count: 1,
|
|
364
364
|
results: [
|
|
365
365
|
{
|
|
366
|
-
masterVariant: { sku:
|
|
366
|
+
masterVariant: { sku: "my-sku" },
|
|
367
367
|
},
|
|
368
368
|
],
|
|
369
|
-
})
|
|
370
|
-
})
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
371
|
|
|
372
|
-
test(
|
|
372
|
+
test("variants.attributes.range - match", async () => {
|
|
373
373
|
const response = await supertest(ctMock.app)
|
|
374
|
-
.get(
|
|
374
|
+
.get("/dummy/product-projections/search")
|
|
375
375
|
.query({
|
|
376
|
-
filter: [
|
|
377
|
-
})
|
|
376
|
+
filter: ["variants.attributes.number:range(0 TO 10)"],
|
|
377
|
+
});
|
|
378
378
|
|
|
379
|
-
const result: ProductProjectionPagedSearchResponse = response.body
|
|
379
|
+
const result: ProductProjectionPagedSearchResponse = response.body;
|
|
380
380
|
expect(result).toMatchObject({
|
|
381
381
|
count: 1,
|
|
382
382
|
results: [
|
|
383
383
|
{
|
|
384
|
-
masterVariant: { sku:
|
|
384
|
+
masterVariant: { sku: "my-sku" },
|
|
385
385
|
},
|
|
386
386
|
],
|
|
387
|
-
})
|
|
388
|
-
})
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
389
|
|
|
390
|
-
test(
|
|
390
|
+
test("variants.attributes.range - mismatch", async () => {
|
|
391
391
|
const response = await supertest(ctMock.app)
|
|
392
|
-
.get(
|
|
392
|
+
.get("/dummy/product-projections/search")
|
|
393
393
|
.query({
|
|
394
|
-
filter: [
|
|
395
|
-
})
|
|
394
|
+
filter: ["variants.attributes.number:range(5 TO 10)"],
|
|
395
|
+
});
|
|
396
396
|
|
|
397
|
-
const result: ProductProjectionPagedSearchResponse = response.body
|
|
397
|
+
const result: ProductProjectionPagedSearchResponse = response.body;
|
|
398
398
|
expect(result).toMatchObject({
|
|
399
399
|
count: 0,
|
|
400
400
|
results: [],
|
|
401
|
-
})
|
|
402
|
-
})
|
|
403
|
-
})
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
404
|
|
|
405
|
-
describe(
|
|
406
|
-
test(
|
|
405
|
+
describe("Product Projection Search - Facets", () => {
|
|
406
|
+
test("termExpr - variants.attributes.number", async () => {
|
|
407
407
|
const response = await supertest(ctMock.app)
|
|
408
|
-
.get(
|
|
408
|
+
.get("/dummy/product-projections/search")
|
|
409
409
|
.query({
|
|
410
|
-
facet: [
|
|
411
|
-
})
|
|
410
|
+
facet: ["variants.attributes.number"],
|
|
411
|
+
});
|
|
412
412
|
|
|
413
|
-
const result: ProductProjectionPagedSearchResponse = response.body
|
|
413
|
+
const result: ProductProjectionPagedSearchResponse = response.body;
|
|
414
414
|
expect(result).toMatchObject({
|
|
415
415
|
count: 1,
|
|
416
416
|
facets: {
|
|
417
|
-
|
|
418
|
-
type:
|
|
419
|
-
dataType:
|
|
417
|
+
"variants.attributes.number": {
|
|
418
|
+
type: "terms",
|
|
419
|
+
dataType: "text",
|
|
420
420
|
missing: 0,
|
|
421
421
|
total: 2,
|
|
422
422
|
terms: [
|
|
423
423
|
{
|
|
424
|
-
term:
|
|
424
|
+
term: "4.0",
|
|
425
425
|
count: 1,
|
|
426
426
|
},
|
|
427
427
|
{
|
|
428
|
-
term:
|
|
428
|
+
term: "50.0",
|
|
429
429
|
count: 1,
|
|
430
430
|
},
|
|
431
431
|
],
|
|
@@ -433,59 +433,59 @@ describe('Product Projection Search - Facets', () => {
|
|
|
433
433
|
},
|
|
434
434
|
results: [
|
|
435
435
|
{
|
|
436
|
-
masterVariant: { sku:
|
|
436
|
+
masterVariant: { sku: "my-sku" },
|
|
437
437
|
},
|
|
438
438
|
],
|
|
439
|
-
})
|
|
440
|
-
})
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
441
|
|
|
442
|
-
test(
|
|
442
|
+
test("filterExpr - variants.attributes.number", async () => {
|
|
443
443
|
const response = await supertest(ctMock.app)
|
|
444
|
-
.get(
|
|
444
|
+
.get("/dummy/product-projections/search")
|
|
445
445
|
.query({
|
|
446
|
-
facet: [
|
|
447
|
-
})
|
|
446
|
+
facet: ["variants.attributes.number:3,4"],
|
|
447
|
+
});
|
|
448
448
|
|
|
449
|
-
const result: ProductProjectionPagedSearchResponse = response.body
|
|
449
|
+
const result: ProductProjectionPagedSearchResponse = response.body;
|
|
450
450
|
expect(result).toMatchObject({
|
|
451
451
|
count: 1,
|
|
452
452
|
facets: {
|
|
453
|
-
|
|
454
|
-
type:
|
|
453
|
+
"variants.attributes.number": {
|
|
454
|
+
type: "filter",
|
|
455
455
|
count: 1,
|
|
456
456
|
},
|
|
457
457
|
},
|
|
458
458
|
results: [
|
|
459
459
|
{
|
|
460
|
-
masterVariant: { sku:
|
|
460
|
+
masterVariant: { sku: "my-sku" },
|
|
461
461
|
},
|
|
462
462
|
],
|
|
463
|
-
})
|
|
464
|
-
})
|
|
463
|
+
});
|
|
464
|
+
});
|
|
465
465
|
|
|
466
|
-
test(
|
|
466
|
+
test("rangeExpr - variants.attributes.number", async () => {
|
|
467
467
|
const response = await supertest(ctMock.app)
|
|
468
|
-
.get(
|
|
468
|
+
.get("/dummy/product-projections/search")
|
|
469
469
|
.query({
|
|
470
470
|
facet: [
|
|
471
|
-
|
|
471
|
+
"variants.attributes.number:range(* TO 5), (5 TO 25), (25 TO 100)",
|
|
472
472
|
],
|
|
473
|
-
})
|
|
473
|
+
});
|
|
474
474
|
|
|
475
|
-
const result: ProductProjectionPagedSearchResponse = response.body
|
|
475
|
+
const result: ProductProjectionPagedSearchResponse = response.body;
|
|
476
476
|
expect(result).toMatchObject({
|
|
477
477
|
count: 1,
|
|
478
478
|
facets: {
|
|
479
|
-
|
|
480
|
-
type:
|
|
481
|
-
dataType:
|
|
479
|
+
"variants.attributes.number": {
|
|
480
|
+
type: "range",
|
|
481
|
+
dataType: "number",
|
|
482
482
|
ranges: [
|
|
483
483
|
{
|
|
484
|
-
type:
|
|
484
|
+
type: "double",
|
|
485
485
|
from: 0.0,
|
|
486
|
-
fromStr:
|
|
486
|
+
fromStr: "",
|
|
487
487
|
to: 5.0,
|
|
488
|
-
toStr:
|
|
488
|
+
toStr: "5.0",
|
|
489
489
|
count: 1,
|
|
490
490
|
// totalCount: 1,
|
|
491
491
|
total: 4.0,
|
|
@@ -494,11 +494,11 @@ describe('Product Projection Search - Facets', () => {
|
|
|
494
494
|
mean: 4.0,
|
|
495
495
|
},
|
|
496
496
|
{
|
|
497
|
-
type:
|
|
497
|
+
type: "double",
|
|
498
498
|
from: 5.0,
|
|
499
|
-
fromStr:
|
|
499
|
+
fromStr: "5.0",
|
|
500
500
|
to: 25.0,
|
|
501
|
-
toStr:
|
|
501
|
+
toStr: "25.0",
|
|
502
502
|
count: 0,
|
|
503
503
|
// totalCount: 0,
|
|
504
504
|
total: 0.0,
|
|
@@ -507,11 +507,11 @@ describe('Product Projection Search - Facets', () => {
|
|
|
507
507
|
mean: 0.0,
|
|
508
508
|
},
|
|
509
509
|
{
|
|
510
|
-
type:
|
|
510
|
+
type: "double",
|
|
511
511
|
from: 25.0,
|
|
512
|
-
fromStr:
|
|
512
|
+
fromStr: "25.0",
|
|
513
513
|
to: 100.0,
|
|
514
|
-
toStr:
|
|
514
|
+
toStr: "100.0",
|
|
515
515
|
count: 1,
|
|
516
516
|
// totalCount: 1,
|
|
517
517
|
total: 50,
|
|
@@ -524,9 +524,9 @@ describe('Product Projection Search - Facets', () => {
|
|
|
524
524
|
},
|
|
525
525
|
results: [
|
|
526
526
|
{
|
|
527
|
-
masterVariant: { sku:
|
|
527
|
+
masterVariant: { sku: "my-sku" },
|
|
528
528
|
},
|
|
529
529
|
],
|
|
530
|
-
})
|
|
531
|
-
})
|
|
532
|
-
})
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
});
|