@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.
Files changed (281) hide show
  1. package/README.md +31 -8
  2. package/dist/abstract-BKFcva6S.mjs +1044 -0
  3. package/dist/abstract-BKFcva6S.mjs.map +1 -0
  4. package/dist/config-BcNSzPZz.d.mts +1718 -0
  5. package/dist/index.d.mts +50 -1633
  6. package/dist/index.mjs +3769 -2653
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/storage/sqlite.d.mts +59 -0
  9. package/dist/storage/sqlite.mjs +234 -0
  10. package/dist/storage/sqlite.mjs.map +1 -0
  11. package/package.json +26 -29
  12. package/src/ctMock.ts +125 -136
  13. package/src/helpers.ts +14 -6
  14. package/src/index.ts +5 -0
  15. package/src/lib/masking.ts +4 -5
  16. package/src/lib/product-review-statistics.test.ts +257 -294
  17. package/src/lib/review-statistics.ts +17 -4
  18. package/src/oauth/helpers.ts +7 -4
  19. package/src/oauth/server.test.ts +102 -62
  20. package/src/oauth/server.ts +215 -213
  21. package/src/oauth/store.ts +20 -6
  22. package/src/orderSearch.ts +3 -3
  23. package/src/product-projection-search.ts +38 -20
  24. package/src/product-search-availability.test.ts +31 -52
  25. package/src/product-search.ts +19 -10
  26. package/src/projectAPI.ts +6 -22
  27. package/src/repositories/abstract.ts +182 -48
  28. package/src/repositories/as-associate.test.ts +19 -19
  29. package/src/repositories/associate-role.ts +12 -23
  30. package/src/repositories/attribute-group.test.ts +23 -23
  31. package/src/repositories/attribute-group.ts +6 -4
  32. package/src/repositories/business-unit.test.ts +63 -57
  33. package/src/repositories/business-unit.ts +107 -55
  34. package/src/repositories/cart/actions.ts +96 -65
  35. package/src/repositories/cart/helpers.ts +15 -11
  36. package/src/repositories/cart/index.test.ts +136 -30
  37. package/src/repositories/cart/index.ts +76 -59
  38. package/src/repositories/cart-discount/actions.ts +12 -44
  39. package/src/repositories/cart-discount/index.ts +20 -8
  40. package/src/repositories/category/actions.ts +27 -27
  41. package/src/repositories/category/index.test.ts +13 -9
  42. package/src/repositories/category/index.ts +40 -23
  43. package/src/repositories/channel.test.ts +53 -51
  44. package/src/repositories/channel.ts +12 -22
  45. package/src/repositories/custom-object.ts +34 -25
  46. package/src/repositories/customer/actions.ts +47 -25
  47. package/src/repositories/customer/index.test.ts +11 -11
  48. package/src/repositories/customer/index.ts +65 -35
  49. package/src/repositories/customer-group.test.ts +44 -42
  50. package/src/repositories/customer-group.ts +12 -22
  51. package/src/repositories/discount-code/actions.ts +3 -19
  52. package/src/repositories/discount-code/index.ts +9 -4
  53. package/src/repositories/discount-group/index.ts +8 -3
  54. package/src/repositories/extension.test.ts +27 -27
  55. package/src/repositories/extension.ts +10 -5
  56. package/src/repositories/helpers.ts +126 -47
  57. package/src/repositories/inventory-entry/actions.ts +3 -24
  58. package/src/repositories/inventory-entry/index.ts +19 -11
  59. package/src/repositories/my-customer.ts +13 -12
  60. package/src/repositories/my-order.ts +5 -2
  61. package/src/repositories/order/actions.ts +84 -56
  62. package/src/repositories/order/index.test.ts +36 -31
  63. package/src/repositories/order/index.ts +83 -49
  64. package/src/repositories/order-edit.ts +8 -3
  65. package/src/repositories/payment/actions.ts +64 -44
  66. package/src/repositories/payment/helpers.ts +3 -3
  67. package/src/repositories/payment/index.ts +28 -12
  68. package/src/repositories/product/actions.ts +133 -98
  69. package/src/repositories/product/helpers.ts +29 -16
  70. package/src/repositories/product/index.ts +42 -25
  71. package/src/repositories/product-discount.ts +6 -4
  72. package/src/repositories/product-projection.ts +41 -21
  73. package/src/repositories/product-selection.ts +8 -15
  74. package/src/repositories/product-tailoring.ts +22 -3
  75. package/src/repositories/product-type.ts +45 -4
  76. package/src/repositories/project.ts +57 -13
  77. package/src/repositories/quote/actions.ts +5 -28
  78. package/src/repositories/quote/index.ts +29 -6
  79. package/src/repositories/quote-request/actions.ts +5 -28
  80. package/src/repositories/quote-request/index.test.ts +3 -3
  81. package/src/repositories/quote-request/index.ts +31 -11
  82. package/src/repositories/quote-staged/actions.ts +5 -28
  83. package/src/repositories/quote-staged/index.ts +22 -8
  84. package/src/repositories/recurrence-policy/index.ts +6 -4
  85. package/src/repositories/recurring-order/actions.ts +7 -32
  86. package/src/repositories/recurring-order/index.ts +8 -6
  87. package/src/repositories/review.test.ts +147 -142
  88. package/src/repositories/review.ts +31 -37
  89. package/src/repositories/shipping-method/actions.ts +11 -28
  90. package/src/repositories/shipping-method/index.ts +26 -15
  91. package/src/repositories/shopping-list/actions.ts +21 -31
  92. package/src/repositories/shopping-list/index.ts +44 -22
  93. package/src/repositories/standalone-price.ts +6 -4
  94. package/src/repositories/state.ts +15 -9
  95. package/src/repositories/store.ts +21 -32
  96. package/src/repositories/subscription.test.ts +22 -22
  97. package/src/repositories/subscription.ts +8 -3
  98. package/src/repositories/tax-category/index.ts +8 -3
  99. package/src/repositories/type/actions.ts +21 -3
  100. package/src/repositories/type/index.ts +5 -3
  101. package/src/repositories/zone.test.ts +112 -77
  102. package/src/repositories/zone.ts +5 -3
  103. package/src/schemas/generated/associate-role.ts +13 -0
  104. package/src/schemas/generated/attribute-group.ts +12 -0
  105. package/src/schemas/generated/business-unit.ts +38 -0
  106. package/src/schemas/generated/cart-discount.ts +33 -0
  107. package/src/schemas/generated/cart.ts +61 -0
  108. package/src/schemas/generated/category.ts +25 -0
  109. package/src/schemas/generated/channel.ts +21 -0
  110. package/src/schemas/generated/common.ts +1372 -0
  111. package/src/schemas/generated/custom-object.ts +11 -0
  112. package/src/schemas/generated/customer-group.ts +11 -0
  113. package/src/schemas/generated/customer.ts +47 -0
  114. package/src/schemas/generated/discount-code.ts +25 -0
  115. package/src/schemas/generated/discount-group.ts +13 -0
  116. package/src/schemas/generated/extension.ts +15 -0
  117. package/src/schemas/generated/index.ts +42 -0
  118. package/src/schemas/generated/inventory-entry.ts +20 -0
  119. package/src/schemas/generated/my-quote-request.ts +10 -0
  120. package/src/schemas/generated/order-edit.ts +18 -0
  121. package/src/schemas/generated/order-from-cart.ts +25 -0
  122. package/src/schemas/generated/payment.ts +30 -0
  123. package/src/schemas/generated/product-discount.ts +20 -0
  124. package/src/schemas/generated/product-selection.ts +18 -0
  125. package/src/schemas/generated/product-tailoring.ts +26 -0
  126. package/src/schemas/generated/product-type.ts +12 -0
  127. package/src/schemas/generated/product.ts +37 -0
  128. package/src/schemas/generated/quote-request.ts +19 -0
  129. package/src/schemas/generated/quote.ts +18 -0
  130. package/src/schemas/generated/recurrence-policy.ts +15 -0
  131. package/src/schemas/generated/recurring-order.ts +19 -0
  132. package/src/schemas/generated/review.ts +24 -0
  133. package/src/schemas/generated/shipping-method.ts +24 -0
  134. package/src/schemas/generated/shopping-list.ts +28 -0
  135. package/src/schemas/generated/staged-quote.ts +18 -0
  136. package/src/schemas/generated/standalone-price.ts +32 -0
  137. package/src/schemas/generated/state.ts +20 -0
  138. package/src/schemas/generated/store.ts +23 -0
  139. package/src/schemas/generated/subscription.ts +20 -0
  140. package/src/schemas/generated/tax-category.ts +12 -0
  141. package/src/schemas/generated/type.ts +17 -0
  142. package/src/schemas/generated/zone.ts +12 -0
  143. package/src/schemas/update-request.ts +3 -5
  144. package/src/server.ts +32 -4
  145. package/src/services/abstract.ts +207 -101
  146. package/src/services/as-associate-cart.test.ts +28 -36
  147. package/src/services/as-associate-cart.ts +15 -12
  148. package/src/services/as-associate-order.test.ts +33 -40
  149. package/src/services/as-associate-order.ts +15 -12
  150. package/src/services/as-associate-quote-request.ts +15 -12
  151. package/src/services/as-associate-shopping-list.test.ts +25 -35
  152. package/src/services/as-associate-shopping-list.ts +15 -12
  153. package/src/services/as-associate.test.ts +21 -15
  154. package/src/services/as-associate.ts +23 -22
  155. package/src/services/associate-roles.test.ts +16 -22
  156. package/src/services/associate-roles.ts +2 -2
  157. package/src/services/attribute-group.test.ts +40 -44
  158. package/src/services/attribute-group.ts +2 -2
  159. package/src/services/business-units.test.ts +227 -163
  160. package/src/services/business-units.ts +2 -2
  161. package/src/services/cart-discount.test.ts +253 -187
  162. package/src/services/cart-discount.ts +2 -2
  163. package/src/services/cart.test.ts +833 -832
  164. package/src/services/cart.ts +31 -12
  165. package/src/services/category.test.ts +208 -130
  166. package/src/services/category.ts +2 -2
  167. package/src/services/channel.test.ts +39 -44
  168. package/src/services/channel.ts +2 -2
  169. package/src/services/custom-object.test.ts +103 -79
  170. package/src/services/custom-object.ts +106 -38
  171. package/src/services/customer-group.test.ts +39 -44
  172. package/src/services/customer-group.ts +2 -2
  173. package/src/services/customer.test.ts +357 -292
  174. package/src/services/customer.ts +70 -23
  175. package/src/services/discount-code.test.ts +57 -68
  176. package/src/services/discount-code.ts +2 -2
  177. package/src/services/discount-group.test.ts +111 -134
  178. package/src/services/discount-group.ts +2 -2
  179. package/src/services/draft-validation.test.ts +255 -0
  180. package/src/services/extension.test.ts +39 -44
  181. package/src/services/extension.ts +2 -2
  182. package/src/services/inventory-entry.test.ts +106 -87
  183. package/src/services/inventory-entry.ts +2 -2
  184. package/src/services/my-business-unit.test.ts +82 -112
  185. package/src/services/my-business-unit.ts +25 -19
  186. package/src/services/my-cart.test.ts +46 -41
  187. package/src/services/my-cart.ts +32 -28
  188. package/src/services/my-customer.test.ts +153 -88
  189. package/src/services/my-customer.ts +130 -61
  190. package/src/services/my-order.ts +15 -12
  191. package/src/services/my-payment.test.ts +30 -24
  192. package/src/services/my-payment.ts +2 -2
  193. package/src/services/my-shopping-list.ts +2 -2
  194. package/src/services/order.test.ts +332 -276
  195. package/src/services/order.ts +45 -27
  196. package/src/services/payment.test.ts +31 -29
  197. package/src/services/payment.ts +2 -2
  198. package/src/services/product-discount.test.ts +39 -46
  199. package/src/services/product-discount.ts +2 -2
  200. package/src/services/product-projection.test.ts +176 -166
  201. package/src/services/product-projection.ts +31 -15
  202. package/src/services/product-selection.test.ts +17 -9
  203. package/src/services/product-selection.ts +2 -2
  204. package/src/services/product-type.test.ts +80 -21
  205. package/src/services/product-type.ts +2 -2
  206. package/src/services/product.test.ts +569 -534
  207. package/src/services/product.ts +14 -7
  208. package/src/services/project.test.ts +22 -12
  209. package/src/services/project.ts +28 -13
  210. package/src/services/quote-request.test.ts +36 -39
  211. package/src/services/quote-request.ts +2 -2
  212. package/src/services/quote-staged.ts +2 -2
  213. package/src/services/quote.ts +2 -2
  214. package/src/services/recurrence-policy.test.ts +114 -139
  215. package/src/services/recurrence-policy.ts +2 -2
  216. package/src/services/recurring-order.test.ts +149 -194
  217. package/src/services/recurring-order.ts +2 -2
  218. package/src/services/reviews.test.ts +127 -106
  219. package/src/services/reviews.ts +2 -2
  220. package/src/services/shipping-method.test.ts +96 -125
  221. package/src/services/shipping-method.ts +24 -12
  222. package/src/services/shopping-list.test.ts +183 -141
  223. package/src/services/shopping-list.ts +2 -2
  224. package/src/services/standalone-price.test.ts +60 -46
  225. package/src/services/standalone-price.ts +2 -2
  226. package/src/services/state.test.ts +20 -25
  227. package/src/services/state.ts +2 -2
  228. package/src/services/store.test.ts +26 -45
  229. package/src/services/store.ts +2 -2
  230. package/src/services/subscription.test.ts +39 -44
  231. package/src/services/subscription.ts +2 -2
  232. package/src/services/tax-category.test.ts +33 -36
  233. package/src/services/tax-category.ts +2 -2
  234. package/src/services/type.test.ts +45 -44
  235. package/src/services/type.ts +2 -2
  236. package/src/services/zone.test.ts +40 -44
  237. package/src/services/zone.ts +2 -2
  238. package/src/shipping.ts +41 -11
  239. package/src/storage/abstract.ts +248 -17
  240. package/src/storage/in-memory.ts +147 -290
  241. package/src/storage/sqlite.ts +429 -0
  242. package/src/storage/storage-map.ts +75 -0
  243. package/src/storage/storage.test-helpers.ts +97 -0
  244. package/src/storage/storage.test.ts +802 -0
  245. package/src/testing/associate-role.ts +28 -0
  246. package/src/testing/attribute-group.ts +27 -0
  247. package/src/testing/business-unit.ts +9 -8
  248. package/src/testing/cart-discount.ts +34 -0
  249. package/src/testing/cart.ts +20 -0
  250. package/src/testing/category.ts +25 -0
  251. package/src/testing/channel.ts +23 -0
  252. package/src/testing/custom-object.ts +27 -0
  253. package/src/testing/customer-group.ts +26 -0
  254. package/src/testing/customer.ts +36 -33
  255. package/src/testing/discount-code.ts +29 -0
  256. package/src/testing/discount-group.ts +27 -0
  257. package/src/testing/extension.ts +32 -0
  258. package/src/testing/index.ts +33 -0
  259. package/src/testing/inventory-entry.ts +26 -0
  260. package/src/testing/order.ts +27 -0
  261. package/src/testing/payment.ts +23 -0
  262. package/src/testing/product-discount.ts +33 -0
  263. package/src/testing/product-selection.ts +28 -0
  264. package/src/testing/product-type.ts +27 -0
  265. package/src/testing/product.ts +38 -0
  266. package/src/testing/quote-request.ts +29 -0
  267. package/src/testing/recurrence-policy.ts +33 -0
  268. package/src/testing/recurring-order.ts +32 -0
  269. package/src/testing/review.ts +24 -0
  270. package/src/testing/shipping-method.ts +31 -0
  271. package/src/testing/shopping-list.ts +25 -0
  272. package/src/testing/standalone-price.ts +31 -0
  273. package/src/testing/state.ts +21 -0
  274. package/src/testing/store.ts +26 -0
  275. package/src/testing/subscription.ts +38 -0
  276. package/src/testing/tax-category.ts +27 -0
  277. package/src/testing/type.ts +9 -6
  278. package/src/testing/zone.ts +22 -0
  279. package/src/validate.test.ts +122 -0
  280. package/src/validate.ts +78 -7
  281. package/src/.env +0 -0
@@ -1,5 +1,13 @@
1
- import type { CustomerSignInResult } from "@commercetools/platform-sdk";
2
- import type { Request, Response, Router } from "express";
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: Router, repository: CustomerRepository) {
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: Router) {
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(request: Request, response: Response) {
27
- const draft = request.body;
28
- const resource = this.repository.create(
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
- draft,
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
- response.status(this.createStatusCode).send(result);
56
+ return reply.status(this.createStatusCode).send(result);
38
57
  }
39
58
 
40
- passwordResetToken(request: Request, response: Response) {
41
- const customer = this.repository.passwordResetToken(
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
- response.status(200).send(customer);
71
+ return reply.status(200).send(customer);
47
72
  }
48
73
 
49
- passwordReset(request: Request, response: Response) {
50
- const customer = this.repository.passwordReset(
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
- response.status(200).send(customer);
86
+ return reply.status(200).send(customer);
56
87
  }
57
88
 
58
- emailToken(request: Request, response: Response) {
59
- const id = request.body.id;
60
- const token = this.repository.emailToken(getRepositoryContext(request), id);
61
- response.status(200).send(token);
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(request: Request, response: Response) {
65
- const customer = this.repository.emailTokenConfirm(
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
- response.status(200).send(customer);
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
- test("Create discount code", async () => {
10
- // First create a cart discount to reference
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
- expect(cartDiscountResponse.status).toBe(201);
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: DiscountCodeDraft = {
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: cartDiscountResponse.body.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
- expect(response.status).toBe(201);
42
+ const response = await ctMock.app.inject({
43
+ method: "POST",
44
+ url: "/dummy/discount-codes",
45
+ payload: draft,
46
+ });
50
47
 
51
- expect(response.body).toEqual({
48
+ expect(response.statusCode).toBe(201);
49
+ expect(response.json()).toEqual({
52
50
  applicationVersion: 1,
53
51
  cartDiscounts: [
54
52
  {
55
- id: cartDiscountResponse.body.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
- // First create a cart discount to reference
75
- const cartDiscountResponse = await supertest(ctMock.app)
76
- .post("/dummy/cart-discounts")
77
- .send({
78
- key: "test-cart-discount-2",
79
- name: {
80
- en: "Test Cart Discount 2",
81
- },
82
- value: {
83
- type: "relative",
84
- permyriad: 500,
85
- },
86
- cartPredicate: "1 = 1",
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 draft: DiscountCodeDraft = {
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: cartDiscountResponse.body.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 supertest(ctMock.app).get(
114
- `/dummy/discount-codes/${createResponse.body.id}`,
115
- );
101
+ const response = await ctMock.app.inject({
102
+ method: "GET",
103
+ url: `/dummy/discount-codes/${discountCode.id}`,
104
+ });
116
105
 
117
- expect(response.status).toBe(200);
118
- expect(response.body).toEqual(createResponse.body);
106
+ expect(response.statusCode).toBe(200);
107
+ expect(response.json()).toEqual(discountCode);
119
108
  });
120
109
  });
@@ -1,11 +1,11 @@
1
- import type { Router } from "express";
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: Router, repository: DiscountCodeRepository) {
8
+ constructor(parent: FastifyInstance, repository: DiscountCodeRepository) {
9
9
  super(parent);
10
10
  this.repository = repository;
11
11
  }