@labdigital/commercetools-mock 2.66.0 → 3.0.0-beta.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/README.md +31 -8
- package/dist/abstract-BKFcva6S.mjs +1044 -0
- package/dist/abstract-BKFcva6S.mjs.map +1 -0
- package/dist/config-BcNSzPZz.d.mts +1718 -0
- package/dist/index.d.mts +50 -1633
- package/dist/index.mjs +3769 -2653
- package/dist/index.mjs.map +1 -1
- package/dist/storage/sqlite.d.mts +59 -0
- package/dist/storage/sqlite.mjs +234 -0
- package/dist/storage/sqlite.mjs.map +1 -0
- package/package.json +26 -29
- package/src/ctMock.ts +125 -136
- package/src/helpers.ts +14 -6
- package/src/index.ts +5 -0
- package/src/lib/masking.ts +4 -5
- package/src/lib/product-review-statistics.test.ts +257 -294
- package/src/lib/review-statistics.ts +17 -4
- package/src/oauth/helpers.ts +7 -4
- package/src/oauth/server.test.ts +102 -62
- package/src/oauth/server.ts +215 -213
- package/src/oauth/store.ts +20 -6
- package/src/orderSearch.ts +3 -3
- package/src/product-projection-search.ts +38 -20
- package/src/product-search-availability.test.ts +31 -52
- package/src/product-search.ts +19 -10
- package/src/projectAPI.ts +6 -22
- package/src/repositories/abstract.ts +182 -48
- package/src/repositories/as-associate.test.ts +19 -19
- package/src/repositories/associate-role.ts +12 -23
- package/src/repositories/attribute-group.test.ts +23 -23
- package/src/repositories/attribute-group.ts +6 -4
- package/src/repositories/business-unit.test.ts +63 -57
- package/src/repositories/business-unit.ts +107 -55
- package/src/repositories/cart/actions.ts +96 -65
- package/src/repositories/cart/helpers.ts +15 -11
- package/src/repositories/cart/index.test.ts +136 -30
- package/src/repositories/cart/index.ts +76 -59
- package/src/repositories/cart-discount/actions.ts +12 -44
- package/src/repositories/cart-discount/index.ts +20 -8
- package/src/repositories/category/actions.ts +27 -27
- package/src/repositories/category/index.test.ts +13 -9
- package/src/repositories/category/index.ts +40 -23
- package/src/repositories/channel.test.ts +53 -51
- package/src/repositories/channel.ts +12 -22
- package/src/repositories/custom-object.ts +34 -25
- package/src/repositories/customer/actions.ts +47 -25
- package/src/repositories/customer/index.test.ts +11 -11
- package/src/repositories/customer/index.ts +65 -35
- package/src/repositories/customer-group.test.ts +44 -42
- package/src/repositories/customer-group.ts +12 -22
- package/src/repositories/discount-code/actions.ts +3 -19
- package/src/repositories/discount-code/index.ts +9 -4
- package/src/repositories/discount-group/index.ts +8 -3
- package/src/repositories/extension.test.ts +27 -27
- package/src/repositories/extension.ts +10 -5
- package/src/repositories/helpers.ts +126 -47
- package/src/repositories/inventory-entry/actions.ts +3 -24
- package/src/repositories/inventory-entry/index.ts +19 -11
- package/src/repositories/my-customer.ts +13 -12
- package/src/repositories/my-order.ts +5 -2
- package/src/repositories/order/actions.ts +84 -56
- package/src/repositories/order/index.test.ts +36 -31
- package/src/repositories/order/index.ts +83 -49
- package/src/repositories/order-edit.ts +8 -3
- package/src/repositories/payment/actions.ts +64 -44
- package/src/repositories/payment/helpers.ts +3 -3
- package/src/repositories/payment/index.ts +28 -12
- package/src/repositories/product/actions.ts +133 -98
- package/src/repositories/product/helpers.ts +29 -16
- package/src/repositories/product/index.ts +42 -25
- package/src/repositories/product-discount.ts +6 -4
- package/src/repositories/product-projection.ts +41 -21
- package/src/repositories/product-selection.ts +8 -15
- package/src/repositories/product-tailoring.ts +22 -3
- package/src/repositories/product-type.ts +45 -4
- package/src/repositories/project.ts +57 -13
- package/src/repositories/quote/actions.ts +5 -28
- package/src/repositories/quote/index.ts +29 -6
- package/src/repositories/quote-request/actions.ts +5 -28
- package/src/repositories/quote-request/index.test.ts +3 -3
- package/src/repositories/quote-request/index.ts +31 -11
- package/src/repositories/quote-staged/actions.ts +5 -28
- package/src/repositories/quote-staged/index.ts +22 -8
- package/src/repositories/recurrence-policy/index.ts +6 -4
- package/src/repositories/recurring-order/actions.ts +7 -32
- package/src/repositories/recurring-order/index.ts +8 -6
- package/src/repositories/review.test.ts +147 -142
- package/src/repositories/review.ts +31 -37
- package/src/repositories/shipping-method/actions.ts +11 -28
- package/src/repositories/shipping-method/index.ts +26 -15
- package/src/repositories/shopping-list/actions.ts +21 -31
- package/src/repositories/shopping-list/index.ts +44 -22
- package/src/repositories/standalone-price.ts +6 -4
- package/src/repositories/state.ts +15 -9
- package/src/repositories/store.ts +21 -32
- package/src/repositories/subscription.test.ts +22 -22
- package/src/repositories/subscription.ts +8 -3
- package/src/repositories/tax-category/index.ts +8 -3
- package/src/repositories/type/actions.ts +21 -3
- package/src/repositories/type/index.ts +5 -3
- package/src/repositories/zone.test.ts +112 -77
- package/src/repositories/zone.ts +5 -3
- package/src/schemas/generated/associate-role.ts +13 -0
- package/src/schemas/generated/attribute-group.ts +12 -0
- package/src/schemas/generated/business-unit.ts +38 -0
- package/src/schemas/generated/cart-discount.ts +33 -0
- package/src/schemas/generated/cart.ts +61 -0
- package/src/schemas/generated/category.ts +25 -0
- package/src/schemas/generated/channel.ts +21 -0
- package/src/schemas/generated/common.ts +1372 -0
- package/src/schemas/generated/custom-object.ts +11 -0
- package/src/schemas/generated/customer-group.ts +11 -0
- package/src/schemas/generated/customer.ts +47 -0
- package/src/schemas/generated/discount-code.ts +25 -0
- package/src/schemas/generated/discount-group.ts +13 -0
- package/src/schemas/generated/extension.ts +15 -0
- package/src/schemas/generated/index.ts +42 -0
- package/src/schemas/generated/inventory-entry.ts +20 -0
- package/src/schemas/generated/my-quote-request.ts +10 -0
- package/src/schemas/generated/order-edit.ts +18 -0
- package/src/schemas/generated/order-from-cart.ts +25 -0
- package/src/schemas/generated/payment.ts +30 -0
- package/src/schemas/generated/product-discount.ts +20 -0
- package/src/schemas/generated/product-selection.ts +18 -0
- package/src/schemas/generated/product-tailoring.ts +26 -0
- package/src/schemas/generated/product-type.ts +12 -0
- package/src/schemas/generated/product.ts +37 -0
- package/src/schemas/generated/quote-request.ts +19 -0
- package/src/schemas/generated/quote.ts +18 -0
- package/src/schemas/generated/recurrence-policy.ts +15 -0
- package/src/schemas/generated/recurring-order.ts +19 -0
- package/src/schemas/generated/review.ts +24 -0
- package/src/schemas/generated/shipping-method.ts +24 -0
- package/src/schemas/generated/shopping-list.ts +28 -0
- package/src/schemas/generated/staged-quote.ts +18 -0
- package/src/schemas/generated/standalone-price.ts +32 -0
- package/src/schemas/generated/state.ts +20 -0
- package/src/schemas/generated/store.ts +23 -0
- package/src/schemas/generated/subscription.ts +20 -0
- package/src/schemas/generated/tax-category.ts +12 -0
- package/src/schemas/generated/type.ts +17 -0
- package/src/schemas/generated/zone.ts +12 -0
- package/src/schemas/update-request.ts +3 -5
- package/src/server.ts +32 -4
- package/src/services/abstract.ts +207 -101
- package/src/services/as-associate-cart.test.ts +28 -36
- package/src/services/as-associate-cart.ts +15 -12
- package/src/services/as-associate-order.test.ts +33 -40
- package/src/services/as-associate-order.ts +15 -12
- package/src/services/as-associate-quote-request.ts +15 -12
- package/src/services/as-associate-shopping-list.test.ts +25 -35
- package/src/services/as-associate-shopping-list.ts +15 -12
- package/src/services/as-associate.test.ts +21 -15
- package/src/services/as-associate.ts +23 -22
- package/src/services/associate-roles.test.ts +16 -22
- package/src/services/associate-roles.ts +2 -2
- package/src/services/attribute-group.test.ts +40 -44
- package/src/services/attribute-group.ts +2 -2
- package/src/services/business-units.test.ts +227 -163
- package/src/services/business-units.ts +2 -2
- package/src/services/cart-discount.test.ts +253 -187
- package/src/services/cart-discount.ts +2 -2
- package/src/services/cart.test.ts +833 -832
- package/src/services/cart.ts +31 -12
- package/src/services/category.test.ts +208 -130
- package/src/services/category.ts +2 -2
- package/src/services/channel.test.ts +39 -44
- package/src/services/channel.ts +2 -2
- package/src/services/custom-object.test.ts +103 -79
- package/src/services/custom-object.ts +106 -38
- package/src/services/customer-group.test.ts +39 -44
- package/src/services/customer-group.ts +2 -2
- package/src/services/customer.test.ts +357 -292
- package/src/services/customer.ts +70 -23
- package/src/services/discount-code.test.ts +57 -68
- package/src/services/discount-code.ts +2 -2
- package/src/services/discount-group.test.ts +111 -134
- package/src/services/discount-group.ts +2 -2
- package/src/services/draft-validation.test.ts +255 -0
- package/src/services/extension.test.ts +39 -44
- package/src/services/extension.ts +2 -2
- package/src/services/inventory-entry.test.ts +106 -87
- package/src/services/inventory-entry.ts +2 -2
- package/src/services/my-business-unit.test.ts +82 -112
- package/src/services/my-business-unit.ts +25 -19
- package/src/services/my-cart.test.ts +46 -41
- package/src/services/my-cart.ts +32 -28
- package/src/services/my-customer.test.ts +153 -88
- package/src/services/my-customer.ts +130 -61
- package/src/services/my-order.ts +15 -12
- package/src/services/my-payment.test.ts +30 -24
- package/src/services/my-payment.ts +2 -2
- package/src/services/my-shopping-list.ts +2 -2
- package/src/services/order.test.ts +332 -276
- package/src/services/order.ts +45 -27
- package/src/services/payment.test.ts +31 -29
- package/src/services/payment.ts +2 -2
- package/src/services/product-discount.test.ts +39 -46
- package/src/services/product-discount.ts +2 -2
- package/src/services/product-projection.test.ts +176 -166
- package/src/services/product-projection.ts +31 -15
- package/src/services/product-selection.test.ts +17 -9
- package/src/services/product-selection.ts +2 -2
- package/src/services/product-type.test.ts +80 -21
- package/src/services/product-type.ts +2 -2
- package/src/services/product.test.ts +569 -534
- package/src/services/product.ts +14 -7
- package/src/services/project.test.ts +22 -12
- package/src/services/project.ts +28 -13
- package/src/services/quote-request.test.ts +36 -39
- package/src/services/quote-request.ts +2 -2
- package/src/services/quote-staged.ts +2 -2
- package/src/services/quote.ts +2 -2
- package/src/services/recurrence-policy.test.ts +114 -139
- package/src/services/recurrence-policy.ts +2 -2
- package/src/services/recurring-order.test.ts +149 -194
- package/src/services/recurring-order.ts +2 -2
- package/src/services/reviews.test.ts +127 -106
- package/src/services/reviews.ts +2 -2
- package/src/services/shipping-method.test.ts +96 -125
- package/src/services/shipping-method.ts +24 -12
- package/src/services/shopping-list.test.ts +183 -141
- package/src/services/shopping-list.ts +2 -2
- package/src/services/standalone-price.test.ts +60 -46
- package/src/services/standalone-price.ts +2 -2
- package/src/services/state.test.ts +20 -25
- package/src/services/state.ts +2 -2
- package/src/services/store.test.ts +26 -45
- package/src/services/store.ts +2 -2
- package/src/services/subscription.test.ts +39 -44
- package/src/services/subscription.ts +2 -2
- package/src/services/tax-category.test.ts +33 -36
- package/src/services/tax-category.ts +2 -2
- package/src/services/type.test.ts +45 -44
- package/src/services/type.ts +2 -2
- package/src/services/zone.test.ts +40 -44
- package/src/services/zone.ts +2 -2
- package/src/shipping.ts +41 -11
- package/src/storage/abstract.ts +248 -17
- package/src/storage/in-memory.ts +147 -290
- package/src/storage/sqlite.ts +429 -0
- package/src/storage/storage-map.ts +75 -0
- package/src/storage/storage.test-helpers.ts +97 -0
- package/src/storage/storage.test.ts +802 -0
- package/src/testing/associate-role.ts +28 -0
- package/src/testing/attribute-group.ts +27 -0
- package/src/testing/business-unit.ts +9 -8
- package/src/testing/cart-discount.ts +34 -0
- package/src/testing/cart.ts +20 -0
- package/src/testing/category.ts +25 -0
- package/src/testing/channel.ts +23 -0
- package/src/testing/custom-object.ts +27 -0
- package/src/testing/customer-group.ts +26 -0
- package/src/testing/customer.ts +36 -33
- package/src/testing/discount-code.ts +29 -0
- package/src/testing/discount-group.ts +27 -0
- package/src/testing/extension.ts +32 -0
- package/src/testing/index.ts +33 -0
- package/src/testing/inventory-entry.ts +26 -0
- package/src/testing/order.ts +27 -0
- package/src/testing/payment.ts +23 -0
- package/src/testing/product-discount.ts +33 -0
- package/src/testing/product-selection.ts +28 -0
- package/src/testing/product-type.ts +27 -0
- package/src/testing/product.ts +38 -0
- package/src/testing/quote-request.ts +29 -0
- package/src/testing/recurrence-policy.ts +33 -0
- package/src/testing/recurring-order.ts +32 -0
- package/src/testing/review.ts +24 -0
- package/src/testing/shipping-method.ts +31 -0
- package/src/testing/shopping-list.ts +25 -0
- package/src/testing/standalone-price.ts +31 -0
- package/src/testing/state.ts +21 -0
- package/src/testing/store.ts +26 -0
- package/src/testing/subscription.ts +38 -0
- package/src/testing/tax-category.ts +27 -0
- package/src/testing/type.ts +9 -6
- package/src/testing/zone.ts +22 -0
- package/src/validate.test.ts +122 -0
- package/src/validate.ts +78 -7
- package/src/.env +0 -0
|
@@ -22,46 +22,25 @@ export class QuoteUpdateHandler
|
|
|
22
22
|
resource: Quote,
|
|
23
23
|
{ name, value }: QuoteSetCustomFieldAction,
|
|
24
24
|
) {
|
|
25
|
-
|
|
26
|
-
throw new Error("Resource has no custom field");
|
|
27
|
-
}
|
|
28
|
-
resource.custom.fields[name] = value;
|
|
25
|
+
this._setCustomFieldValues(resource, { name, value });
|
|
29
26
|
}
|
|
30
27
|
|
|
31
|
-
setCustomType(
|
|
28
|
+
async setCustomType(
|
|
32
29
|
context: RepositoryContext,
|
|
33
30
|
resource: Writable<Quote>,
|
|
34
31
|
{ type, fields }: QuoteSetCustomTypeAction,
|
|
35
32
|
) {
|
|
36
|
-
|
|
37
|
-
resource.custom = undefined;
|
|
38
|
-
} else {
|
|
39
|
-
const resolvedType = this._storage.getByResourceIdentifier(
|
|
40
|
-
context.projectKey,
|
|
41
|
-
type,
|
|
42
|
-
);
|
|
43
|
-
if (!resolvedType) {
|
|
44
|
-
throw new Error(`Type ${type} not found`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
resource.custom = {
|
|
48
|
-
type: {
|
|
49
|
-
typeId: "type",
|
|
50
|
-
id: resolvedType.id,
|
|
51
|
-
},
|
|
52
|
-
fields: fields || {},
|
|
53
|
-
};
|
|
54
|
-
}
|
|
33
|
+
await this._setCustomType(context, resource, { type, fields });
|
|
55
34
|
}
|
|
56
35
|
|
|
57
|
-
transitionState(
|
|
36
|
+
async transitionState(
|
|
58
37
|
context: RepositoryContext,
|
|
59
38
|
resource: Writable<Quote>,
|
|
60
39
|
{ state, force }: QuoteTransitionStateAction,
|
|
61
40
|
) {
|
|
62
41
|
let stateReference: StateReference | undefined;
|
|
63
42
|
if (state) {
|
|
64
|
-
stateReference = getReferenceFromResourceIdentifier<StateReference>(
|
|
43
|
+
stateReference = await getReferenceFromResourceIdentifier<StateReference>(
|
|
65
44
|
state,
|
|
66
45
|
context.projectKey,
|
|
67
46
|
this._storage,
|
|
@@ -77,7 +56,5 @@ export class QuoteUpdateHandler
|
|
|
77
56
|
400,
|
|
78
57
|
);
|
|
79
58
|
}
|
|
80
|
-
|
|
81
|
-
return resource;
|
|
82
59
|
}
|
|
83
60
|
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
InvalidOperationError,
|
|
3
|
+
Quote,
|
|
4
|
+
QuoteDraft,
|
|
5
|
+
} from "@commercetools/platform-sdk";
|
|
2
6
|
import type { Config } from "#src/config.ts";
|
|
7
|
+
import { CommercetoolsError } from "#src/exceptions.ts";
|
|
3
8
|
import { getBaseResourceProperties } from "#src/helpers.ts";
|
|
9
|
+
import { QuoteDraftSchema } from "#src/schemas/generated/quote.ts";
|
|
4
10
|
import type { RepositoryContext } from "../abstract.ts";
|
|
5
11
|
import { AbstractResourceRepository } from "../abstract.ts";
|
|
6
12
|
import { QuoteUpdateHandler } from "./actions.ts";
|
|
@@ -9,25 +15,42 @@ export class QuoteRepository extends AbstractResourceRepository<"quote"> {
|
|
|
9
15
|
constructor(config: Config) {
|
|
10
16
|
super("quote", config);
|
|
11
17
|
this.actions = new QuoteUpdateHandler(config.storage);
|
|
18
|
+
this.draftSchema = QuoteDraftSchema;
|
|
12
19
|
}
|
|
13
20
|
|
|
14
|
-
create(context: RepositoryContext, draft: QuoteDraft): Quote {
|
|
15
|
-
const staged = this._storage.getByResourceIdentifier<"staged-quote">(
|
|
21
|
+
async create(context: RepositoryContext, draft: QuoteDraft): Promise<Quote> {
|
|
22
|
+
const staged = await this._storage.getByResourceIdentifier<"staged-quote">(
|
|
16
23
|
context.projectKey,
|
|
17
24
|
draft.stagedQuote,
|
|
18
25
|
);
|
|
19
26
|
|
|
20
|
-
|
|
27
|
+
if (!staged.quotationCart) {
|
|
28
|
+
throw new CommercetoolsError<InvalidOperationError>(
|
|
29
|
+
{
|
|
30
|
+
code: "InvalidOperation",
|
|
31
|
+
message: "Staged quote does not have a quotation cart",
|
|
32
|
+
},
|
|
33
|
+
400,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const cart = await this._storage.getByResourceIdentifier<"cart">(
|
|
21
38
|
context.projectKey,
|
|
22
39
|
staged.quotationCart,
|
|
23
40
|
);
|
|
24
41
|
|
|
25
42
|
if (!cart.customerId) {
|
|
26
|
-
throw new
|
|
43
|
+
throw new CommercetoolsError<InvalidOperationError>(
|
|
44
|
+
{
|
|
45
|
+
code: "InvalidOperation",
|
|
46
|
+
message: "Cart does not have a customer",
|
|
47
|
+
},
|
|
48
|
+
400,
|
|
49
|
+
);
|
|
27
50
|
}
|
|
28
51
|
|
|
29
52
|
const resource: Quote = {
|
|
30
|
-
...getBaseResourceProperties(),
|
|
53
|
+
...getBaseResourceProperties(context.clientId),
|
|
31
54
|
quoteState: "Accepted",
|
|
32
55
|
quoteRequest: staged.quoteRequest,
|
|
33
56
|
lineItems: cart.lineItems,
|
|
@@ -23,46 +23,25 @@ export class QuoteRequestUpdateHandler
|
|
|
23
23
|
resource: QuoteRequest,
|
|
24
24
|
{ name, value }: QuoteRequestSetCustomFieldAction,
|
|
25
25
|
) {
|
|
26
|
-
|
|
27
|
-
throw new Error("Resource has no custom field");
|
|
28
|
-
}
|
|
29
|
-
resource.custom.fields[name] = value;
|
|
26
|
+
this._setCustomFieldValues(resource, { name, value });
|
|
30
27
|
}
|
|
31
28
|
|
|
32
|
-
setCustomType(
|
|
29
|
+
async setCustomType(
|
|
33
30
|
context: RepositoryContext,
|
|
34
31
|
resource: Writable<QuoteRequest>,
|
|
35
32
|
{ type, fields }: QuoteRequestSetCustomTypeAction,
|
|
36
33
|
) {
|
|
37
|
-
|
|
38
|
-
resource.custom = undefined;
|
|
39
|
-
} else {
|
|
40
|
-
const resolvedType = this._storage.getByResourceIdentifier(
|
|
41
|
-
context.projectKey,
|
|
42
|
-
type,
|
|
43
|
-
);
|
|
44
|
-
if (!resolvedType) {
|
|
45
|
-
throw new Error(`Type ${type} not found`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
resource.custom = {
|
|
49
|
-
type: {
|
|
50
|
-
typeId: "type",
|
|
51
|
-
id: resolvedType.id,
|
|
52
|
-
},
|
|
53
|
-
fields: fields || {},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
34
|
+
await this._setCustomType(context, resource, { type, fields });
|
|
56
35
|
}
|
|
57
36
|
|
|
58
|
-
transitionState(
|
|
37
|
+
async transitionState(
|
|
59
38
|
context: RepositoryContext,
|
|
60
39
|
resource: Writable<QuoteRequest>,
|
|
61
40
|
{ state, force }: QuoteRequestTransitionStateAction,
|
|
62
41
|
) {
|
|
63
42
|
let stateReference: StateReference | undefined;
|
|
64
43
|
if (state) {
|
|
65
|
-
stateReference = getReferenceFromResourceIdentifier<StateReference>(
|
|
44
|
+
stateReference = await getReferenceFromResourceIdentifier<StateReference>(
|
|
66
45
|
state,
|
|
67
46
|
context.projectKey,
|
|
68
47
|
this._storage,
|
|
@@ -78,7 +57,5 @@ export class QuoteRequestUpdateHandler
|
|
|
78
57
|
400,
|
|
79
58
|
);
|
|
80
59
|
}
|
|
81
|
-
|
|
82
|
-
return resource;
|
|
83
60
|
}
|
|
84
61
|
}
|
|
@@ -132,10 +132,10 @@ describe("QuoteRequest repository", () => {
|
|
|
132
132
|
},
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
-
storage.add("dummy", "cart", cart);
|
|
135
|
+
await storage.add("dummy", "cart", cart);
|
|
136
136
|
const ctx = { projectKey: "dummy" };
|
|
137
137
|
|
|
138
|
-
const result = repository.create(ctx, {
|
|
138
|
+
const result = await repository.create(ctx, {
|
|
139
139
|
cart: {
|
|
140
140
|
id: cart.id,
|
|
141
141
|
typeId: "cart",
|
|
@@ -144,7 +144,7 @@ describe("QuoteRequest repository", () => {
|
|
|
144
144
|
});
|
|
145
145
|
expect(result.cart?.id).toBe(cart.id);
|
|
146
146
|
|
|
147
|
-
const items = repository.query(ctx);
|
|
147
|
+
const items = await repository.query(ctx);
|
|
148
148
|
expect(items.count).toBe(1);
|
|
149
149
|
|
|
150
150
|
expect(result.billingAddress).toEqual(cart.billingAddress);
|
|
@@ -2,12 +2,16 @@ import assert from "node:assert";
|
|
|
2
2
|
import type {
|
|
3
3
|
Cart,
|
|
4
4
|
CartReference,
|
|
5
|
+
InvalidOperationError,
|
|
5
6
|
MyQuoteRequestDraft,
|
|
6
7
|
QuoteRequest,
|
|
7
8
|
QuoteRequestDraft,
|
|
9
|
+
ResourceNotFoundError,
|
|
8
10
|
} from "@commercetools/platform-sdk";
|
|
9
11
|
import type { Config } from "#src/config.ts";
|
|
12
|
+
import { CommercetoolsError } from "#src/exceptions.ts";
|
|
10
13
|
import { getBaseResourceProperties } from "#src/helpers.ts";
|
|
14
|
+
import { QuoteRequestDraftSchema } from "#src/schemas/generated/quote-request.ts";
|
|
11
15
|
import type { RepositoryContext } from "../abstract.ts";
|
|
12
16
|
import { AbstractResourceRepository } from "../abstract.ts";
|
|
13
17
|
import { QuoteRequestUpdateHandler } from "./actions.ts";
|
|
@@ -16,42 +20,58 @@ export class QuoteRequestRepository extends AbstractResourceRepository<"quote-re
|
|
|
16
20
|
constructor(config: Config) {
|
|
17
21
|
super("quote-request", config);
|
|
18
22
|
this.actions = new QuoteRequestUpdateHandler(config.storage);
|
|
23
|
+
this.draftSchema = QuoteRequestDraftSchema;
|
|
19
24
|
}
|
|
20
25
|
|
|
21
|
-
create(
|
|
26
|
+
async create(
|
|
22
27
|
context: RepositoryContext,
|
|
23
28
|
draft: QuoteRequestDraft | MyQuoteRequestDraft,
|
|
24
|
-
): QuoteRequest {
|
|
29
|
+
): Promise<QuoteRequest> {
|
|
25
30
|
// Handle the 'my' version of the draft
|
|
26
31
|
if ("cartId" in draft) {
|
|
27
|
-
return this.createFromCart(context, {
|
|
32
|
+
return await this.createFromCart(context, {
|
|
28
33
|
id: draft.cartId,
|
|
29
34
|
typeId: "cart",
|
|
30
35
|
});
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
assert(draft.cart, "draft.cart is missing");
|
|
34
|
-
return this.createFromCart(context, {
|
|
39
|
+
return await this.createFromCart(context, {
|
|
35
40
|
id: draft.cart.id!,
|
|
36
41
|
typeId: "cart",
|
|
37
42
|
});
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
createFromCart(
|
|
41
|
-
|
|
45
|
+
async createFromCart(
|
|
46
|
+
context: RepositoryContext,
|
|
47
|
+
cartReference: CartReference,
|
|
48
|
+
) {
|
|
49
|
+
const cart = (await this._storage.getByResourceIdentifier(
|
|
42
50
|
context.projectKey,
|
|
43
51
|
cartReference,
|
|
44
|
-
) as Cart | null;
|
|
52
|
+
)) as Cart | null;
|
|
45
53
|
if (!cart) {
|
|
46
|
-
throw new
|
|
54
|
+
throw new CommercetoolsError<ResourceNotFoundError>(
|
|
55
|
+
{
|
|
56
|
+
code: "ResourceNotFound",
|
|
57
|
+
message: "Cannot find cart",
|
|
58
|
+
},
|
|
59
|
+
404,
|
|
60
|
+
);
|
|
47
61
|
}
|
|
48
62
|
|
|
49
63
|
if (!cart.customerId) {
|
|
50
|
-
throw new
|
|
64
|
+
throw new CommercetoolsError<InvalidOperationError>(
|
|
65
|
+
{
|
|
66
|
+
code: "InvalidOperation",
|
|
67
|
+
message: "Cart does not have a customer",
|
|
68
|
+
},
|
|
69
|
+
400,
|
|
70
|
+
);
|
|
51
71
|
}
|
|
52
72
|
|
|
53
73
|
const resource: QuoteRequest = {
|
|
54
|
-
...getBaseResourceProperties(),
|
|
74
|
+
...getBaseResourceProperties(context.clientId),
|
|
55
75
|
billingAddress: cart.billingAddress,
|
|
56
76
|
cart: cartReference,
|
|
57
77
|
country: cart.country,
|
|
@@ -75,6 +95,6 @@ export class QuoteRequestRepository extends AbstractResourceRepository<"quote-re
|
|
|
75
95
|
totalPrice: cart.totalPrice,
|
|
76
96
|
store: cart.store,
|
|
77
97
|
};
|
|
78
|
-
return this.saveNew(context, resource);
|
|
98
|
+
return await this.saveNew(context, resource);
|
|
79
99
|
}
|
|
80
100
|
}
|
|
@@ -23,46 +23,25 @@ export class StagedQuoteUpdateHandler
|
|
|
23
23
|
resource: StagedQuote,
|
|
24
24
|
{ name, value }: StagedQuoteSetCustomFieldAction,
|
|
25
25
|
) {
|
|
26
|
-
|
|
27
|
-
throw new Error("Resource has no custom field");
|
|
28
|
-
}
|
|
29
|
-
resource.custom.fields[name] = value;
|
|
26
|
+
this._setCustomFieldValues(resource, { name, value });
|
|
30
27
|
}
|
|
31
28
|
|
|
32
|
-
setCustomType(
|
|
29
|
+
async setCustomType(
|
|
33
30
|
context: RepositoryContext,
|
|
34
31
|
resource: Writable<StagedQuote>,
|
|
35
32
|
{ type, fields }: StagedQuoteSetCustomTypeAction,
|
|
36
33
|
) {
|
|
37
|
-
|
|
38
|
-
resource.custom = undefined;
|
|
39
|
-
} else {
|
|
40
|
-
const resolvedType = this._storage.getByResourceIdentifier(
|
|
41
|
-
context.projectKey,
|
|
42
|
-
type,
|
|
43
|
-
);
|
|
44
|
-
if (!resolvedType) {
|
|
45
|
-
throw new Error(`Type ${type} not found`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
resource.custom = {
|
|
49
|
-
type: {
|
|
50
|
-
typeId: "type",
|
|
51
|
-
id: resolvedType.id,
|
|
52
|
-
},
|
|
53
|
-
fields: fields || {},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
34
|
+
await this._setCustomType(context, resource, { type, fields });
|
|
56
35
|
}
|
|
57
36
|
|
|
58
|
-
transitionState(
|
|
37
|
+
async transitionState(
|
|
59
38
|
context: RepositoryContext,
|
|
60
39
|
resource: Writable<StagedQuote>,
|
|
61
40
|
{ state, force }: StagedQuoteTransitionStateAction,
|
|
62
41
|
) {
|
|
63
42
|
let stateReference: StateReference | undefined;
|
|
64
43
|
if (state) {
|
|
65
|
-
stateReference = getReferenceFromResourceIdentifier<StateReference>(
|
|
44
|
+
stateReference = await getReferenceFromResourceIdentifier<StateReference>(
|
|
66
45
|
state,
|
|
67
46
|
context.projectKey,
|
|
68
47
|
this._storage,
|
|
@@ -78,7 +57,5 @@ export class StagedQuoteUpdateHandler
|
|
|
78
57
|
400,
|
|
79
58
|
);
|
|
80
59
|
}
|
|
81
|
-
|
|
82
|
-
return resource;
|
|
83
60
|
}
|
|
84
61
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
ResourceNotFoundError,
|
|
2
3
|
StagedQuote,
|
|
3
4
|
StagedQuoteDraft,
|
|
4
5
|
} from "@commercetools/platform-sdk";
|
|
5
6
|
import type { Config } from "#src/config.ts";
|
|
7
|
+
import { CommercetoolsError } from "#src/exceptions.ts";
|
|
6
8
|
import { getBaseResourceProperties } from "#src/helpers.ts";
|
|
9
|
+
import { StagedQuoteDraftSchema } from "#src/schemas/generated/staged-quote.ts";
|
|
7
10
|
import type { RepositoryContext } from "../abstract.ts";
|
|
8
11
|
import { AbstractResourceRepository } from "../abstract.ts";
|
|
9
12
|
import { StagedQuoteUpdateHandler } from "./actions.ts";
|
|
@@ -12,25 +15,36 @@ export class StagedQuoteRepository extends AbstractResourceRepository<"staged-qu
|
|
|
12
15
|
constructor(config: Config) {
|
|
13
16
|
super("staged-quote", config);
|
|
14
17
|
this.actions = new StagedQuoteUpdateHandler(config.storage);
|
|
18
|
+
this.draftSchema = StagedQuoteDraftSchema;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
create(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
async create(
|
|
22
|
+
context: RepositoryContext,
|
|
23
|
+
draft: StagedQuoteDraft,
|
|
24
|
+
): Promise<StagedQuote> {
|
|
25
|
+
const quoteRequest =
|
|
26
|
+
await this._storage.getByResourceIdentifier<"quote-request">(
|
|
27
|
+
context.projectKey,
|
|
28
|
+
draft.quoteRequest,
|
|
29
|
+
);
|
|
22
30
|
|
|
23
31
|
if (!quoteRequest.cart) {
|
|
24
|
-
throw new
|
|
32
|
+
throw new CommercetoolsError<ResourceNotFoundError>(
|
|
33
|
+
{
|
|
34
|
+
code: "ResourceNotFound",
|
|
35
|
+
message: "Cannot find quote request",
|
|
36
|
+
},
|
|
37
|
+
404,
|
|
38
|
+
);
|
|
25
39
|
}
|
|
26
40
|
|
|
27
|
-
const cart = this._storage.getByResourceIdentifier<"cart">(
|
|
41
|
+
const cart = await this._storage.getByResourceIdentifier<"cart">(
|
|
28
42
|
context.projectKey,
|
|
29
43
|
quoteRequest.cart,
|
|
30
44
|
);
|
|
31
45
|
|
|
32
46
|
const resource: StagedQuote = {
|
|
33
|
-
...getBaseResourceProperties(),
|
|
47
|
+
...getBaseResourceProperties(context.clientId),
|
|
34
48
|
stagedQuoteState: "InProgress",
|
|
35
49
|
quoteRequest: {
|
|
36
50
|
typeId: "quote-request",
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
} from "@commercetools/platform-sdk";
|
|
5
5
|
import type { Config } from "#src/config.ts";
|
|
6
6
|
import { getBaseResourceProperties } from "#src/helpers.ts";
|
|
7
|
+
import { RecurrencePolicyDraftSchema } from "#src/schemas/generated/recurrence-policy.ts";
|
|
7
8
|
import {
|
|
8
9
|
AbstractResourceRepository,
|
|
9
10
|
type RepositoryContext,
|
|
@@ -14,19 +15,20 @@ export class RecurrencePolicyRepository extends AbstractResourceRepository<"recu
|
|
|
14
15
|
constructor(config: Config) {
|
|
15
16
|
super("recurrence-policy", config);
|
|
16
17
|
this.actions = new RecurrencePolicyUpdateHandler(config.storage);
|
|
18
|
+
this.draftSchema = RecurrencePolicyDraftSchema;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
create(
|
|
21
|
+
async create(
|
|
20
22
|
context: RepositoryContext,
|
|
21
23
|
draft: RecurrencePolicyDraft,
|
|
22
|
-
): RecurrencePolicy {
|
|
24
|
+
): Promise<RecurrencePolicy> {
|
|
23
25
|
const resource: RecurrencePolicy = {
|
|
24
|
-
...getBaseResourceProperties(),
|
|
26
|
+
...getBaseResourceProperties(context.clientId),
|
|
25
27
|
key: draft.key,
|
|
26
28
|
name: draft.name,
|
|
27
29
|
description: draft.description,
|
|
28
30
|
schedule: draft.schedule,
|
|
29
31
|
};
|
|
30
|
-
return this.saveNew(context, resource);
|
|
32
|
+
return await this.saveNew(context, resource);
|
|
31
33
|
}
|
|
32
34
|
}
|
|
@@ -25,40 +25,15 @@ export class RecurringOrderUpdateHandler
|
|
|
25
25
|
resource: Writable<RecurringOrder>,
|
|
26
26
|
{ name, value }: RecurringOrderSetCustomFieldAction,
|
|
27
27
|
) {
|
|
28
|
-
|
|
29
|
-
throw new Error("Resource has no custom field");
|
|
30
|
-
}
|
|
31
|
-
if (value === null) {
|
|
32
|
-
delete resource.custom.fields[name];
|
|
33
|
-
} else {
|
|
34
|
-
resource.custom.fields[name] = value;
|
|
35
|
-
}
|
|
28
|
+
this._setCustomFieldValues(resource, { name, value });
|
|
36
29
|
}
|
|
37
30
|
|
|
38
|
-
setCustomType(
|
|
31
|
+
async setCustomType(
|
|
39
32
|
context: RepositoryContext,
|
|
40
33
|
resource: Writable<RecurringOrder>,
|
|
41
34
|
{ type, fields }: RecurringOrderSetCustomTypeAction,
|
|
42
35
|
) {
|
|
43
|
-
|
|
44
|
-
resource.custom = undefined;
|
|
45
|
-
} else {
|
|
46
|
-
const resolvedType = this._storage.getByResourceIdentifier(
|
|
47
|
-
context.projectKey,
|
|
48
|
-
type,
|
|
49
|
-
);
|
|
50
|
-
if (!resolvedType) {
|
|
51
|
-
throw new Error(`Type ${type} not found`);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
resource.custom = {
|
|
55
|
-
type: {
|
|
56
|
-
typeId: "type",
|
|
57
|
-
id: resolvedType.id,
|
|
58
|
-
},
|
|
59
|
-
fields: fields || {},
|
|
60
|
-
};
|
|
61
|
-
}
|
|
36
|
+
await this._setCustomType(context, resource, { type, fields });
|
|
62
37
|
}
|
|
63
38
|
|
|
64
39
|
setExpiresAt(
|
|
@@ -81,14 +56,14 @@ export class RecurringOrderUpdateHandler
|
|
|
81
56
|
context: RepositoryContext,
|
|
82
57
|
resource: Writable<RecurringOrder>,
|
|
83
58
|
{
|
|
84
|
-
|
|
59
|
+
skipConfigurationInputDraft,
|
|
85
60
|
updatedExpiresAt,
|
|
86
61
|
}: RecurringOrderSetOrderSkipConfigurationAction,
|
|
87
62
|
) {
|
|
88
|
-
if (
|
|
63
|
+
if (skipConfigurationInputDraft) {
|
|
89
64
|
resource.skipConfiguration = {
|
|
90
|
-
type:
|
|
91
|
-
totalToSkip:
|
|
65
|
+
type: skipConfigurationInputDraft.type,
|
|
66
|
+
totalToSkip: skipConfigurationInputDraft.totalToSkip,
|
|
92
67
|
skipped: 0,
|
|
93
68
|
lastSkippedAt: undefined,
|
|
94
69
|
};
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
} from "@commercetools/platform-sdk";
|
|
6
6
|
import type { Config } from "#src/config.ts";
|
|
7
7
|
import { getBaseResourceProperties } from "#src/helpers.ts";
|
|
8
|
+
import { RecurringOrderDraftSchema } from "#src/schemas/generated/recurring-order.ts";
|
|
8
9
|
import {
|
|
9
10
|
AbstractResourceRepository,
|
|
10
11
|
type RepositoryContext,
|
|
@@ -16,23 +17,24 @@ export class RecurringOrderRepository extends AbstractResourceRepository<"recurr
|
|
|
16
17
|
constructor(config: Config) {
|
|
17
18
|
super("recurring-order", config);
|
|
18
19
|
this.actions = new RecurringOrderUpdateHandler(config.storage);
|
|
20
|
+
this.draftSchema = RecurringOrderDraftSchema;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
create(
|
|
23
|
+
async create(
|
|
22
24
|
context: RepositoryContext,
|
|
23
25
|
draft: RecurringOrderDraft,
|
|
24
|
-
): RecurringOrder {
|
|
26
|
+
): Promise<RecurringOrder> {
|
|
25
27
|
assert(draft.cart, "draft.cart is missing");
|
|
26
28
|
|
|
27
29
|
const orderRepo = new OrderRepository(this.config);
|
|
28
30
|
|
|
29
|
-
const initialOrder = orderRepo.createFromCart(context, {
|
|
31
|
+
const initialOrder = await orderRepo.createFromCart(context, {
|
|
30
32
|
id: draft.cart.id!,
|
|
31
33
|
typeId: "cart",
|
|
32
34
|
});
|
|
33
35
|
|
|
34
36
|
const resource: RecurringOrder = {
|
|
35
|
-
...getBaseResourceProperties(),
|
|
37
|
+
...getBaseResourceProperties(context.clientId),
|
|
36
38
|
key: draft.key,
|
|
37
39
|
cart: {
|
|
38
40
|
typeId: "cart",
|
|
@@ -42,11 +44,11 @@ export class RecurringOrderRepository extends AbstractResourceRepository<"recurr
|
|
|
42
44
|
typeId: "order",
|
|
43
45
|
id: initialOrder.id,
|
|
44
46
|
},
|
|
45
|
-
startsAt: draft.startsAt,
|
|
47
|
+
startsAt: draft.startsAt ?? new Date().toISOString(),
|
|
46
48
|
expiresAt: draft.expiresAt,
|
|
47
49
|
recurringOrderState: "Active",
|
|
48
50
|
schedule: { type: "standard", intervalUnit: "month", value: 1 },
|
|
49
51
|
};
|
|
50
|
-
return this.saveNew(context, resource);
|
|
52
|
+
return await this.saveNew(context, resource);
|
|
51
53
|
}
|
|
52
54
|
}
|