@labdigital/commercetools-mock 2.65.1 → 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 +3771 -2654
  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 +89 -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,4 @@
1
1
  import type { BusinessUnit } from "@commercetools/platform-sdk";
2
- import supertest from "supertest";
3
2
  import { afterEach, beforeEach, describe, expect, test } from "vitest";
4
3
  import { businessUnitDraftFactory } from "#src/testing/business-unit.ts";
5
4
  import { customerDraftFactory } from "#src/testing/customer.ts";
@@ -15,25 +14,30 @@ describe("Business units query", () => {
15
14
  });
16
15
 
17
16
  beforeEach(async () => {
18
- const draft = businessUnitDraftFactory(ctMock).build();
17
+ const draft = businessUnitDraftFactory(ctMock).build({
18
+ key: "test-business-unit",
19
+ });
19
20
 
20
- const response = await supertest(ctMock.app)
21
- .post("/dummy/business-units")
22
- .send(draft);
23
- expect(response.status).toBe(201);
24
- businessUnit = response.body as BusinessUnit;
21
+ const response = await ctMock.app.inject({
22
+ method: "POST",
23
+ url: "/dummy/business-units",
24
+ payload: draft,
25
+ });
26
+ expect(response.statusCode).toBe(201);
27
+ businessUnit = response.json() as BusinessUnit;
25
28
  });
26
29
 
27
30
  test("no filter", async () => {
28
- const response = await supertest(ctMock.app)
29
- .get("/dummy/business-units")
30
- .query("{}")
31
- .send();
32
-
33
- expect(response.status).toBe(200);
34
- expect(response.body.count).toBe(1);
35
- businessUnit = response.body.results[0] as BusinessUnit;
36
- expect(businessUnit.key).toBe("test-business-unit");
31
+ const response = await ctMock.app.inject({
32
+ method: "GET",
33
+ url: "/dummy/business-units?{}",
34
+ });
35
+
36
+ expect(response.statusCode).toBe(200);
37
+ const body = response.json();
38
+ expect(body.count).toBe(1);
39
+ businessUnit = body.results[0] as BusinessUnit;
40
+ expect(businessUnit!.key).toBe("test-business-unit");
37
41
  });
38
42
  });
39
43
 
@@ -47,9 +51,10 @@ describe("Business Unit Update Actions", () => {
47
51
  test("addAddress", async () => {
48
52
  const businessUnit = await businessUnitDraftFactory(ctMock).create();
49
53
 
50
- const response = await supertest(ctMock.app)
51
- .post(`/dummy/business-units/${businessUnit.id}`)
52
- .send({
54
+ const response = await ctMock.app.inject({
55
+ method: "POST",
56
+ url: `/dummy/business-units/${businessUnit.id}`,
57
+ payload: {
53
58
  version: 1,
54
59
  actions: [
55
60
  {
@@ -64,18 +69,21 @@ describe("Business Unit Update Actions", () => {
64
69
  },
65
70
  },
66
71
  ],
67
- });
68
- expect(response.status).toBe(200);
69
- expect(response.body.version).toBe(2);
70
- expect(response.body.addresses).toHaveLength(2);
72
+ },
73
+ });
74
+ expect(response.statusCode).toBe(200);
75
+ const body = response.json();
76
+ expect(body.version).toBe(2);
77
+ expect(body.addresses).toHaveLength(2);
71
78
  });
72
79
 
73
80
  test("removeAddress by ID", async () => {
74
81
  const businessUnit = await businessUnitDraftFactory(ctMock).create();
75
82
 
76
- const response = await supertest(ctMock.app)
77
- .post(`/dummy/business-units/${businessUnit.id}`)
78
- .send({
83
+ const response = await ctMock.app.inject({
84
+ method: "POST",
85
+ url: `/dummy/business-units/${businessUnit.id}`,
86
+ payload: {
79
87
  version: 1,
80
88
  actions: [
81
89
  {
@@ -83,10 +91,12 @@ describe("Business Unit Update Actions", () => {
83
91
  addressId: businessUnit.addresses[0].id,
84
92
  },
85
93
  ],
86
- });
87
- expect(response.status, JSON.stringify(response.body)).toBe(200);
88
- expect(response.body.version).toBe(2);
89
- expect(response.body.addresses).toHaveLength(0);
94
+ },
95
+ });
96
+ const body = response.json();
97
+ expect(response.statusCode, JSON.stringify(body)).toBe(200);
98
+ expect(body.version).toBe(2);
99
+ expect(body.addresses).toHaveLength(0);
90
100
  });
91
101
 
92
102
  test("changeAddress by ID", async () => {
@@ -94,9 +104,10 @@ describe("Business Unit Update Actions", () => {
94
104
 
95
105
  const addressId = businessUnit.addresses[0].id;
96
106
 
97
- const response = await supertest(ctMock.app)
98
- .post(`/dummy/business-units/${businessUnit.id}`)
99
- .send({
107
+ const response = await ctMock.app.inject({
108
+ method: "POST",
109
+ url: `/dummy/business-units/${businessUnit.id}`,
110
+ payload: {
100
111
  version: 1,
101
112
  actions: [
102
113
  {
@@ -112,9 +123,11 @@ describe("Business Unit Update Actions", () => {
112
123
  },
113
124
  },
114
125
  ],
115
- });
116
- expect(response.status, JSON.stringify(response.body)).toBe(200);
117
- const result = response.body as BusinessUnit;
126
+ },
127
+ });
128
+ const body = response.json();
129
+ expect(response.statusCode, JSON.stringify(body)).toBe(200);
130
+ const result = body as BusinessUnit;
118
131
  expect(result.version).toBe(2);
119
132
  expect(result.addresses).toHaveLength(1);
120
133
  expect(result.addresses).toStrictEqual([
@@ -133,9 +146,10 @@ describe("Business Unit Update Actions", () => {
133
146
  test("addShippingAddressId", async () => {
134
147
  const businessUnit = await businessUnitDraftFactory(ctMock).create();
135
148
 
136
- const response = await supertest(ctMock.app)
137
- .post(`/dummy/business-units/${businessUnit.id}`)
138
- .send({
149
+ const response = await ctMock.app.inject({
150
+ method: "POST",
151
+ url: `/dummy/business-units/${businessUnit.id}`,
152
+ payload: {
139
153
  version: 1,
140
154
  actions: [
141
155
  {
@@ -143,19 +157,22 @@ describe("Business Unit Update Actions", () => {
143
157
  addressId: businessUnit.addresses[0].id,
144
158
  },
145
159
  ],
146
- });
147
- expect(response.status).toBe(200);
148
- expect(response.body.version).toBe(2);
149
- expect(response.body.shippingAddressIds).toHaveLength(1);
160
+ },
161
+ });
162
+ expect(response.statusCode).toBe(200);
163
+ const body = response.json();
164
+ expect(body.version).toBe(2);
165
+ expect(body.shippingAddressIds).toHaveLength(1);
150
166
  });
151
167
 
152
168
  test("removeShippingAddressId", async () => {
153
169
  const businessUnit = await businessUnitDraftFactory(ctMock).create();
154
170
 
155
171
  const addressId = businessUnit.addresses[0].id;
156
- await supertest(ctMock.app)
157
- .post(`/dummy/business-units/${businessUnit.id}`)
158
- .send({
172
+ await ctMock.app.inject({
173
+ method: "POST",
174
+ url: `/dummy/business-units/${businessUnit.id}`,
175
+ payload: {
159
176
  version: 1,
160
177
  actions: [
161
178
  {
@@ -163,11 +180,13 @@ describe("Business Unit Update Actions", () => {
163
180
  addressId: addressId,
164
181
  },
165
182
  ],
166
- });
183
+ },
184
+ });
167
185
 
168
- const response = await supertest(ctMock.app)
169
- .post(`/dummy/business-units/${businessUnit.id}`)
170
- .send({
186
+ const response = await ctMock.app.inject({
187
+ method: "POST",
188
+ url: `/dummy/business-units/${businessUnit.id}`,
189
+ payload: {
171
190
  version: 2,
172
191
  actions: [
173
192
  {
@@ -175,9 +194,10 @@ describe("Business Unit Update Actions", () => {
175
194
  addressId: addressId,
176
195
  },
177
196
  ],
178
- });
179
- expect(response.status).toBe(200);
180
- const result = response.body as BusinessUnit;
197
+ },
198
+ });
199
+ expect(response.statusCode).toBe(200);
200
+ const result = response.json() as BusinessUnit;
181
201
  expect(result.version).toBe(3);
182
202
  expect(result.shippingAddressIds).toHaveLength(0);
183
203
  });
@@ -187,9 +207,10 @@ describe("Business Unit Update Actions", () => {
187
207
 
188
208
  const addressId = businessUnit.addresses[0].id;
189
209
 
190
- const response = await supertest(ctMock.app)
191
- .post(`/dummy/business-units/${businessUnit.id}`)
192
- .send({
210
+ const response = await ctMock.app.inject({
211
+ method: "POST",
212
+ url: `/dummy/business-units/${businessUnit.id}`,
213
+ payload: {
193
214
  version: businessUnit.version,
194
215
  actions: [
195
216
  {
@@ -197,18 +218,21 @@ describe("Business Unit Update Actions", () => {
197
218
  addressId: addressId,
198
219
  },
199
220
  ],
200
- });
201
- expect(response.status, JSON.stringify(response.body)).toBe(200);
202
- expect(response.body.version).toBe(2);
203
- expect(response.body.defaultShippingAddressId).toBe(addressId);
221
+ },
222
+ });
223
+ const body = response.json();
224
+ expect(response.statusCode, JSON.stringify(body)).toBe(200);
225
+ expect(body.version).toBe(2);
226
+ expect(body.defaultShippingAddressId).toBe(addressId);
204
227
  });
205
228
 
206
229
  test("addBillingAddressId", async () => {
207
230
  const businessUnit = await businessUnitDraftFactory(ctMock).create();
208
231
 
209
- const response = await supertest(ctMock.app)
210
- .post(`/dummy/business-units/${businessUnit.id}`)
211
- .send({
232
+ const response = await ctMock.app.inject({
233
+ method: "POST",
234
+ url: `/dummy/business-units/${businessUnit.id}`,
235
+ payload: {
212
236
  version: 1,
213
237
  actions: [
214
238
  {
@@ -216,20 +240,23 @@ describe("Business Unit Update Actions", () => {
216
240
  addressId: businessUnit.addresses[0].id,
217
241
  },
218
242
  ],
219
- });
243
+ },
244
+ });
220
245
 
221
- expect(response.status).toBe(200);
222
- expect(response.body.version).toBe(2);
223
- expect(response.body.billingAddressIds).toHaveLength(1);
246
+ expect(response.statusCode).toBe(200);
247
+ const body = response.json();
248
+ expect(body.version).toBe(2);
249
+ expect(body.billingAddressIds).toHaveLength(1);
224
250
  });
225
251
 
226
252
  test("removeBillingAddressId", async () => {
227
253
  const businessUnit = await businessUnitDraftFactory(ctMock).create();
228
254
 
229
255
  const addressId = businessUnit.addresses[0].id;
230
- await supertest(ctMock.app)
231
- .post(`/dummy/business-units/${businessUnit.id}`)
232
- .send({
256
+ await ctMock.app.inject({
257
+ method: "POST",
258
+ url: `/dummy/business-units/${businessUnit.id}`,
259
+ payload: {
233
260
  version: 1,
234
261
  actions: [
235
262
  {
@@ -237,11 +264,13 @@ describe("Business Unit Update Actions", () => {
237
264
  addressId: addressId,
238
265
  },
239
266
  ],
240
- });
267
+ },
268
+ });
241
269
 
242
- const response = await supertest(ctMock.app)
243
- .post(`/dummy/business-units/${businessUnit.id}`)
244
- .send({
270
+ const response = await ctMock.app.inject({
271
+ method: "POST",
272
+ url: `/dummy/business-units/${businessUnit.id}`,
273
+ payload: {
245
274
  version: 2,
246
275
  actions: [
247
276
  {
@@ -249,9 +278,10 @@ describe("Business Unit Update Actions", () => {
249
278
  addressId: addressId,
250
279
  },
251
280
  ],
252
- });
253
- expect(response.status).toBe(200);
254
- const result = response.body as BusinessUnit;
281
+ },
282
+ });
283
+ expect(response.statusCode).toBe(200);
284
+ const result = response.json() as BusinessUnit;
255
285
  expect(result.version).toBe(3);
256
286
  expect(result.billingAddressIds).toHaveLength(0);
257
287
  });
@@ -260,9 +290,10 @@ describe("Business Unit Update Actions", () => {
260
290
  const businessUnit = await businessUnitDraftFactory(ctMock).create();
261
291
  const addressId = businessUnit.addresses[0].id;
262
292
 
263
- const response = await supertest(ctMock.app)
264
- .post(`/dummy/business-units/${businessUnit.id}`)
265
- .send({
293
+ const response = await ctMock.app.inject({
294
+ method: "POST",
295
+ url: `/dummy/business-units/${businessUnit.id}`,
296
+ payload: {
266
297
  version: businessUnit.version,
267
298
  actions: [
268
299
  {
@@ -270,54 +301,65 @@ describe("Business Unit Update Actions", () => {
270
301
  addressId: addressId,
271
302
  },
272
303
  ],
273
- });
274
- expect(response.status, JSON.stringify(response.body)).toBe(200);
275
- expect(response.body.version).toBe(2);
276
- expect(response.body.defaultBillingAddressId).toBe(addressId);
304
+ },
305
+ });
306
+ const body = response.json();
307
+ expect(response.statusCode, JSON.stringify(body)).toBe(200);
308
+ expect(body.version).toBe(2);
309
+ expect(body.defaultBillingAddressId).toBe(addressId);
277
310
  });
278
311
 
279
312
  test("changeName", async () => {
280
313
  const businessUnit = await businessUnitDraftFactory(ctMock).create();
281
314
 
282
- const response = await supertest(ctMock.app)
283
- .post(`/dummy/business-units/${businessUnit.id}`)
284
- .send({
315
+ const response = await ctMock.app.inject({
316
+ method: "POST",
317
+ url: `/dummy/business-units/${businessUnit.id}`,
318
+ payload: {
285
319
  version: 1,
286
320
  actions: [{ action: "changeName", name: "Updated Business Unit Name" }],
287
- });
288
- expect(response.status).toBe(200);
289
- expect(response.body.version).toBe(2);
290
- expect(response.body.name).toBe("Updated Business Unit Name");
321
+ },
322
+ });
323
+ expect(response.statusCode).toBe(200);
324
+ const body = response.json();
325
+ expect(body.version).toBe(2);
326
+ expect(body.name).toBe("Updated Business Unit Name");
291
327
  });
292
328
 
293
329
  test("setContactEmail", async () => {
294
330
  const businessUnit = await businessUnitDraftFactory(ctMock).create();
295
331
 
296
- const response = await supertest(ctMock.app)
297
- .post(`/dummy/business-units/${businessUnit.id}`)
298
- .send({
332
+ const response = await ctMock.app.inject({
333
+ method: "POST",
334
+ url: `/dummy/business-units/${businessUnit.id}`,
335
+ payload: {
299
336
  version: 1,
300
337
  actions: [
301
338
  { action: "setContactEmail", contactEmail: "newemail@business.com" },
302
339
  ],
303
- });
304
- expect(response.status).toBe(200);
305
- expect(response.body.version).toBe(2);
306
- expect(response.body.contactEmail).toBe("newemail@business.com");
340
+ },
341
+ });
342
+ expect(response.statusCode).toBe(200);
343
+ const body = response.json();
344
+ expect(body.version).toBe(2);
345
+ expect(body.contactEmail).toBe("newemail@business.com");
307
346
  });
308
347
 
309
348
  test("changeStatus", async () => {
310
349
  const businessUnit = await businessUnitDraftFactory(ctMock).create();
311
350
 
312
- const response = await supertest(ctMock.app)
313
- .post(`/dummy/business-units/${businessUnit.id}`)
314
- .send({
351
+ const response = await ctMock.app.inject({
352
+ method: "POST",
353
+ url: `/dummy/business-units/${businessUnit.id}`,
354
+ payload: {
315
355
  version: 1,
316
356
  actions: [{ action: "changeStatus", status: "Inactive" }],
317
- });
318
- expect(response.status).toBe(200);
319
- expect(response.body.version).toBe(2);
320
- expect(response.body.status).toBe("Inactive");
357
+ },
358
+ });
359
+ expect(response.statusCode).toBe(200);
360
+ const body = response.json();
361
+ expect(body.version).toBe(2);
362
+ expect(body.status).toBe("Inactive");
321
363
  });
322
364
 
323
365
  test("changeParentUnit", async () => {
@@ -331,9 +373,10 @@ describe("Business Unit Update Actions", () => {
331
373
  name: "Division Unit",
332
374
  });
333
375
 
334
- const response = await supertest(ctMock.app)
335
- .post(`/dummy/business-units/${divisionBusinessUnit.id}`)
336
- .send({
376
+ const response = await ctMock.app.inject({
377
+ method: "POST",
378
+ url: `/dummy/business-units/${divisionBusinessUnit.id}`,
379
+ payload: {
337
380
  version: 1,
338
381
  actions: [
339
382
  {
@@ -344,19 +387,22 @@ describe("Business Unit Update Actions", () => {
344
387
  },
345
388
  },
346
389
  ],
347
- });
348
- expect(response.status).toBe(200);
349
- expect(response.body.version).toBe(2);
350
- expect(response.body.parentUnit?.key).toBe(parentBusinessUnit.key);
390
+ },
391
+ });
392
+ expect(response.statusCode).toBe(200);
393
+ const body = response.json();
394
+ expect(body.version).toBe(2);
395
+ expect(body.parentUnit?.key).toBe(parentBusinessUnit.key);
351
396
  });
352
397
 
353
398
  test("addAssociate", async () => {
354
399
  const businessUnit = await businessUnitDraftFactory(ctMock).create();
355
400
  const customer = await customerDraftFactory(ctMock).create();
356
401
 
357
- const response = await supertest(ctMock.app)
358
- .post(`/dummy/business-units/${businessUnit.id}`)
359
- .send({
402
+ const response = await ctMock.app.inject({
403
+ method: "POST",
404
+ url: `/dummy/business-units/${businessUnit.id}`,
405
+ payload: {
360
406
  version: 1,
361
407
  actions: [
362
408
  {
@@ -370,10 +416,12 @@ describe("Business Unit Update Actions", () => {
370
416
  },
371
417
  },
372
418
  ],
373
- });
374
- expect(response.status).toBe(200);
375
- expect(response.body.version).toBe(2);
376
- expect(response.body.associates).toHaveLength(1);
419
+ },
420
+ });
421
+ expect(response.statusCode).toBe(200);
422
+ const body = response.json();
423
+ expect(body.version).toBe(2);
424
+ expect(body.associates).toHaveLength(1);
377
425
  });
378
426
 
379
427
  test("removeAssociate", async () => {
@@ -390,9 +438,10 @@ describe("Business Unit Update Actions", () => {
390
438
  ],
391
439
  });
392
440
 
393
- const response = await supertest(ctMock.app)
394
- .post(`/dummy/business-units/${businessUnit.id}`)
395
- .send({
441
+ const response = await ctMock.app.inject({
442
+ method: "POST",
443
+ url: `/dummy/business-units/${businessUnit.id}`,
444
+ payload: {
396
445
  version: 1,
397
446
  actions: [
398
447
  {
@@ -403,10 +452,12 @@ describe("Business Unit Update Actions", () => {
403
452
  },
404
453
  },
405
454
  ],
406
- });
407
- expect(response.status).toBe(200);
408
- expect(response.body.version).toBe(2);
409
- expect(response.body.associates).toHaveLength(0);
455
+ },
456
+ });
457
+ expect(response.statusCode).toBe(200);
458
+ const body = response.json();
459
+ expect(body.version).toBe(2);
460
+ expect(body.associates).toHaveLength(0);
410
461
  });
411
462
 
412
463
  test("changeAssociate", async () => {
@@ -423,9 +474,10 @@ describe("Business Unit Update Actions", () => {
423
474
  ],
424
475
  });
425
476
 
426
- const response = await supertest(ctMock.app)
427
- .post(`/dummy/business-units/${businessUnit.id}`)
428
- .send({
477
+ const response = await ctMock.app.inject({
478
+ method: "POST",
479
+ url: `/dummy/business-units/${businessUnit.id}`,
480
+ payload: {
429
481
  version: 1,
430
482
  actions: [
431
483
  {
@@ -451,12 +503,12 @@ describe("Business Unit Update Actions", () => {
451
503
  },
452
504
  },
453
505
  ],
454
- });
455
- expect(response.status).toBe(200);
456
- expect(response.body.version).toBe(2);
457
- expect(response.body.associates[0].associateRoleAssignments).toHaveLength(
458
- 1,
459
- );
506
+ },
507
+ });
508
+ expect(response.statusCode).toBe(200);
509
+ const body = response.json();
510
+ expect(body.version).toBe(2);
511
+ expect(body.associates[0].associateRoleAssignments).toHaveLength(1);
460
512
  });
461
513
 
462
514
  test("setCustomType", async () => {
@@ -474,9 +526,10 @@ describe("Business Unit Update Actions", () => {
474
526
 
475
527
  const businessUnit = await businessUnitDraftFactory(ctMock).create();
476
528
 
477
- const response = await supertest(ctMock.app)
478
- .post(`/dummy/business-units/${businessUnit.id}`)
479
- .send({
529
+ const response = await ctMock.app.inject({
530
+ method: "POST",
531
+ url: `/dummy/business-units/${businessUnit.id}`,
532
+ payload: {
480
533
  version: 1,
481
534
  actions: [
482
535
  {
@@ -487,10 +540,12 @@ describe("Business Unit Update Actions", () => {
487
540
  },
488
541
  },
489
542
  ],
490
- });
491
- expect(response.status).toBe(200);
492
- expect(response.body.version).toBe(2);
493
- expect(response.body.custom.type.id).toBe(type.id);
543
+ },
544
+ });
545
+ expect(response.statusCode).toBe(200);
546
+ const body = response.json();
547
+ expect(body.version).toBe(2);
548
+ expect(body.custom.type.id).toBe(type.id);
494
549
  });
495
550
 
496
551
  test("setCustomField", async () => {
@@ -518,9 +573,10 @@ describe("Business Unit Update Actions", () => {
518
573
  },
519
574
  });
520
575
 
521
- const response = await supertest(ctMock.app)
522
- .post(`/dummy/business-units/${businessUnit.id}`)
523
- .send({
576
+ const response = await ctMock.app.inject({
577
+ method: "POST",
578
+ url: `/dummy/business-units/${businessUnit.id}`,
579
+ payload: {
524
580
  version: 1,
525
581
  actions: [
526
582
  {
@@ -529,10 +585,12 @@ describe("Business Unit Update Actions", () => {
529
585
  value: "bar",
530
586
  },
531
587
  ],
532
- });
533
- expect(response.status).toBe(200);
534
- expect(response.body.version).toBe(2);
535
- expect(response.body.custom.fields.customField).toBe("bar");
588
+ },
589
+ });
590
+ expect(response.statusCode).toBe(200);
591
+ const body = response.json();
592
+ expect(body.version).toBe(2);
593
+ expect(body.custom.fields.customField).toBe("bar");
536
594
  });
537
595
 
538
596
  test("setAddressCustomType", async () => {
@@ -549,9 +607,10 @@ describe("Business Unit Update Actions", () => {
549
607
  });
550
608
  const businessUnit = await businessUnitDraftFactory(ctMock).create();
551
609
 
552
- const response = await supertest(ctMock.app)
553
- .post(`/dummy/business-units/${businessUnit.id}`)
554
- .send({
610
+ const response = await ctMock.app.inject({
611
+ method: "POST",
612
+ url: `/dummy/business-units/${businessUnit.id}`,
613
+ payload: {
555
614
  version: 1,
556
615
  actions: [
557
616
  {
@@ -563,10 +622,12 @@ describe("Business Unit Update Actions", () => {
563
622
  },
564
623
  },
565
624
  ],
566
- });
567
- expect(response.status).toBe(200);
568
- expect(response.body.version).toBe(2);
569
- expect(response.body.addresses[0].custom.type.id).toBe(type.id);
625
+ },
626
+ });
627
+ expect(response.statusCode).toBe(200);
628
+ const body = response.json();
629
+ expect(body.version).toBe(2);
630
+ expect(body.addresses[0].custom.type.id).toBe(type.id);
570
631
  });
571
632
 
572
633
  test("setAddressCustomField", async () => {
@@ -583,9 +644,10 @@ describe("Business Unit Update Actions", () => {
583
644
  });
584
645
  const businessUnit = await businessUnitDraftFactory(ctMock).create();
585
646
 
586
- const response = await supertest(ctMock.app)
587
- .post(`/dummy/business-units/${businessUnit.id}`)
588
- .send({
647
+ const response = await ctMock.app.inject({
648
+ method: "POST",
649
+ url: `/dummy/business-units/${businessUnit.id}`,
650
+ payload: {
589
651
  version: 1,
590
652
  actions: [
591
653
  {
@@ -603,10 +665,12 @@ describe("Business Unit Update Actions", () => {
603
665
  value: "address custom value",
604
666
  },
605
667
  ],
606
- });
607
- expect(response.status).toBe(200);
608
- expect(response.body.version).toBe(3);
609
- expect(response.body.addresses[0].custom.fields.addressCustomField).toBe(
668
+ },
669
+ });
670
+ expect(response.statusCode).toBe(200);
671
+ const body = response.json();
672
+ expect(body.version).toBe(3);
673
+ expect(body.addresses[0].custom.fields.addressCustomField).toBe(
610
674
  "address custom value",
611
675
  );
612
676
  });
@@ -1,11 +1,11 @@
1
- import type { Router } from "express";
1
+ import type { FastifyInstance } from "fastify";
2
2
  import type { BusinessUnitRepository } from "../repositories/business-unit.ts";
3
3
  import AbstractService from "./abstract.ts";
4
4
 
5
5
  export class BusinessUnitServices extends AbstractService {
6
6
  public repository: BusinessUnitRepository;
7
7
 
8
- constructor(parent: Router, repository: BusinessUnitRepository) {
8
+ constructor(parent: FastifyInstance, repository: BusinessUnitRepository) {
9
9
  super(parent);
10
10
 
11
11
  this.repository = repository;