@labdigital/commercetools-mock 2.45.1 → 2.47.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 +614 -250
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +788 -59
- package/dist/index.d.ts +788 -59
- package/dist/index.js +602 -238
- package/dist/index.js.map +1 -1
- package/package.json +41 -48
- package/src/ctMock.ts +11 -13
- package/src/index.test.ts +5 -5
- package/src/lib/predicateParser.test.ts +91 -60
- package/src/lib/predicateParser.ts +38 -42
- package/src/lib/productSearchFilter.test.ts +18 -0
- package/src/lib/productSearchFilter.ts +7 -0
- package/src/lib/projectionSearchFilter.test.ts +17 -17
- package/src/lib/projectionSearchFilter.ts +2 -3
- package/src/oauth/server.test.ts +1 -1
- package/src/oauth/server.ts +11 -11
- package/src/priceSelector.ts +1 -1
- package/src/product-projection-search.ts +18 -19
- package/src/product-search.ts +48 -8
- package/src/repositories/business-unit.ts +17 -16
- package/src/repositories/cart/actions.ts +32 -32
- package/src/repositories/cart/helpers.ts +1 -1
- package/src/repositories/cart/index.ts +25 -8
- package/src/repositories/cart-discount/actions.ts +1 -4
- package/src/repositories/category/actions.ts +2 -6
- package/src/repositories/custom-object.ts +20 -21
- package/src/repositories/customer/actions.ts +4 -4
- package/src/repositories/errors.ts +1 -1
- package/src/repositories/extension.ts +2 -1
- package/src/repositories/helpers.ts +27 -27
- package/src/repositories/index.ts +17 -17
- package/src/repositories/my-customer.ts +1 -1
- package/src/repositories/my-order.ts +2 -2
- package/src/repositories/order/index.ts +1 -1
- package/src/repositories/product/actions.ts +1 -1
- package/src/repositories/quote/actions.ts +83 -0
- package/src/repositories/quote/index.ts +54 -0
- package/src/repositories/quote-request/actions.ts +84 -0
- package/src/repositories/quote-request/index.test.ts +167 -0
- package/src/repositories/quote-request/index.ts +67 -0
- package/src/repositories/quote-staged/actions.ts +84 -0
- package/src/repositories/quote-staged/index.ts +47 -0
- package/src/repositories/review.ts +4 -4
- package/src/repositories/shipping-method/actions.ts +17 -17
- package/src/repositories/shipping-method/index.ts +6 -6
- package/src/repositories/shopping-list/actions.ts +1 -1
- package/src/repositories/shopping-list/index.ts +9 -1
- package/src/repositories/subscription.ts +2 -4
- package/src/server.ts +3 -2
- package/src/services/abstract.ts +7 -7
- package/src/services/as-associate-order.test.ts +1 -1
- package/src/services/cart-discount.test.ts +1 -1
- package/src/services/cart.test.ts +40 -15
- package/src/services/category.test.ts +1 -1
- package/src/services/customer.test.ts +16 -55
- package/src/services/customer.ts +1 -1
- package/src/services/index.ts +20 -14
- package/src/services/inventory-entry.test.ts +5 -5
- package/src/services/my-cart.test.ts +2 -2
- package/src/services/my-customer.test.ts +2 -2
- package/src/services/order.test.ts +8 -8
- package/src/services/product-projection.test.ts +5 -5
- package/src/services/product-projection.ts +12 -14
- package/src/services/product.test.ts +155 -71
- package/src/services/quote-request.test.ts +59 -0
- package/src/services/quote-request.ts +16 -0
- package/src/services/quote-staged.ts +16 -0
- package/src/services/quote.ts +16 -0
- package/src/services/standalone-price.test.ts +4 -4
- package/src/services/state.test.ts +1 -1
- package/src/services/store.test.ts +2 -2
- package/src/services/tax-category.test.ts +1 -1
- package/src/shipping.ts +3 -3
- package/src/storage/in-memory.ts +55 -63
- package/src/testing/customer.ts +40 -0
- package/src/types.ts +51 -31
- package/src/repositories/quote-request.ts +0 -17
- package/src/repositories/quote.ts +0 -14
- package/src/repositories/staged-quote.ts +0 -17
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
1
2
|
import type {
|
|
2
3
|
Address,
|
|
3
4
|
Cart,
|
|
@@ -10,9 +11,9 @@ import type {
|
|
|
10
11
|
TaxCategoryDraft,
|
|
11
12
|
Zone,
|
|
12
13
|
} from "@commercetools/platform-sdk";
|
|
13
|
-
import assert from "assert";
|
|
14
14
|
import supertest from "supertest";
|
|
15
15
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
16
|
+
import { customerDraftFactory } from "~src/testing/customer";
|
|
16
17
|
import { CommercetoolsMock } from "../index";
|
|
17
18
|
|
|
18
19
|
describe("Carts Query", () => {
|
|
@@ -81,6 +82,30 @@ describe("Carts Query", () => {
|
|
|
81
82
|
expect(myCart.custom?.type.id).toBe(myCart.custom?.type.obj?.id);
|
|
82
83
|
expect(myCart.custom?.type.obj?.description?.en).toBe("Test Type");
|
|
83
84
|
});
|
|
85
|
+
|
|
86
|
+
test("throw error when anonymousId and customerId are given", async () => {
|
|
87
|
+
const customerId = "400be09e-bfe8-4925-a307-4ef6280b063e";
|
|
88
|
+
const anonymousId = "a99f27d1-7e7e-4592-8d5a-aa5da1adfe24";
|
|
89
|
+
const response = await supertest(ctMock.app).post("/dummy/carts").send({
|
|
90
|
+
currency: "EUR",
|
|
91
|
+
anonymousId,
|
|
92
|
+
customerId,
|
|
93
|
+
});
|
|
94
|
+
expect(response.status).toBe(400);
|
|
95
|
+
expect(response.body.message).toBe(
|
|
96
|
+
"Can set only one of customer OR anonymousId",
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("create cart with existing customer", async () => {
|
|
101
|
+
const customer = await customerDraftFactory(ctMock).create();
|
|
102
|
+
const response = await supertest(ctMock.app).post("/dummy/carts").send({
|
|
103
|
+
currency: "EUR",
|
|
104
|
+
customerId: customer.id,
|
|
105
|
+
});
|
|
106
|
+
expect(response.status).toBe(201);
|
|
107
|
+
expect(response.body.customerId).toBe(customer.id);
|
|
108
|
+
});
|
|
84
109
|
});
|
|
85
110
|
|
|
86
111
|
describe("Cart Update Actions", () => {
|
|
@@ -227,7 +252,7 @@ describe("Cart Update Actions", () => {
|
|
|
227
252
|
|
|
228
253
|
test("addLineItem", async () => {
|
|
229
254
|
const product = await supertest(ctMock.app)
|
|
230
|
-
.post(
|
|
255
|
+
.post("/dummy/products")
|
|
231
256
|
.send(productDraft)
|
|
232
257
|
.then((x) => x.body);
|
|
233
258
|
|
|
@@ -254,7 +279,7 @@ describe("Cart Update Actions", () => {
|
|
|
254
279
|
|
|
255
280
|
test("addLineItem by SKU", async () => {
|
|
256
281
|
const product = await supertest(ctMock.app)
|
|
257
|
-
.post(
|
|
282
|
+
.post("/dummy/products")
|
|
258
283
|
.send(productDraft)
|
|
259
284
|
.then((x) => x.body);
|
|
260
285
|
|
|
@@ -280,7 +305,7 @@ describe("Cart Update Actions", () => {
|
|
|
280
305
|
await createCart(currency);
|
|
281
306
|
|
|
282
307
|
const product = await supertest(ctMock.app)
|
|
283
|
-
.post(
|
|
308
|
+
.post("/dummy/products")
|
|
284
309
|
.send(productDraft)
|
|
285
310
|
.then((x) => x.body);
|
|
286
311
|
|
|
@@ -302,12 +327,12 @@ describe("Cart Update Actions", () => {
|
|
|
302
327
|
|
|
303
328
|
test("addLineItem with custom field", async () => {
|
|
304
329
|
const product = await supertest(ctMock.app)
|
|
305
|
-
.post(
|
|
330
|
+
.post("/dummy/products")
|
|
306
331
|
.send(productDraft)
|
|
307
332
|
.then((x) => x.body);
|
|
308
333
|
|
|
309
334
|
const type = await supertest(ctMock.app)
|
|
310
|
-
.post(
|
|
335
|
+
.post("/dummy/types")
|
|
311
336
|
.send({
|
|
312
337
|
key: "my-type",
|
|
313
338
|
name: {
|
|
@@ -363,12 +388,12 @@ describe("Cart Update Actions", () => {
|
|
|
363
388
|
|
|
364
389
|
test("addLineItem with key", async () => {
|
|
365
390
|
const product = await supertest(ctMock.app)
|
|
366
|
-
.post(
|
|
391
|
+
.post("/dummy/products")
|
|
367
392
|
.send(productDraft)
|
|
368
393
|
.then((x) => x.body);
|
|
369
394
|
|
|
370
395
|
const type = await supertest(ctMock.app)
|
|
371
|
-
.post(
|
|
396
|
+
.post("/dummy/types")
|
|
372
397
|
.send({
|
|
373
398
|
key: "my-type",
|
|
374
399
|
name: {
|
|
@@ -436,7 +461,7 @@ describe("Cart Update Actions", () => {
|
|
|
436
461
|
|
|
437
462
|
test("addItemShippingAddress", async () => {
|
|
438
463
|
await supertest(ctMock.app)
|
|
439
|
-
.post(
|
|
464
|
+
.post("/dummy/products")
|
|
440
465
|
.send(productDraft)
|
|
441
466
|
.then((x) => x.body);
|
|
442
467
|
|
|
@@ -487,7 +512,7 @@ describe("Cart Update Actions", () => {
|
|
|
487
512
|
|
|
488
513
|
test("recalculate", async () => {
|
|
489
514
|
await supertest(ctMock.app)
|
|
490
|
-
.post(
|
|
515
|
+
.post("/dummy/products")
|
|
491
516
|
.send(productDraft)
|
|
492
517
|
.then((x) => x.body);
|
|
493
518
|
|
|
@@ -511,7 +536,7 @@ describe("Cart Update Actions", () => {
|
|
|
511
536
|
|
|
512
537
|
test("removeLineItem", async () => {
|
|
513
538
|
const product = await supertest(ctMock.app)
|
|
514
|
-
.post(
|
|
539
|
+
.post("/dummy/products")
|
|
515
540
|
.send(productDraft)
|
|
516
541
|
.then((x) => x.body);
|
|
517
542
|
|
|
@@ -548,7 +573,7 @@ describe("Cart Update Actions", () => {
|
|
|
548
573
|
|
|
549
574
|
test("removeLineItem decrease quantity", async () => {
|
|
550
575
|
const product = await supertest(ctMock.app)
|
|
551
|
-
.post(
|
|
576
|
+
.post("/dummy/products")
|
|
552
577
|
.send(productDraft)
|
|
553
578
|
.then((x) => x.body);
|
|
554
579
|
|
|
@@ -716,7 +741,7 @@ describe("Cart Update Actions", () => {
|
|
|
716
741
|
};
|
|
717
742
|
|
|
718
743
|
const type = await supertest(ctMock.app)
|
|
719
|
-
.post(
|
|
744
|
+
.post("/dummy/types")
|
|
720
745
|
.send({
|
|
721
746
|
key: "my-type",
|
|
722
747
|
name: {
|
|
@@ -784,7 +809,7 @@ describe("Cart Update Actions", () => {
|
|
|
784
809
|
};
|
|
785
810
|
|
|
786
811
|
const type = await supertest(ctMock.app)
|
|
787
|
-
.post(
|
|
812
|
+
.post("/dummy/types")
|
|
788
813
|
.send({
|
|
789
814
|
key: "my-type",
|
|
790
815
|
name: {
|
|
@@ -1218,7 +1243,7 @@ describe("Cart Update Actions", () => {
|
|
|
1218
1243
|
|
|
1219
1244
|
test("setLineItemShippingDetails", async () => {
|
|
1220
1245
|
const product = await supertest(ctMock.app)
|
|
1221
|
-
.post(
|
|
1246
|
+
.post("/dummy/products")
|
|
1222
1247
|
.send(productDraft)
|
|
1223
1248
|
.then((x) => x.body);
|
|
1224
1249
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
1
2
|
import type {
|
|
2
3
|
Category,
|
|
3
4
|
CategoryAddAssetAction,
|
|
4
5
|
CategoryRemoveAssetAction,
|
|
5
6
|
} from "@commercetools/platform-sdk";
|
|
6
|
-
import assert from "assert";
|
|
7
7
|
import supertest from "supertest";
|
|
8
8
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
9
9
|
import { CommercetoolsMock } from "../index";
|
|
@@ -1,66 +1,27 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
1
2
|
import type {
|
|
2
3
|
Customer,
|
|
3
4
|
CustomerDraft,
|
|
4
5
|
CustomerToken,
|
|
5
6
|
} from "@commercetools/platform-sdk";
|
|
6
|
-
import assert from "assert";
|
|
7
|
-
import { Factory } from "fishery";
|
|
8
7
|
import supertest from "supertest";
|
|
9
8
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
10
9
|
import { hashPassword } from "~src/lib/password";
|
|
10
|
+
import { customerDraftFactory } from "~src/testing/customer";
|
|
11
11
|
import { CommercetoolsMock, getBaseResourceProperties } from "../index";
|
|
12
12
|
|
|
13
13
|
const ctMock = new CommercetoolsMock();
|
|
14
14
|
|
|
15
|
-
const customerDraftFactory = Factory.define<
|
|
16
|
-
CustomerDraft,
|
|
17
|
-
CustomerDraft,
|
|
18
|
-
Customer
|
|
19
|
-
>(({ onCreate }) => {
|
|
20
|
-
onCreate(async (draft) => {
|
|
21
|
-
const response = await supertest(ctMock.app)
|
|
22
|
-
.post(`/dummy/customers`)
|
|
23
|
-
.send(draft);
|
|
24
|
-
|
|
25
|
-
return response.body.customer;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
email: "customer@example.com",
|
|
30
|
-
firstName: "John",
|
|
31
|
-
lastName: "Doe",
|
|
32
|
-
locale: "nl-NL",
|
|
33
|
-
password: "my-secret-pw",
|
|
34
|
-
addresses: [
|
|
35
|
-
{
|
|
36
|
-
firstName: "John",
|
|
37
|
-
lastName: "Doe",
|
|
38
|
-
streetName: "Street name",
|
|
39
|
-
streetNumber: "42",
|
|
40
|
-
postalCode: "1234 AB",
|
|
41
|
-
city: "Utrecht",
|
|
42
|
-
country: "NL",
|
|
43
|
-
company: "Lab Digital",
|
|
44
|
-
phone: "+31612345678",
|
|
45
|
-
email: "customer@example.com",
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
isEmailVerified: false,
|
|
49
|
-
stores: [],
|
|
50
|
-
authenticationMode: "Password",
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
|
|
54
15
|
afterEach(() => {
|
|
55
16
|
ctMock.clear();
|
|
56
17
|
});
|
|
57
18
|
|
|
58
19
|
describe("Customer create", () => {
|
|
59
20
|
test("create new customer", async () => {
|
|
60
|
-
const draft = customerDraftFactory.build();
|
|
21
|
+
const draft = customerDraftFactory(ctMock).build();
|
|
61
22
|
|
|
62
23
|
const response = await supertest(ctMock.app)
|
|
63
|
-
.post(
|
|
24
|
+
.post("/dummy/customers")
|
|
64
25
|
.send(draft);
|
|
65
26
|
|
|
66
27
|
const customer = response.body.customer as Customer;
|
|
@@ -94,7 +55,7 @@ describe("Customer create", () => {
|
|
|
94
55
|
};
|
|
95
56
|
|
|
96
57
|
const response = await supertest(ctMock.app)
|
|
97
|
-
.post(
|
|
58
|
+
.post("/dummy/customers")
|
|
98
59
|
.send(draft);
|
|
99
60
|
|
|
100
61
|
const customer = response.body.customer as Customer;
|
|
@@ -109,7 +70,7 @@ describe("Customer create", () => {
|
|
|
109
70
|
|
|
110
71
|
describe("Customer Update Actions", () => {
|
|
111
72
|
test("addAddress", async () => {
|
|
112
|
-
const customer = await customerDraftFactory.create();
|
|
73
|
+
const customer = await customerDraftFactory(ctMock).create();
|
|
113
74
|
const response = await supertest(ctMock.app)
|
|
114
75
|
.post(`/dummy/customers/${customer.id}`)
|
|
115
76
|
.send({
|
|
@@ -134,7 +95,7 @@ describe("Customer Update Actions", () => {
|
|
|
134
95
|
});
|
|
135
96
|
|
|
136
97
|
test("removeAddress by ID", async () => {
|
|
137
|
-
const customer = await customerDraftFactory.create({
|
|
98
|
+
const customer = await customerDraftFactory(ctMock).create({
|
|
138
99
|
addresses: [
|
|
139
100
|
{
|
|
140
101
|
key: "address-key",
|
|
@@ -165,7 +126,7 @@ describe("Customer Update Actions", () => {
|
|
|
165
126
|
});
|
|
166
127
|
|
|
167
128
|
test("removeAddress by Key", async () => {
|
|
168
|
-
const customer = await customerDraftFactory.create({
|
|
129
|
+
const customer = await customerDraftFactory(ctMock).create({
|
|
169
130
|
addresses: [
|
|
170
131
|
{
|
|
171
132
|
key: "address-key",
|
|
@@ -196,7 +157,7 @@ describe("Customer Update Actions", () => {
|
|
|
196
157
|
});
|
|
197
158
|
|
|
198
159
|
test("changeAddress by ID", async () => {
|
|
199
|
-
const customer = await customerDraftFactory.create({
|
|
160
|
+
const customer = await customerDraftFactory(ctMock).create({
|
|
200
161
|
addresses: [
|
|
201
162
|
{
|
|
202
163
|
key: "address-key",
|
|
@@ -248,7 +209,7 @@ describe("Customer Update Actions", () => {
|
|
|
248
209
|
});
|
|
249
210
|
|
|
250
211
|
test("addBillingAddressId", async () => {
|
|
251
|
-
const customer = await customerDraftFactory.create({
|
|
212
|
+
const customer = await customerDraftFactory(ctMock).create({
|
|
252
213
|
addresses: [
|
|
253
214
|
{
|
|
254
215
|
key: "address-key",
|
|
@@ -280,7 +241,7 @@ describe("Customer Update Actions", () => {
|
|
|
280
241
|
});
|
|
281
242
|
|
|
282
243
|
test("removeBillingAddressId", async () => {
|
|
283
|
-
const customer = await customerDraftFactory.create({
|
|
244
|
+
const customer = await customerDraftFactory(ctMock).create({
|
|
284
245
|
addresses: [
|
|
285
246
|
{
|
|
286
247
|
key: "address-key",
|
|
@@ -318,7 +279,7 @@ describe("Customer Update Actions", () => {
|
|
|
318
279
|
});
|
|
319
280
|
|
|
320
281
|
test("setDefaultBillingAddress by ID", async () => {
|
|
321
|
-
const customer = await customerDraftFactory.create({
|
|
282
|
+
const customer = await customerDraftFactory(ctMock).create({
|
|
322
283
|
defaultBillingAddress: undefined,
|
|
323
284
|
defaultShippingAddress: undefined,
|
|
324
285
|
addresses: [
|
|
@@ -356,7 +317,7 @@ describe("Customer Update Actions", () => {
|
|
|
356
317
|
});
|
|
357
318
|
|
|
358
319
|
test("addShippingAddressId", async () => {
|
|
359
|
-
const customer = await customerDraftFactory.create({
|
|
320
|
+
const customer = await customerDraftFactory(ctMock).create({
|
|
360
321
|
addresses: [
|
|
361
322
|
{
|
|
362
323
|
key: "address-key",
|
|
@@ -387,7 +348,7 @@ describe("Customer Update Actions", () => {
|
|
|
387
348
|
});
|
|
388
349
|
|
|
389
350
|
test("removeShippingAddressId", async () => {
|
|
390
|
-
const customer = await customerDraftFactory.create({
|
|
351
|
+
const customer = await customerDraftFactory(ctMock).create({
|
|
391
352
|
addresses: [
|
|
392
353
|
{
|
|
393
354
|
key: "address-key",
|
|
@@ -425,7 +386,7 @@ describe("Customer Update Actions", () => {
|
|
|
425
386
|
});
|
|
426
387
|
|
|
427
388
|
test("setDefaultShippingAddress by ID", async () => {
|
|
428
|
-
const customer = await customerDraftFactory.create({
|
|
389
|
+
const customer = await customerDraftFactory(ctMock).create({
|
|
429
390
|
defaultBillingAddress: undefined,
|
|
430
391
|
defaultShippingAddress: undefined,
|
|
431
392
|
addresses: [
|
|
@@ -498,7 +459,7 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
498
459
|
assert(customer, "customer not created");
|
|
499
460
|
|
|
500
461
|
const response = await supertest(ctMock.app)
|
|
501
|
-
.head(
|
|
462
|
+
.head("/dummy/customers/invalid-id")
|
|
502
463
|
.send();
|
|
503
464
|
|
|
504
465
|
expect(response.status).toBe(404);
|
package/src/services/customer.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CustomerSignInResult } from "@commercetools/platform-sdk";
|
|
2
2
|
import type { Router } from "express";
|
|
3
|
-
import {
|
|
3
|
+
import type { Request, Response } from "express";
|
|
4
4
|
import type { CustomerRepository } from "../repositories/customer";
|
|
5
5
|
import { getRepositoryContext } from "../repositories/helpers";
|
|
6
6
|
import AbstractService from "./abstract";
|
package/src/services/index.ts
CHANGED
|
@@ -26,6 +26,9 @@ import { ProductDiscountService } from "./product-discount";
|
|
|
26
26
|
import { ProductProjectionService } from "./product-projection";
|
|
27
27
|
import { ProductSelectionService } from "./product-selection";
|
|
28
28
|
import { ProductTypeService } from "./product-type";
|
|
29
|
+
import { QuoteService } from "./quote";
|
|
30
|
+
import { QuoteRequestService } from "./quote-request";
|
|
31
|
+
import { StagedQuoteService } from "./quote-staged";
|
|
29
32
|
import { ReviewService } from "./reviews";
|
|
30
33
|
import { ShippingMethodService } from "./shipping-method";
|
|
31
34
|
import { ShoppingListService } from "./shopping-list";
|
|
@@ -44,14 +47,14 @@ export const createServices = (
|
|
|
44
47
|
"associate-role": new AssociateRoleServices(router, repos["associate-role"]),
|
|
45
48
|
"as-associate": new AsAssociateService(router, repos["as-associate"]),
|
|
46
49
|
"business-unit": new BusinessUnitServices(router, repos["business-unit"]),
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
category: new CategoryServices(router, repos.category),
|
|
51
|
+
cart: new CartService(router, repos.cart, repos.order),
|
|
49
52
|
"cart-discount": new CartDiscountService(router, repos["cart-discount"]),
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
customer: new CustomerService(router, repos.customer),
|
|
54
|
+
channel: new ChannelService(router, repos.channel),
|
|
52
55
|
"customer-group": new CustomerGroupService(router, repos["customer-group"]),
|
|
53
56
|
"discount-code": new DiscountCodeService(router, repos["discount-code"]),
|
|
54
|
-
|
|
57
|
+
extension: new ExtensionServices(router, repos.extension),
|
|
55
58
|
"inventory-entry": new InventoryEntryService(
|
|
56
59
|
router,
|
|
57
60
|
repos["inventory-entry"],
|
|
@@ -60,8 +63,8 @@ export const createServices = (
|
|
|
60
63
|
router,
|
|
61
64
|
repos["key-value-document"],
|
|
62
65
|
),
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
order: new OrderService(router, repos.order),
|
|
67
|
+
payment: new PaymentService(router, repos.payment),
|
|
65
68
|
"standalone-price": new StandAlonePriceService(
|
|
66
69
|
router,
|
|
67
70
|
repos["standalone-price"],
|
|
@@ -80,7 +83,7 @@ export const createServices = (
|
|
|
80
83
|
repos["shipping-method"],
|
|
81
84
|
),
|
|
82
85
|
"product-type": new ProductTypeService(router, repos["product-type"]),
|
|
83
|
-
|
|
86
|
+
product: new ProductService(router, repos.product),
|
|
84
87
|
"product-discount": new ProductDiscountService(
|
|
85
88
|
router,
|
|
86
89
|
repos["product-discount"],
|
|
@@ -93,16 +96,19 @@ export const createServices = (
|
|
|
93
96
|
router,
|
|
94
97
|
repos["product-selection"],
|
|
95
98
|
),
|
|
96
|
-
|
|
99
|
+
quotes: new QuoteService(router, repos.quote),
|
|
100
|
+
"quote-request": new QuoteRequestService(router, repos["quote-request"]),
|
|
101
|
+
reviews: new ReviewService(router, repos.review),
|
|
97
102
|
"shopping-list": new ShoppingListService(router, repos["shopping-list"]),
|
|
98
|
-
"
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
"staged-quote": new StagedQuoteService(router, repos["staged-quote"]),
|
|
104
|
+
state: new StateService(router, repos.state),
|
|
105
|
+
store: new StoreService(router, repos.store),
|
|
106
|
+
subscription: new SubscriptionService(router, repos.subscription),
|
|
101
107
|
"tax-category": new TaxCategoryService(router, repos["tax-category"]),
|
|
102
108
|
"attribute-group": new AttributeGroupService(
|
|
103
109
|
router,
|
|
104
110
|
repos["attribute-group"],
|
|
105
111
|
),
|
|
106
|
-
|
|
107
|
-
|
|
112
|
+
type: new TypeService(router, repos.type),
|
|
113
|
+
zone: new ZoneService(router, repos.zone),
|
|
108
114
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
1
2
|
import type { InventoryEntry, Type } from "@commercetools/platform-sdk";
|
|
2
|
-
import assert from "assert";
|
|
3
3
|
import supertest from "supertest";
|
|
4
4
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
5
5
|
import { CommercetoolsMock } from "../index";
|
|
@@ -24,7 +24,7 @@ describe("Inventory Entry Query", () => {
|
|
|
24
24
|
test("no filter", async () => {
|
|
25
25
|
assert(inventoryEntry, "inventory entry not created");
|
|
26
26
|
|
|
27
|
-
const response = await supertest(ctMock.app).get(
|
|
27
|
+
const response = await supertest(ctMock.app).get("/dummy/inventory");
|
|
28
28
|
expect(response.status).toBe(200);
|
|
29
29
|
expect(response.body.count).toBe(1);
|
|
30
30
|
expect(response.body.total).toBe(1);
|
|
@@ -37,14 +37,14 @@ describe("Inventory Entry Query", () => {
|
|
|
37
37
|
|
|
38
38
|
{
|
|
39
39
|
const response = await supertest(ctMock.app)
|
|
40
|
-
.get(
|
|
40
|
+
.get("/dummy/inventory")
|
|
41
41
|
.query({ where: 'sku="unknown"' });
|
|
42
42
|
expect(response.status).toBe(200);
|
|
43
43
|
expect(response.body.count).toBe(0);
|
|
44
44
|
}
|
|
45
45
|
{
|
|
46
46
|
const response = await supertest(ctMock.app)
|
|
47
|
-
.get(
|
|
47
|
+
.get("/dummy/inventory")
|
|
48
48
|
.query({ where: 'sku="1337"' });
|
|
49
49
|
expect(response.status).toBe(200);
|
|
50
50
|
expect(response.body.count).toBe(1);
|
|
@@ -155,7 +155,7 @@ describe("Inventory Entry Update Actions", () => {
|
|
|
155
155
|
|
|
156
156
|
expect(response.status).toBe(200);
|
|
157
157
|
expect(response.body.version).toBe(3);
|
|
158
|
-
expect(response.body.custom.fields
|
|
158
|
+
expect(response.body.custom.fields.foo).toBe("bar");
|
|
159
159
|
});
|
|
160
160
|
|
|
161
161
|
test("set restockable in days", async () => {
|
|
@@ -85,14 +85,14 @@ describe("MyCart", () => {
|
|
|
85
85
|
.post("/dummy/me/carts")
|
|
86
86
|
.send(draft);
|
|
87
87
|
|
|
88
|
-
const response = await supertest(ctMock.app).get(
|
|
88
|
+
const response = await supertest(ctMock.app).get("/dummy/me/active-cart");
|
|
89
89
|
|
|
90
90
|
expect(response.status).toBe(200);
|
|
91
91
|
expect(response.body).toEqual(createResponse.body);
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
test("Get my active cart which doesnt exists", async () => {
|
|
95
|
-
const response = await supertest(ctMock.app).get(
|
|
95
|
+
const response = await supertest(ctMock.app).get("/dummy/me/active-cart");
|
|
96
96
|
|
|
97
97
|
expect(response.status).toBe(404);
|
|
98
98
|
});
|
|
@@ -55,7 +55,7 @@ describe("Me", () => {
|
|
|
55
55
|
.post("/dummy/me/signup")
|
|
56
56
|
.send(draft);
|
|
57
57
|
|
|
58
|
-
const response = await supertest(ctMock.app).get(
|
|
58
|
+
const response = await supertest(ctMock.app).get("/dummy/me");
|
|
59
59
|
|
|
60
60
|
expect(response.status).toBe(200);
|
|
61
61
|
expect(response.body).toEqual(createResponse.body.customer);
|
|
@@ -284,7 +284,7 @@ describe("/me", () => {
|
|
|
284
284
|
|
|
285
285
|
test("setCustomField", async () => {
|
|
286
286
|
const response = await supertest(ctMock.app)
|
|
287
|
-
.post(
|
|
287
|
+
.post("/dummy/me")
|
|
288
288
|
.send({
|
|
289
289
|
version: 2,
|
|
290
290
|
actions: [{ action: "setCustomField", name: "foobar", value: true }],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
1
2
|
import type { Order, Payment, State } from "@commercetools/platform-sdk";
|
|
2
|
-
import assert from "assert";
|
|
3
3
|
import supertest from "supertest";
|
|
4
4
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
5
5
|
import { generateRandomString } from "~src/helpers";
|
|
@@ -46,7 +46,7 @@ describe("Order Query", () => {
|
|
|
46
46
|
test("no filter", async () => {
|
|
47
47
|
assert(order, "order not created");
|
|
48
48
|
|
|
49
|
-
const response = await supertest(ctMock.app).get(
|
|
49
|
+
const response = await supertest(ctMock.app).get("/dummy/orders");
|
|
50
50
|
expect(response.status).toBe(200);
|
|
51
51
|
expect(response.body.count).toBe(1);
|
|
52
52
|
expect(response.body.total).toBe(1);
|
|
@@ -59,14 +59,14 @@ describe("Order Query", () => {
|
|
|
59
59
|
|
|
60
60
|
{
|
|
61
61
|
const response = await supertest(ctMock.app)
|
|
62
|
-
.get(
|
|
62
|
+
.get("/dummy/orders")
|
|
63
63
|
.query({ where: 'orderNumber="nomatch"' });
|
|
64
64
|
expect(response.status).toBe(200);
|
|
65
65
|
expect(response.body.count).toBe(0);
|
|
66
66
|
}
|
|
67
67
|
{
|
|
68
68
|
const response = await supertest(ctMock.app)
|
|
69
|
-
.get(
|
|
69
|
+
.get("/dummy/orders")
|
|
70
70
|
.query({ where: 'orderNumber="foobar"' });
|
|
71
71
|
expect(response.status).toBe(200);
|
|
72
72
|
expect(response.body.count).toBe(1);
|
|
@@ -171,7 +171,7 @@ describe("Order payment tests", () => {
|
|
|
171
171
|
ctMock.project().add("order", order);
|
|
172
172
|
|
|
173
173
|
const response = await supertest(ctMock.app)
|
|
174
|
-
.get(
|
|
174
|
+
.get("/dummy/orders")
|
|
175
175
|
.query({ where: `paymentInfo(payments(id="${payment.id}"))` });
|
|
176
176
|
|
|
177
177
|
expect(response.status).toBe(200);
|
|
@@ -179,8 +179,8 @@ describe("Order payment tests", () => {
|
|
|
179
179
|
|
|
180
180
|
{
|
|
181
181
|
const response = await supertest(ctMock.app)
|
|
182
|
-
.get(
|
|
183
|
-
.query({ where:
|
|
182
|
+
.get("/dummy/orders")
|
|
183
|
+
.query({ where: "paymentInfo(payments(id is defined))" });
|
|
184
184
|
|
|
185
185
|
expect(response.status).toBe(200);
|
|
186
186
|
expect(response.body.results[0].id).toBe(order.id);
|
|
@@ -800,7 +800,7 @@ describe("Order Import", () => {
|
|
|
800
800
|
|
|
801
801
|
test("Import", async () => {
|
|
802
802
|
const response = await supertest(ctMock.app)
|
|
803
|
-
.post(
|
|
803
|
+
.post("/dummy/orders/import")
|
|
804
804
|
.send({
|
|
805
805
|
orderNumber: "100000001",
|
|
806
806
|
totalPrice: {
|
|
@@ -181,7 +181,7 @@ beforeEach(async () => {
|
|
|
181
181
|
],
|
|
182
182
|
assets: [],
|
|
183
183
|
images: [],
|
|
184
|
-
attributes: productDraft.variants
|
|
184
|
+
attributes: productDraft.variants?.[0].attributes,
|
|
185
185
|
},
|
|
186
186
|
],
|
|
187
187
|
name: productDraft.name,
|
|
@@ -236,8 +236,8 @@ describe("Product Projection Query - Generic", () => {
|
|
|
236
236
|
const response = await supertest(ctMock.app)
|
|
237
237
|
.get("/dummy/product-projections")
|
|
238
238
|
.query({
|
|
239
|
-
|
|
240
|
-
|
|
239
|
+
limit: 50,
|
|
240
|
+
where: ["slug(nl-NL=:slug)"],
|
|
241
241
|
"var.slug": "test-product",
|
|
242
242
|
});
|
|
243
243
|
|
|
@@ -257,8 +257,8 @@ describe("Product Projection Query - Generic", () => {
|
|
|
257
257
|
const response = await supertest(ctMock.app)
|
|
258
258
|
.get("/dummy/product-projections")
|
|
259
259
|
.query({
|
|
260
|
-
|
|
261
|
-
|
|
260
|
+
limit: 50,
|
|
261
|
+
where: ["slug(nl-NL=:slug)"],
|
|
262
262
|
"var.slug": "missing-product",
|
|
263
263
|
});
|
|
264
264
|
|
|
@@ -40,21 +40,19 @@ export class ProductProjectionService extends AbstractService {
|
|
|
40
40
|
search(request: Request, response: Response) {
|
|
41
41
|
const query = request.query;
|
|
42
42
|
const searchParams: ProductProjectionQueryParams = {
|
|
43
|
-
|
|
43
|
+
filter: queryParamsArray(query.filter),
|
|
44
44
|
"filter.query": queryParamsArray(query["filter.query"]),
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
: undefined,
|
|
57
|
-
"limit": query.limit ? Number(queryParamsValue(query.limit)) : undefined,
|
|
45
|
+
facet: queryParamsArray(query.facet),
|
|
46
|
+
expand: queryParamsArray(query.expand),
|
|
47
|
+
staged: queryParamsValue(query.staged) === "true",
|
|
48
|
+
localeProjection: queryParamsValue(query.localeProjection),
|
|
49
|
+
storeProjection: queryParamsValue(query.storeProjection),
|
|
50
|
+
priceChannel: queryParamsValue(query.priceChannel),
|
|
51
|
+
priceCountry: queryParamsValue(query.priceCountry),
|
|
52
|
+
priceCurrency: queryParamsValue(query.priceCurrency),
|
|
53
|
+
priceCustomerGroup: queryParamsValue(query.priceCustomerGroup),
|
|
54
|
+
offset: query.offset ? Number(queryParamsValue(query.offset)) : undefined,
|
|
55
|
+
limit: query.limit ? Number(queryParamsValue(query.limit)) : undefined,
|
|
58
56
|
};
|
|
59
57
|
const resource = this.repository.search(
|
|
60
58
|
getRepositoryContext(request),
|