@labdigital/commercetools-mock 2.46.0 → 2.47.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 +589 -267
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +782 -58
- package/dist/index.d.ts +782 -58
- package/dist/index.js +574 -252
- package/dist/index.js.map +1 -1
- package/package.json +45 -53
- package/src/ctMock.ts +16 -15
- package/src/index.test.ts +5 -5
- package/src/lib/predicateParser.test.ts +62 -62
- package/src/lib/predicateParser.ts +32 -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 +9 -1
- package/src/oauth/server.ts +26 -22
- package/src/priceSelector.ts +1 -1
- package/src/product-projection-search.ts +18 -19
- 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 +8 -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 +32 -22
- 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 +15 -15
- package/src/services/cart.ts +3 -2
- package/src/services/category.test.ts +1 -1
- package/src/services/custom-object.ts +8 -6
- package/src/services/customer.test.ts +4 -4
- package/src/services/customer.ts +5 -5
- 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-cart.ts +3 -2
- package/src/services/my-customer.test.ts +2 -2
- package/src/services/my-customer.ts +16 -12
- package/src/services/order.test.ts +8 -8
- package/src/services/order.ts +4 -3
- package/src/services/product-projection.test.ts +5 -5
- package/src/services/product-projection.ts +14 -16
- package/src/services/product.test.ts +1 -1
- package/src/services/product.ts +1 -1
- package/src/services/project.ts +4 -3
- 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/shipping-method.ts +4 -2
- 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 +1 -1
- 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,7 +11,6 @@ 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
16
|
import { customerDraftFactory } from "~src/testing/customer";
|
|
@@ -252,7 +252,7 @@ describe("Cart Update Actions", () => {
|
|
|
252
252
|
|
|
253
253
|
test("addLineItem", async () => {
|
|
254
254
|
const product = await supertest(ctMock.app)
|
|
255
|
-
.post(
|
|
255
|
+
.post("/dummy/products")
|
|
256
256
|
.send(productDraft)
|
|
257
257
|
.then((x) => x.body);
|
|
258
258
|
|
|
@@ -279,7 +279,7 @@ describe("Cart Update Actions", () => {
|
|
|
279
279
|
|
|
280
280
|
test("addLineItem by SKU", async () => {
|
|
281
281
|
const product = await supertest(ctMock.app)
|
|
282
|
-
.post(
|
|
282
|
+
.post("/dummy/products")
|
|
283
283
|
.send(productDraft)
|
|
284
284
|
.then((x) => x.body);
|
|
285
285
|
|
|
@@ -305,7 +305,7 @@ describe("Cart Update Actions", () => {
|
|
|
305
305
|
await createCart(currency);
|
|
306
306
|
|
|
307
307
|
const product = await supertest(ctMock.app)
|
|
308
|
-
.post(
|
|
308
|
+
.post("/dummy/products")
|
|
309
309
|
.send(productDraft)
|
|
310
310
|
.then((x) => x.body);
|
|
311
311
|
|
|
@@ -327,12 +327,12 @@ describe("Cart Update Actions", () => {
|
|
|
327
327
|
|
|
328
328
|
test("addLineItem with custom field", async () => {
|
|
329
329
|
const product = await supertest(ctMock.app)
|
|
330
|
-
.post(
|
|
330
|
+
.post("/dummy/products")
|
|
331
331
|
.send(productDraft)
|
|
332
332
|
.then((x) => x.body);
|
|
333
333
|
|
|
334
334
|
const type = await supertest(ctMock.app)
|
|
335
|
-
.post(
|
|
335
|
+
.post("/dummy/types")
|
|
336
336
|
.send({
|
|
337
337
|
key: "my-type",
|
|
338
338
|
name: {
|
|
@@ -388,12 +388,12 @@ describe("Cart Update Actions", () => {
|
|
|
388
388
|
|
|
389
389
|
test("addLineItem with key", async () => {
|
|
390
390
|
const product = await supertest(ctMock.app)
|
|
391
|
-
.post(
|
|
391
|
+
.post("/dummy/products")
|
|
392
392
|
.send(productDraft)
|
|
393
393
|
.then((x) => x.body);
|
|
394
394
|
|
|
395
395
|
const type = await supertest(ctMock.app)
|
|
396
|
-
.post(
|
|
396
|
+
.post("/dummy/types")
|
|
397
397
|
.send({
|
|
398
398
|
key: "my-type",
|
|
399
399
|
name: {
|
|
@@ -461,7 +461,7 @@ describe("Cart Update Actions", () => {
|
|
|
461
461
|
|
|
462
462
|
test("addItemShippingAddress", async () => {
|
|
463
463
|
await supertest(ctMock.app)
|
|
464
|
-
.post(
|
|
464
|
+
.post("/dummy/products")
|
|
465
465
|
.send(productDraft)
|
|
466
466
|
.then((x) => x.body);
|
|
467
467
|
|
|
@@ -512,7 +512,7 @@ describe("Cart Update Actions", () => {
|
|
|
512
512
|
|
|
513
513
|
test("recalculate", async () => {
|
|
514
514
|
await supertest(ctMock.app)
|
|
515
|
-
.post(
|
|
515
|
+
.post("/dummy/products")
|
|
516
516
|
.send(productDraft)
|
|
517
517
|
.then((x) => x.body);
|
|
518
518
|
|
|
@@ -536,7 +536,7 @@ describe("Cart Update Actions", () => {
|
|
|
536
536
|
|
|
537
537
|
test("removeLineItem", async () => {
|
|
538
538
|
const product = await supertest(ctMock.app)
|
|
539
|
-
.post(
|
|
539
|
+
.post("/dummy/products")
|
|
540
540
|
.send(productDraft)
|
|
541
541
|
.then((x) => x.body);
|
|
542
542
|
|
|
@@ -573,7 +573,7 @@ describe("Cart Update Actions", () => {
|
|
|
573
573
|
|
|
574
574
|
test("removeLineItem decrease quantity", async () => {
|
|
575
575
|
const product = await supertest(ctMock.app)
|
|
576
|
-
.post(
|
|
576
|
+
.post("/dummy/products")
|
|
577
577
|
.send(productDraft)
|
|
578
578
|
.then((x) => x.body);
|
|
579
579
|
|
|
@@ -741,7 +741,7 @@ describe("Cart Update Actions", () => {
|
|
|
741
741
|
};
|
|
742
742
|
|
|
743
743
|
const type = await supertest(ctMock.app)
|
|
744
|
-
.post(
|
|
744
|
+
.post("/dummy/types")
|
|
745
745
|
.send({
|
|
746
746
|
key: "my-type",
|
|
747
747
|
name: {
|
|
@@ -809,7 +809,7 @@ describe("Cart Update Actions", () => {
|
|
|
809
809
|
};
|
|
810
810
|
|
|
811
811
|
const type = await supertest(ctMock.app)
|
|
812
|
-
.post(
|
|
812
|
+
.post("/dummy/types")
|
|
813
813
|
.send({
|
|
814
814
|
key: "my-type",
|
|
815
815
|
name: {
|
|
@@ -1243,7 +1243,7 @@ describe("Cart Update Actions", () => {
|
|
|
1243
1243
|
|
|
1244
1244
|
test("setLineItemShippingDetails", async () => {
|
|
1245
1245
|
const product = await supertest(ctMock.app)
|
|
1246
|
-
.post(
|
|
1246
|
+
.post("/dummy/products")
|
|
1247
1247
|
.send(productDraft)
|
|
1248
1248
|
.then((x) => x.body);
|
|
1249
1249
|
|
package/src/services/cart.ts
CHANGED
|
@@ -38,7 +38,8 @@ export class CartService extends AbstractService {
|
|
|
38
38
|
: this.repository.get(context, request.body.reference.id);
|
|
39
39
|
|
|
40
40
|
if (!cartOrOrder) {
|
|
41
|
-
|
|
41
|
+
response.status(400).send();
|
|
42
|
+
return;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
const cartDraft: CartDraft = {
|
|
@@ -55,6 +56,6 @@ export class CartService extends AbstractService {
|
|
|
55
56
|
|
|
56
57
|
const newCart = this.repository.create(context, cartDraft);
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
response.status(200).send(newCart);
|
|
59
60
|
}
|
|
60
61
|
}
|
|
@@ -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";
|
|
@@ -41,7 +41,7 @@ export class CustomObjectService extends AbstractService {
|
|
|
41
41
|
},
|
|
42
42
|
);
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
response.status(200).send(result);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
getWithContainerAndKey(request: Request, response: Response) {
|
|
@@ -52,9 +52,10 @@ export class CustomObjectService extends AbstractService {
|
|
|
52
52
|
);
|
|
53
53
|
|
|
54
54
|
if (!result) {
|
|
55
|
-
|
|
55
|
+
response.status(404).send("Not Found");
|
|
56
|
+
return;
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
+
response.status(200).send(result);
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
createWithContainerAndKey(request: Request, response: Response) {
|
|
@@ -65,7 +66,7 @@ export class CustomObjectService extends AbstractService {
|
|
|
65
66
|
};
|
|
66
67
|
|
|
67
68
|
const result = this.repository.create(getRepositoryContext(request), draft);
|
|
68
|
-
|
|
69
|
+
response.status(200).send(result);
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
deleteWithContainerAndKey(request: Request, response: Response) {
|
|
@@ -76,7 +77,8 @@ export class CustomObjectService extends AbstractService {
|
|
|
76
77
|
);
|
|
77
78
|
|
|
78
79
|
if (!current) {
|
|
79
|
-
|
|
80
|
+
response.status(404).send("Not Found");
|
|
81
|
+
return;
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
const result = this.repository.delete(
|
|
@@ -84,6 +86,6 @@ export class CustomObjectService extends AbstractService {
|
|
|
84
86
|
current.id,
|
|
85
87
|
);
|
|
86
88
|
|
|
87
|
-
|
|
89
|
+
response.status(200).send(result);
|
|
88
90
|
}
|
|
89
91
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
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
7
|
import supertest from "supertest";
|
|
8
8
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
9
9
|
import { hashPassword } from "~src/lib/password";
|
|
@@ -21,7 +21,7 @@ describe("Customer create", () => {
|
|
|
21
21
|
const draft = customerDraftFactory(ctMock).build();
|
|
22
22
|
|
|
23
23
|
const response = await supertest(ctMock.app)
|
|
24
|
-
.post(
|
|
24
|
+
.post("/dummy/customers")
|
|
25
25
|
.send(draft);
|
|
26
26
|
|
|
27
27
|
const customer = response.body.customer as Customer;
|
|
@@ -55,7 +55,7 @@ describe("Customer create", () => {
|
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
const response = await supertest(ctMock.app)
|
|
58
|
-
.post(
|
|
58
|
+
.post("/dummy/customers")
|
|
59
59
|
.send(draft);
|
|
60
60
|
|
|
61
61
|
const customer = response.body.customer as Customer;
|
|
@@ -459,7 +459,7 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
459
459
|
assert(customer, "customer not created");
|
|
460
460
|
|
|
461
461
|
const response = await supertest(ctMock.app)
|
|
462
|
-
.head(
|
|
462
|
+
.head("/dummy/customers/invalid-id")
|
|
463
463
|
.send();
|
|
464
464
|
|
|
465
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";
|
|
@@ -34,7 +34,7 @@ export class CustomerService extends AbstractService {
|
|
|
34
34
|
const result: CustomerSignInResult = {
|
|
35
35
|
customer: expanded,
|
|
36
36
|
};
|
|
37
|
-
|
|
37
|
+
response.status(this.createStatusCode).send(result);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
passwordResetToken(request: Request, response: Response) {
|
|
@@ -43,7 +43,7 @@ export class CustomerService extends AbstractService {
|
|
|
43
43
|
request.body,
|
|
44
44
|
);
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
response.status(200).send(customer);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
passwordReset(request: Request, response: Response) {
|
|
@@ -52,7 +52,7 @@ export class CustomerService extends AbstractService {
|
|
|
52
52
|
request.body,
|
|
53
53
|
);
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
response.status(200).send(customer);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
confirmEmailToken(request: Request, response: Response) {
|
|
@@ -61,6 +61,6 @@ export class CustomerService extends AbstractService {
|
|
|
61
61
|
getRepositoryContext(request),
|
|
62
62
|
id,
|
|
63
63
|
);
|
|
64
|
-
|
|
64
|
+
response.status(200).send(token);
|
|
65
65
|
}
|
|
66
66
|
}
|
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
|
});
|
package/src/services/my-cart.ts
CHANGED
|
@@ -37,8 +37,9 @@ export class MyCartService extends AbstractService {
|
|
|
37
37
|
activeCart(request: Request, response: Response) {
|
|
38
38
|
const resource = this.repository.getActiveCart(request.params.projectKey);
|
|
39
39
|
if (!resource) {
|
|
40
|
-
|
|
40
|
+
response.status(404).send("Not found");
|
|
41
|
+
return;
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
+
response.status(200).send(resource);
|
|
43
44
|
}
|
|
44
45
|
}
|
|
@@ -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 }],
|
|
@@ -44,16 +44,18 @@ export class MyCustomerService extends AbstractService {
|
|
|
44
44
|
getMe(request: Request, response: Response) {
|
|
45
45
|
const resource = this.repository.getMe(getRepositoryContext(request));
|
|
46
46
|
if (!resource) {
|
|
47
|
-
|
|
47
|
+
response.status(404).send("Not found");
|
|
48
|
+
return;
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
+
response.status(200).send(resource);
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
updateMe(request: Request, response: Response) {
|
|
53
54
|
const resource = this.repository.getMe(getRepositoryContext(request));
|
|
54
55
|
|
|
55
56
|
if (!resource) {
|
|
56
|
-
|
|
57
|
+
response.status(404).send("Not found");
|
|
58
|
+
return;
|
|
57
59
|
}
|
|
58
60
|
const updateRequest = validateData<Update>(
|
|
59
61
|
request.body,
|
|
@@ -67,16 +69,17 @@ export class MyCustomerService extends AbstractService {
|
|
|
67
69
|
);
|
|
68
70
|
|
|
69
71
|
const result = this._expandWithId(request, updatedResource.id);
|
|
70
|
-
|
|
72
|
+
response.status(200).send(result);
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
deleteMe(request: Request, response: Response) {
|
|
74
76
|
const resource = this.repository.deleteMe(getRepositoryContext(request));
|
|
75
77
|
if (!resource) {
|
|
76
|
-
|
|
78
|
+
response.status(404).send("Not found");
|
|
79
|
+
return;
|
|
77
80
|
}
|
|
78
81
|
|
|
79
|
-
|
|
82
|
+
response.status(200).send(resource);
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
signUp(request: Request, response: Response) {
|
|
@@ -86,7 +89,7 @@ export class MyCustomerService extends AbstractService {
|
|
|
86
89
|
draft,
|
|
87
90
|
);
|
|
88
91
|
const result = this._expandWithId(request, resource.id);
|
|
89
|
-
|
|
92
|
+
response.status(this.createStatusCode).send({ customer: result });
|
|
90
93
|
}
|
|
91
94
|
|
|
92
95
|
changePassword(request: Request, response: Response) {
|
|
@@ -95,7 +98,7 @@ export class MyCustomerService extends AbstractService {
|
|
|
95
98
|
request.body,
|
|
96
99
|
);
|
|
97
100
|
|
|
98
|
-
|
|
101
|
+
response.status(200).send(customer);
|
|
99
102
|
}
|
|
100
103
|
|
|
101
104
|
resetPassword(request: Request, response: Response) {
|
|
@@ -104,7 +107,7 @@ export class MyCustomerService extends AbstractService {
|
|
|
104
107
|
request.body,
|
|
105
108
|
);
|
|
106
109
|
|
|
107
|
-
|
|
110
|
+
response.status(200).send(customer);
|
|
108
111
|
}
|
|
109
112
|
|
|
110
113
|
emailConfirm(request: Request, response: Response) {
|
|
@@ -113,7 +116,7 @@ export class MyCustomerService extends AbstractService {
|
|
|
113
116
|
request.body,
|
|
114
117
|
);
|
|
115
118
|
|
|
116
|
-
|
|
119
|
+
response.status(200).send(customer);
|
|
117
120
|
}
|
|
118
121
|
|
|
119
122
|
signIn(request: Request, response: Response) {
|
|
@@ -125,7 +128,7 @@ export class MyCustomerService extends AbstractService {
|
|
|
125
128
|
});
|
|
126
129
|
|
|
127
130
|
if (result.count === 0) {
|
|
128
|
-
|
|
131
|
+
response.status(400).send({
|
|
129
132
|
message: "Account with the given credentials not found.",
|
|
130
133
|
errors: [
|
|
131
134
|
{
|
|
@@ -134,8 +137,9 @@ export class MyCustomerService extends AbstractService {
|
|
|
134
137
|
},
|
|
135
138
|
],
|
|
136
139
|
});
|
|
140
|
+
return;
|
|
137
141
|
}
|
|
138
142
|
|
|
139
|
-
|
|
143
|
+
response.status(200).send({ customer: result.results[0] });
|
|
140
144
|
}
|
|
141
145
|
}
|
|
@@ -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: {
|
package/src/services/order.ts
CHANGED
|
@@ -29,7 +29,7 @@ export class OrderService extends AbstractService {
|
|
|
29
29
|
getRepositoryContext(request),
|
|
30
30
|
importDraft,
|
|
31
31
|
);
|
|
32
|
-
|
|
32
|
+
response.status(200).send(resource);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
getWithOrderNumber(request: Request, response: Response) {
|
|
@@ -41,8 +41,9 @@ export class OrderService extends AbstractService {
|
|
|
41
41
|
request.query,
|
|
42
42
|
);
|
|
43
43
|
if (resource) {
|
|
44
|
-
|
|
44
|
+
response.status(200).send(resource);
|
|
45
|
+
return;
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
+
response.status(404).send("Not found");
|
|
47
48
|
}
|
|
48
49
|
}
|
|
@@ -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
|
|