@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
package/src/services/customer.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
CustomerCreateEmailToken,
|
|
3
|
+
CustomerCreatePasswordResetToken,
|
|
4
|
+
CustomerDraft,
|
|
5
|
+
CustomerEmailVerify,
|
|
6
|
+
CustomerResetPassword,
|
|
7
|
+
CustomerSignInResult,
|
|
8
|
+
} from "@commercetools/platform-sdk";
|
|
9
|
+
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
|
10
|
+
import { validateDraft } from "#src/validate.ts";
|
|
3
11
|
import type { CustomerRepository } from "../repositories/customer/index.ts";
|
|
4
12
|
import { getRepositoryContext } from "../repositories/helpers.ts";
|
|
5
13
|
import AbstractService from "./abstract.ts";
|
|
@@ -7,7 +15,7 @@ import AbstractService from "./abstract.ts";
|
|
|
7
15
|
export class CustomerService extends AbstractService {
|
|
8
16
|
public repository: CustomerRepository;
|
|
9
17
|
|
|
10
|
-
constructor(parent:
|
|
18
|
+
constructor(parent: FastifyInstance, repository: CustomerRepository) {
|
|
11
19
|
super(parent);
|
|
12
20
|
this.repository = repository;
|
|
13
21
|
}
|
|
@@ -16,57 +24,96 @@ export class CustomerService extends AbstractService {
|
|
|
16
24
|
return "customers";
|
|
17
25
|
}
|
|
18
26
|
|
|
19
|
-
extraRoutes(parent:
|
|
27
|
+
extraRoutes(parent: FastifyInstance) {
|
|
20
28
|
parent.post("/password-token", this.passwordResetToken.bind(this));
|
|
21
29
|
parent.post("/password/reset", this.passwordReset.bind(this));
|
|
22
30
|
parent.post("/email-token", this.emailToken.bind(this));
|
|
23
31
|
parent.post("/email/confirm", this.emailTokenConfirm.bind(this));
|
|
24
32
|
}
|
|
25
33
|
|
|
26
|
-
post(
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
async post(
|
|
35
|
+
request: FastifyRequest<{
|
|
36
|
+
Params: Record<string, string>;
|
|
37
|
+
Querystring: Record<string, any>;
|
|
38
|
+
Body: CustomerDraft;
|
|
39
|
+
}>,
|
|
40
|
+
reply: FastifyReply,
|
|
41
|
+
) {
|
|
42
|
+
// Validate the draft against the schema when strict mode is enabled
|
|
43
|
+
if (this.repository.strict && this.repository.draftSchema) {
|
|
44
|
+
validateDraft(request.body, this.repository.draftSchema);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const resource = await this.repository.create(
|
|
29
48
|
getRepositoryContext(request),
|
|
30
|
-
|
|
49
|
+
request.body,
|
|
31
50
|
);
|
|
32
|
-
const expanded = this._expandWithId(request, resource.id);
|
|
51
|
+
const expanded = await this._expandWithId(request, resource.id);
|
|
33
52
|
|
|
34
53
|
const result: CustomerSignInResult = {
|
|
35
54
|
customer: expanded,
|
|
36
55
|
};
|
|
37
|
-
|
|
56
|
+
return reply.status(this.createStatusCode).send(result);
|
|
38
57
|
}
|
|
39
58
|
|
|
40
|
-
passwordResetToken(
|
|
41
|
-
|
|
59
|
+
async passwordResetToken(
|
|
60
|
+
request: FastifyRequest<{
|
|
61
|
+
Params: Record<string, string>;
|
|
62
|
+
Body: CustomerCreatePasswordResetToken;
|
|
63
|
+
}>,
|
|
64
|
+
reply: FastifyReply,
|
|
65
|
+
) {
|
|
66
|
+
const customer = await this.repository.passwordResetToken(
|
|
42
67
|
getRepositoryContext(request),
|
|
43
68
|
request.body,
|
|
44
69
|
);
|
|
45
70
|
|
|
46
|
-
|
|
71
|
+
return reply.status(200).send(customer);
|
|
47
72
|
}
|
|
48
73
|
|
|
49
|
-
passwordReset(
|
|
50
|
-
|
|
74
|
+
async passwordReset(
|
|
75
|
+
request: FastifyRequest<{
|
|
76
|
+
Params: Record<string, string>;
|
|
77
|
+
Body: CustomerResetPassword;
|
|
78
|
+
}>,
|
|
79
|
+
reply: FastifyReply,
|
|
80
|
+
) {
|
|
81
|
+
const customer = await this.repository.passwordReset(
|
|
51
82
|
getRepositoryContext(request),
|
|
52
83
|
request.body,
|
|
53
84
|
);
|
|
54
85
|
|
|
55
|
-
|
|
86
|
+
return reply.status(200).send(customer);
|
|
56
87
|
}
|
|
57
88
|
|
|
58
|
-
emailToken(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
89
|
+
async emailToken(
|
|
90
|
+
request: FastifyRequest<{
|
|
91
|
+
Params: Record<string, string>;
|
|
92
|
+
Body: CustomerCreateEmailToken;
|
|
93
|
+
}>,
|
|
94
|
+
reply: FastifyReply,
|
|
95
|
+
) {
|
|
96
|
+
const body = request.body;
|
|
97
|
+
const id = body.id;
|
|
98
|
+
const token = await this.repository.emailToken(
|
|
99
|
+
getRepositoryContext(request),
|
|
100
|
+
id,
|
|
101
|
+
);
|
|
102
|
+
return reply.status(200).send(token);
|
|
62
103
|
}
|
|
63
104
|
|
|
64
|
-
emailTokenConfirm(
|
|
65
|
-
|
|
105
|
+
async emailTokenConfirm(
|
|
106
|
+
request: FastifyRequest<{
|
|
107
|
+
Params: Record<string, string>;
|
|
108
|
+
Body: CustomerEmailVerify;
|
|
109
|
+
}>,
|
|
110
|
+
reply: FastifyReply,
|
|
111
|
+
) {
|
|
112
|
+
const customer = await this.repository.emailTokenConfirm(
|
|
66
113
|
getRepositoryContext(request),
|
|
67
114
|
request.body,
|
|
68
115
|
);
|
|
69
116
|
|
|
70
|
-
|
|
117
|
+
return reply.status(200).send(customer);
|
|
71
118
|
}
|
|
72
119
|
}
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import type { DiscountCodeDraft } from "@commercetools/platform-sdk";
|
|
2
|
-
import supertest from "supertest";
|
|
3
1
|
import { describe, expect, test } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
cartDiscountDraftFactory,
|
|
4
|
+
discountCodeDraftFactory,
|
|
5
|
+
} from "#src/testing/index.ts";
|
|
4
6
|
import { CommercetoolsMock } from "../index.ts";
|
|
5
7
|
|
|
6
8
|
const ctMock = new CommercetoolsMock();
|
|
7
9
|
|
|
8
10
|
describe("DiscountCode", () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const cartDiscountResponse = await supertest(ctMock.app)
|
|
12
|
-
.post("/dummy/cart-discounts")
|
|
13
|
-
.send({
|
|
14
|
-
key: "test-cart-discount",
|
|
15
|
-
name: {
|
|
16
|
-
en: "Test Cart Discount",
|
|
17
|
-
},
|
|
18
|
-
value: {
|
|
19
|
-
type: "relative",
|
|
20
|
-
permyriad: 1000,
|
|
21
|
-
},
|
|
22
|
-
cartPredicate: "1 = 1",
|
|
23
|
-
target: {
|
|
24
|
-
type: "totalPrice",
|
|
25
|
-
},
|
|
26
|
-
sortOrder: "0.1",
|
|
27
|
-
});
|
|
11
|
+
const cartDiscountFactory = cartDiscountDraftFactory(ctMock);
|
|
12
|
+
const discountCodeFactory = discountCodeDraftFactory(ctMock);
|
|
28
13
|
|
|
29
|
-
|
|
14
|
+
test("Create discount code", async () => {
|
|
15
|
+
const cartDiscount = await cartDiscountFactory.create({
|
|
16
|
+
key: "test-cart-discount",
|
|
17
|
+
name: { en: "Test Cart Discount" },
|
|
18
|
+
value: {
|
|
19
|
+
type: "relative",
|
|
20
|
+
permyriad: 1000,
|
|
21
|
+
},
|
|
22
|
+
cartPredicate: "1 = 1",
|
|
23
|
+
target: {
|
|
24
|
+
type: "totalPrice",
|
|
25
|
+
},
|
|
26
|
+
sortOrder: "0.1",
|
|
27
|
+
});
|
|
30
28
|
|
|
31
|
-
const draft
|
|
29
|
+
const draft = discountCodeFactory.build({
|
|
32
30
|
key: "SAVE10",
|
|
33
31
|
code: "SAVE10",
|
|
34
|
-
name: {
|
|
35
|
-
en: "Save 10% Discount",
|
|
36
|
-
},
|
|
32
|
+
name: { en: "Save 10% Discount" },
|
|
37
33
|
cartDiscounts: [
|
|
38
34
|
{
|
|
39
35
|
typeId: "cart-discount",
|
|
40
|
-
id:
|
|
36
|
+
id: cartDiscount.id,
|
|
41
37
|
},
|
|
42
38
|
],
|
|
43
39
|
isActive: true,
|
|
44
|
-
};
|
|
45
|
-
const response = await supertest(ctMock.app)
|
|
46
|
-
.post("/dummy/discount-codes")
|
|
47
|
-
.send(draft);
|
|
40
|
+
});
|
|
48
41
|
|
|
49
|
-
|
|
42
|
+
const response = await ctMock.app.inject({
|
|
43
|
+
method: "POST",
|
|
44
|
+
url: "/dummy/discount-codes",
|
|
45
|
+
payload: draft,
|
|
46
|
+
});
|
|
50
47
|
|
|
51
|
-
expect(response.
|
|
48
|
+
expect(response.statusCode).toBe(201);
|
|
49
|
+
expect(response.json()).toEqual({
|
|
52
50
|
applicationVersion: 1,
|
|
53
51
|
cartDiscounts: [
|
|
54
52
|
{
|
|
55
|
-
id:
|
|
53
|
+
id: cartDiscount.id,
|
|
56
54
|
typeId: "cart-discount",
|
|
57
55
|
},
|
|
58
56
|
],
|
|
59
57
|
code: "SAVE10",
|
|
60
58
|
createdAt: expect.anything(),
|
|
59
|
+
createdBy: expect.anything(),
|
|
61
60
|
groups: [],
|
|
62
61
|
id: expect.anything(),
|
|
63
62
|
isActive: true,
|
|
64
63
|
lastModifiedAt: expect.anything(),
|
|
64
|
+
lastModifiedBy: expect.anything(),
|
|
65
65
|
name: {
|
|
66
66
|
en: "Save 10% Discount",
|
|
67
67
|
},
|
|
@@ -71,50 +71,39 @@ describe("DiscountCode", () => {
|
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
test("Get discount code", async () => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
target: {
|
|
88
|
-
type: "totalPrice",
|
|
89
|
-
},
|
|
90
|
-
sortOrder: "0.1",
|
|
91
|
-
});
|
|
74
|
+
const cartDiscount = await cartDiscountFactory.create({
|
|
75
|
+
key: "test-cart-discount-2",
|
|
76
|
+
name: { en: "Test Cart Discount 2" },
|
|
77
|
+
value: {
|
|
78
|
+
type: "relative",
|
|
79
|
+
permyriad: 500,
|
|
80
|
+
},
|
|
81
|
+
cartPredicate: "1 = 1",
|
|
82
|
+
target: {
|
|
83
|
+
type: "totalPrice",
|
|
84
|
+
},
|
|
85
|
+
sortOrder: "0.1",
|
|
86
|
+
});
|
|
92
87
|
|
|
93
|
-
const
|
|
88
|
+
const discountCode = await discountCodeFactory.create({
|
|
94
89
|
key: "TEST10",
|
|
95
90
|
code: "TEST10",
|
|
96
|
-
name: {
|
|
97
|
-
en: "Test Discount",
|
|
98
|
-
},
|
|
91
|
+
name: { en: "Test Discount" },
|
|
99
92
|
cartDiscounts: [
|
|
100
93
|
{
|
|
101
94
|
typeId: "cart-discount",
|
|
102
|
-
id:
|
|
95
|
+
id: cartDiscount.id,
|
|
103
96
|
},
|
|
104
97
|
],
|
|
105
98
|
isActive: true,
|
|
106
|
-
};
|
|
107
|
-
const createResponse = await supertest(ctMock.app)
|
|
108
|
-
.post("/dummy/discount-codes")
|
|
109
|
-
.send(draft);
|
|
110
|
-
|
|
111
|
-
expect(createResponse.status).toBe(201);
|
|
99
|
+
});
|
|
112
100
|
|
|
113
|
-
const response = await
|
|
114
|
-
|
|
115
|
-
|
|
101
|
+
const response = await ctMock.app.inject({
|
|
102
|
+
method: "GET",
|
|
103
|
+
url: `/dummy/discount-codes/${discountCode.id}`,
|
|
104
|
+
});
|
|
116
105
|
|
|
117
|
-
expect(response.
|
|
118
|
-
expect(response.
|
|
106
|
+
expect(response.statusCode).toBe(200);
|
|
107
|
+
expect(response.json()).toEqual(discountCode);
|
|
119
108
|
});
|
|
120
109
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FastifyInstance } from "fastify";
|
|
2
2
|
import type { DiscountCodeRepository } from "../repositories/discount-code/index.ts";
|
|
3
3
|
import AbstractService from "./abstract.ts";
|
|
4
4
|
|
|
5
5
|
export class DiscountCodeService extends AbstractService {
|
|
6
6
|
public repository: DiscountCodeRepository;
|
|
7
7
|
|
|
8
|
-
constructor(parent:
|
|
8
|
+
constructor(parent: FastifyInstance, repository: DiscountCodeRepository) {
|
|
9
9
|
super(parent);
|
|
10
10
|
this.repository = repository;
|
|
11
11
|
}
|