@labdigital/commercetools-mock 2.53.0 → 2.53.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.
package/package.json
CHANGED
|
@@ -151,6 +151,45 @@ describe("Predicate filter", () => {
|
|
|
151
151
|
expect(match("numberProperty in (1234)")).toBeTruthy();
|
|
152
152
|
});
|
|
153
153
|
|
|
154
|
+
test("in operator with and clause", async () => {
|
|
155
|
+
expect(
|
|
156
|
+
match("numberProperty in (1234) and stringProperty=:val", {
|
|
157
|
+
val: "foobar",
|
|
158
|
+
}),
|
|
159
|
+
).toBeTruthy();
|
|
160
|
+
expect(
|
|
161
|
+
match("numberProperty in (1234) and stringProperty=:val", {
|
|
162
|
+
val: "other",
|
|
163
|
+
}),
|
|
164
|
+
).toBeFalsy();
|
|
165
|
+
expect(
|
|
166
|
+
match("numberProperty in (1235) and stringProperty=:val", {
|
|
167
|
+
val: "foobar",
|
|
168
|
+
}),
|
|
169
|
+
).toBeFalsy();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("within operator with and clause", async () => {
|
|
173
|
+
expect(
|
|
174
|
+
match(
|
|
175
|
+
"geoLocation within circle(5.121310867198959, 52.09068804569714, 2500) and stringProperty=:val",
|
|
176
|
+
{ val: "foobar" },
|
|
177
|
+
),
|
|
178
|
+
).toBeTruthy();
|
|
179
|
+
expect(
|
|
180
|
+
match(
|
|
181
|
+
"geoLocation within circle(5.121310867198959, 52.09068804569714, 2500) and stringProperty=:val",
|
|
182
|
+
{ val: "other" },
|
|
183
|
+
),
|
|
184
|
+
).toBeFalsy();
|
|
185
|
+
expect(
|
|
186
|
+
match(
|
|
187
|
+
"geoLocation within circle(5.121310867198959, 52.09068804569714, 1000) and stringProperty=:val",
|
|
188
|
+
{ val: "foobar" },
|
|
189
|
+
),
|
|
190
|
+
).toBeFalsy();
|
|
191
|
+
});
|
|
192
|
+
|
|
154
193
|
test("arrayProperty contains all (...)", async () => {
|
|
155
194
|
expect(match(`arrayProperty contains all ("foo", "bar")`)).toBeTruthy();
|
|
156
195
|
expect(
|
|
@@ -88,6 +88,15 @@ const resolveValue = (obj: any, val: TypeSymbol): any => {
|
|
|
88
88
|
throw new PredicateError("Internal error");
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
// variants() includes both masterVariant and variants for predicates
|
|
92
|
+
if (
|
|
93
|
+
val.value === "variants" &&
|
|
94
|
+
obj.masterVariant &&
|
|
95
|
+
obj.variants !== undefined
|
|
96
|
+
) {
|
|
97
|
+
return [obj.masterVariant, ...(obj.variants ?? [])];
|
|
98
|
+
}
|
|
99
|
+
|
|
91
100
|
if (!(val.value in obj)) {
|
|
92
101
|
if (Array.isArray(obj)) {
|
|
93
102
|
return Object.values(obj)
|
|
@@ -230,7 +239,7 @@ const generateMatchFunc = (predicate: string): MatchFunc => {
|
|
|
230
239
|
|
|
231
240
|
.led("AND", 5, ({ left, bp }) => {
|
|
232
241
|
const expr = parser.parse({ terminals: [bp - 1] });
|
|
233
|
-
return (obj: any) => left(obj) && expr(obj);
|
|
242
|
+
return (obj: any, vars: object) => left(obj, vars) && expr(obj, vars);
|
|
234
243
|
})
|
|
235
244
|
.led("OR", 5, ({ left, token, bp }) => {
|
|
236
245
|
const expr = parser.parse({ terminals: [bp - 1] });
|
|
@@ -373,6 +382,7 @@ const generateMatchFunc = (predicate: string): MatchFunc => {
|
|
|
373
382
|
})
|
|
374
383
|
.led("IN", 20, ({ left, bp }) => {
|
|
375
384
|
const expr = parser.parse({ terminals: [bp - 1] });
|
|
385
|
+
lexer.expect(")");
|
|
376
386
|
return (obj: any, vars: object) => {
|
|
377
387
|
let symbols = expr;
|
|
378
388
|
if (!Array.isArray(symbols)) {
|
|
@@ -417,6 +427,7 @@ const generateMatchFunc = (predicate: string): MatchFunc => {
|
|
|
417
427
|
|
|
418
428
|
lexer.expect("(");
|
|
419
429
|
const expr = parser.parse({ terminals: [")"] });
|
|
430
|
+
lexer.expect(")");
|
|
420
431
|
|
|
421
432
|
return (obj: any, vars: object) => {
|
|
422
433
|
const value = resolveValue(obj, left);
|
|
@@ -97,6 +97,10 @@ beforeEach(async () => {
|
|
|
97
97
|
name: "number",
|
|
98
98
|
value: 4 as any,
|
|
99
99
|
},
|
|
100
|
+
{
|
|
101
|
+
name: "store",
|
|
102
|
+
value: ["test-store"],
|
|
103
|
+
},
|
|
100
104
|
],
|
|
101
105
|
},
|
|
102
106
|
variants: [
|
|
@@ -252,6 +256,30 @@ describe("Product Projection Query - Generic", () => {
|
|
|
252
256
|
}
|
|
253
257
|
});
|
|
254
258
|
|
|
259
|
+
test("Filter on complex query", async () => {
|
|
260
|
+
{
|
|
261
|
+
const response = await supertest(ctMock.app)
|
|
262
|
+
.get("/dummy/product-projections")
|
|
263
|
+
.query({
|
|
264
|
+
limit: 50,
|
|
265
|
+
where: [
|
|
266
|
+
'slug(nl-NL=:slug) and variants(attributes(name="store" and value="test-store"))',
|
|
267
|
+
],
|
|
268
|
+
"var.slug": "test-product",
|
|
269
|
+
"var.store": "test-store",
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
const result: ProductProjectionPagedSearchResponse = response.body;
|
|
273
|
+
expect(result).toEqual({
|
|
274
|
+
count: 1,
|
|
275
|
+
limit: 50,
|
|
276
|
+
offset: 0,
|
|
277
|
+
total: 1,
|
|
278
|
+
results: [productProjection],
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
|
|
255
283
|
test("Filter on invalid slug", async () => {
|
|
256
284
|
{
|
|
257
285
|
const response = await supertest(ctMock.app)
|