@labdigital/commercetools-mock 2.46.0 → 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 +568 -241
- 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 +556 -229
- 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 +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 +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/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 +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 +15 -15
- package/src/services/category.test.ts +1 -1
- package/src/services/customer.test.ts +4 -4
- 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 +1 -1
- 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 +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
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
StagedQuote,
|
|
3
|
+
StagedQuoteDraft,
|
|
4
|
+
} from "@commercetools/platform-sdk";
|
|
5
|
+
import type { Config } from "~src/config";
|
|
6
|
+
import { getBaseResourceProperties } from "~src/helpers";
|
|
7
|
+
import type { RepositoryContext } from "../abstract";
|
|
8
|
+
import { AbstractResourceRepository } from "../abstract";
|
|
9
|
+
import { StagedQuoteUpdateHandler } from "./actions";
|
|
10
|
+
|
|
11
|
+
export class StagedQuoteRepository extends AbstractResourceRepository<"staged-quote"> {
|
|
12
|
+
constructor(config: Config) {
|
|
13
|
+
super("staged-quote", config);
|
|
14
|
+
this.actions = new StagedQuoteUpdateHandler(config.storage);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
create(context: RepositoryContext, draft: StagedQuoteDraft): StagedQuote {
|
|
18
|
+
const quoteRequest = this._storage.getByResourceIdentifier<"quote-request">(
|
|
19
|
+
context.projectKey,
|
|
20
|
+
draft.quoteRequest,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
if (!quoteRequest.cart) {
|
|
24
|
+
throw new Error("Cannot find quote request");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const cart = this._storage.getByResourceIdentifier<"cart">(
|
|
28
|
+
context.projectKey,
|
|
29
|
+
quoteRequest.cart,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const resource: StagedQuote = {
|
|
33
|
+
...getBaseResourceProperties(),
|
|
34
|
+
stagedQuoteState: "InProgress",
|
|
35
|
+
quoteRequest: {
|
|
36
|
+
typeId: "quote-request",
|
|
37
|
+
id: quoteRequest.id,
|
|
38
|
+
},
|
|
39
|
+
quotationCart: {
|
|
40
|
+
typeId: "cart",
|
|
41
|
+
id: cart.id,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return resource;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -2,10 +2,10 @@ import type {
|
|
|
2
2
|
ChannelReference,
|
|
3
3
|
ProductReference,
|
|
4
4
|
} from "@commercetools/platform-sdk";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
import type {
|
|
6
|
+
Review,
|
|
7
|
+
ReviewDraft,
|
|
8
|
+
StateReference,
|
|
9
9
|
} from "@commercetools/platform-sdk";
|
|
10
10
|
import type { Config } from "~src/config";
|
|
11
11
|
import { getBaseResourceProperties } from "../helpers";
|
|
@@ -2,23 +2,23 @@ import type {
|
|
|
2
2
|
ShippingMethodChangeTaxCategoryAction,
|
|
3
3
|
ShippingMethodRemoveShippingRateAction,
|
|
4
4
|
} from "@commercetools/platform-sdk";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
5
|
+
import type {
|
|
6
|
+
ShippingMethod,
|
|
7
|
+
ShippingMethodAddShippingRateAction,
|
|
8
|
+
ShippingMethodAddZoneAction,
|
|
9
|
+
ShippingMethodChangeActiveAction,
|
|
10
|
+
ShippingMethodChangeIsDefaultAction,
|
|
11
|
+
ShippingMethodChangeNameAction,
|
|
12
|
+
ShippingMethodRemoveZoneAction,
|
|
13
|
+
ShippingMethodSetCustomFieldAction,
|
|
14
|
+
ShippingMethodSetCustomTypeAction,
|
|
15
|
+
ShippingMethodSetDescriptionAction,
|
|
16
|
+
ShippingMethodSetKeyAction,
|
|
17
|
+
ShippingMethodSetLocalizedDescriptionAction,
|
|
18
|
+
ShippingMethodSetLocalizedNameAction,
|
|
19
|
+
ShippingMethodSetPredicateAction,
|
|
20
|
+
ShippingMethodUpdateAction,
|
|
21
|
+
ZoneReference,
|
|
22
22
|
} from "@commercetools/platform-sdk";
|
|
23
23
|
import deepEqual from "deep-equal";
|
|
24
24
|
import type { Writable } from "~src/types";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type {
|
|
2
|
+
ShippingMethod,
|
|
3
|
+
ShippingMethodDraft,
|
|
4
|
+
ZoneRate,
|
|
5
|
+
ZoneRateDraft,
|
|
6
|
+
ZoneReference,
|
|
7
7
|
} from "@commercetools/platform-sdk";
|
|
8
8
|
import type { Config } from "~src/config";
|
|
9
9
|
import { getBaseResourceProperties } from "../../helpers";
|
|
@@ -137,7 +137,7 @@ export class ShoppingListUpdateHandler
|
|
|
137
137
|
} else {
|
|
138
138
|
throw new CommercetoolsError<GeneralError>({
|
|
139
139
|
code: "General",
|
|
140
|
-
message:
|
|
140
|
+
message: "Either lineItemid or lineItemKey needs to be provided.",
|
|
141
141
|
});
|
|
142
142
|
}
|
|
143
143
|
|
|
@@ -13,6 +13,7 @@ import type { RepositoryContext } from "../abstract";
|
|
|
13
13
|
import { AbstractResourceRepository } from "../abstract";
|
|
14
14
|
import {
|
|
15
15
|
createCustomFields,
|
|
16
|
+
getBusinessUnitKeyReference,
|
|
16
17
|
getReferenceFromResourceIdentifier,
|
|
17
18
|
getStoreKeyReference,
|
|
18
19
|
} from "../helpers";
|
|
@@ -50,6 +51,13 @@ export class ShoppingListRepository extends AbstractResourceRepository<"shopping
|
|
|
50
51
|
store: draft.store
|
|
51
52
|
? getStoreKeyReference(draft.store, context.projectKey, this._storage)
|
|
52
53
|
: undefined,
|
|
54
|
+
businessUnit: draft.businessUnit
|
|
55
|
+
? getBusinessUnitKeyReference(
|
|
56
|
+
draft.businessUnit,
|
|
57
|
+
context.projectKey,
|
|
58
|
+
this._storage,
|
|
59
|
+
)
|
|
60
|
+
: undefined,
|
|
53
61
|
};
|
|
54
62
|
return this.saveNew(context, resource);
|
|
55
63
|
}
|
|
@@ -117,7 +125,7 @@ export class ShoppingListRepository extends AbstractResourceRepository<"shopping
|
|
|
117
125
|
}
|
|
118
126
|
|
|
119
127
|
throw new Error(
|
|
120
|
-
|
|
128
|
+
"must provide either sku, productId or variantId for ShoppingListLineItem",
|
|
121
129
|
);
|
|
122
130
|
};
|
|
123
131
|
}
|
|
@@ -29,10 +29,7 @@ export class SubscriptionRepository extends AbstractResourceRepository<"subscrip
|
|
|
29
29
|
throw new CommercetoolsError<InvalidInputError>(
|
|
30
30
|
{
|
|
31
31
|
code: "InvalidInput",
|
|
32
|
-
message:
|
|
33
|
-
"A test message could not be delivered to this destination: " +
|
|
34
|
-
`SQS ${dest.queueUrl} in ${dest.region} for ${dest.accessKey}. ` +
|
|
35
|
-
"Please make sure your destination is correctly configured.",
|
|
32
|
+
message: `A test message could not be delivered to this destination: SQS ${dest.queueUrl} in ${dest.region} for ${dest.accessKey}. Please make sure your destination is correctly configured.`,
|
|
36
33
|
},
|
|
37
34
|
400,
|
|
38
35
|
);
|
|
@@ -49,6 +46,7 @@ export class SubscriptionRepository extends AbstractResourceRepository<"subscrip
|
|
|
49
46
|
key: draft.key,
|
|
50
47
|
messages: draft.messages || [],
|
|
51
48
|
status: "Healthy",
|
|
49
|
+
events: draft.events || [],
|
|
52
50
|
};
|
|
53
51
|
return this.saveNew(context, resource);
|
|
54
52
|
}
|
package/src/server.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CommercetoolsMock } from "./index";
|
|
2
2
|
|
|
3
|
-
process.on("SIGINT",
|
|
3
|
+
process.on("SIGINT", () => {
|
|
4
4
|
console.info("Stopping server...");
|
|
5
5
|
process.exit();
|
|
6
6
|
});
|
|
@@ -9,6 +9,7 @@ const instance = new CommercetoolsMock();
|
|
|
9
9
|
|
|
10
10
|
let port = 3000;
|
|
11
11
|
|
|
12
|
-
if (process.env.HTTP_SERVER_PORT)
|
|
12
|
+
if (process.env.HTTP_SERVER_PORT)
|
|
13
|
+
port = Number.parseInt(process.env.HTTP_SERVER_PORT);
|
|
13
14
|
|
|
14
15
|
instance.runServer(port);
|
package/src/services/abstract.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Update } from "@commercetools/platform-sdk";
|
|
2
|
-
import {
|
|
2
|
+
import { type Request, type Response, Router } from "express";
|
|
3
3
|
import type { ParsedQs } from "qs";
|
|
4
4
|
import { updateRequestSchema } from "~src/schemas/update-request";
|
|
5
5
|
import { validateData } from "~src/validate";
|
|
@@ -68,7 +68,7 @@ export default abstract class AbstractService {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
getWithId(request: Request, response: Response) {
|
|
71
|
-
const result = this._expandWithId(request, request.params
|
|
71
|
+
const result = this._expandWithId(request, request.params.id);
|
|
72
72
|
if (!result) {
|
|
73
73
|
return response.status(404).send();
|
|
74
74
|
}
|
|
@@ -78,7 +78,7 @@ export default abstract class AbstractService {
|
|
|
78
78
|
getWithKey(request: Request, response: Response) {
|
|
79
79
|
const result = this.repository.getByKey(
|
|
80
80
|
getRepositoryContext(request),
|
|
81
|
-
request.params
|
|
81
|
+
request.params.key,
|
|
82
82
|
{
|
|
83
83
|
expand: this._parseParam(request.query.expand),
|
|
84
84
|
},
|
|
@@ -90,7 +90,7 @@ export default abstract class AbstractService {
|
|
|
90
90
|
deleteWithId(request: Request, response: Response) {
|
|
91
91
|
const result = this.repository.delete(
|
|
92
92
|
getRepositoryContext(request),
|
|
93
|
-
request.params
|
|
93
|
+
request.params.id,
|
|
94
94
|
{
|
|
95
95
|
expand: this._parseParam(request.query.expand),
|
|
96
96
|
},
|
|
@@ -104,7 +104,7 @@ export default abstract class AbstractService {
|
|
|
104
104
|
deleteWithKey(request: Request, response: Response) {
|
|
105
105
|
const resource = this.repository.getByKey(
|
|
106
106
|
getRepositoryContext(request),
|
|
107
|
-
request.params
|
|
107
|
+
request.params.key,
|
|
108
108
|
);
|
|
109
109
|
if (!resource) {
|
|
110
110
|
return response.status(404).send("Not found");
|
|
@@ -140,7 +140,7 @@ export default abstract class AbstractService {
|
|
|
140
140
|
);
|
|
141
141
|
const resource = this.repository.get(
|
|
142
142
|
getRepositoryContext(request),
|
|
143
|
-
request.params
|
|
143
|
+
request.params.id,
|
|
144
144
|
);
|
|
145
145
|
if (!resource) {
|
|
146
146
|
return response.status(404).send("Not found");
|
|
@@ -165,7 +165,7 @@ export default abstract class AbstractService {
|
|
|
165
165
|
|
|
166
166
|
const resource = this.repository.getByKey(
|
|
167
167
|
getRepositoryContext(request),
|
|
168
|
-
request.params
|
|
168
|
+
request.params.key,
|
|
169
169
|
);
|
|
170
170
|
if (!resource) {
|
|
171
171
|
return response.status(404).send("Not found");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
1
2
|
import type { Order } 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";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
1
2
|
import type { CartDiscount, TypeDraft } 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 "..";
|
|
@@ -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
|
|
|
@@ -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,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";
|
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 }],
|