@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
@@ -4,81 +4,79 @@ import type {
4
4
  Cart,
5
5
  CentPrecisionMoney,
6
6
  HighPrecisionMoneyDraft,
7
- ProductDraft,
8
7
  ShippingMethod,
9
- ShippingMethodDraft,
10
8
  ShippingMethodResourceIdentifier,
11
9
  TaxCategory,
12
- TaxCategoryDraft,
13
- Zone,
14
10
  } from "@commercetools/platform-sdk";
15
- import supertest from "supertest";
16
11
  import { afterEach, beforeEach, describe, expect, test } from "vitest";
17
12
  import { calculateMoneyTotalCentAmount } from "#src/repositories/helpers.ts";
18
- import { customerDraftFactory } from "#src/testing/customer.ts";
13
+ import {
14
+ cartDraftFactory,
15
+ customerDraftFactory,
16
+ productDraftFactory,
17
+ productTypeDraftFactory,
18
+ shippingMethodDraftFactory,
19
+ taxCategoryDraftFactory,
20
+ typeDraftFactory,
21
+ zoneDraftFactory,
22
+ } from "#src/testing/index.ts";
19
23
  import { CommercetoolsMock } from "../index.ts";
20
24
 
21
25
  describe("Carts Query", () => {
22
26
  const ctMock = new CommercetoolsMock();
23
27
 
24
28
  beforeEach(async () => {
25
- let response;
26
- response = await supertest(ctMock.app)
27
- .post("/dummy/types")
28
- .send({
29
- key: "my-cart",
30
- name: {
31
- en: "Test",
32
- },
33
- description: {
34
- en: "Test Type",
35
- },
36
- resourceTypeIds: ["order"],
37
- fieldDefinitions: [
38
- {
39
- name: "offer_name",
40
- label: {
41
- en: "offer_name",
42
- },
43
- required: false,
44
- type: {
45
- name: "String",
46
- },
47
- inputHint: "SingleLine",
48
- },
49
- ],
50
- });
51
- expect(response.status).toBe(201);
29
+ const typeFactory = typeDraftFactory(ctMock);
30
+ const cartFactory = cartDraftFactory(ctMock);
52
31
 
53
- response = await supertest(ctMock.app)
54
- .post("/dummy/carts")
55
- .send({
56
- currency: "EUR",
57
- custom: {
58
- type: {
59
- typeId: "type",
60
- key: "my-cart",
32
+ await typeFactory.create({
33
+ key: "my-cart",
34
+ name: {
35
+ en: "Test",
36
+ },
37
+ description: {
38
+ en: "Test Type",
39
+ },
40
+ resourceTypeIds: ["order"],
41
+ fieldDefinitions: [
42
+ {
43
+ name: "offer_name",
44
+ label: {
45
+ en: "offer_name",
61
46
  },
62
- fields: {
63
- description: "example description",
47
+ required: false,
48
+ type: {
49
+ name: "String",
64
50
  },
51
+ inputHint: "SingleLine",
65
52
  },
66
- });
67
- expect(response.status).toBe(201);
53
+ ],
54
+ });
55
+
56
+ await cartFactory.create({
57
+ currency: "EUR",
58
+ custom: {
59
+ type: {
60
+ typeId: "type",
61
+ key: "my-cart",
62
+ },
63
+ fields: {
64
+ description: "example description",
65
+ },
66
+ },
67
+ });
68
68
  });
69
69
 
70
70
  test("no filter", async () => {
71
- const response = await supertest(ctMock.app)
72
- .get("/dummy/carts")
73
- .query({
74
- expand: "custom.type",
75
- })
76
- .send();
71
+ const response = await ctMock.app.inject({
72
+ method: "GET",
73
+ url: "/dummy/carts?expand=custom.type",
74
+ });
77
75
 
78
- expect(response.status).toBe(200);
79
- expect(response.body.count).toBe(1);
76
+ expect(response.statusCode).toBe(200);
77
+ expect(response.json().count).toBe(1);
80
78
 
81
- const myCart = response.body.results[0] as Cart;
79
+ const myCart = response.json().results[0] as Cart;
82
80
 
83
81
  expect(myCart.custom?.type.id).not.toBeUndefined();
84
82
  expect(myCart.custom?.type.id).toBe(myCart.custom?.type.obj?.id);
@@ -88,25 +86,33 @@ describe("Carts Query", () => {
88
86
  test("throw error when anonymousId and customerId are given", async () => {
89
87
  const customerId = "400be09e-bfe8-4925-a307-4ef6280b063e";
90
88
  const anonymousId = "a99f27d1-7e7e-4592-8d5a-aa5da1adfe24";
91
- const response = await supertest(ctMock.app).post("/dummy/carts").send({
92
- currency: "EUR",
93
- anonymousId,
94
- customerId,
89
+ const response = await ctMock.app.inject({
90
+ method: "POST",
91
+ url: "/dummy/carts",
92
+ payload: {
93
+ currency: "EUR",
94
+ anonymousId,
95
+ customerId,
96
+ },
95
97
  });
96
- expect(response.status).toBe(400);
97
- expect(response.body.message).toBe(
98
+ expect(response.statusCode).toBe(400);
99
+ expect(response.json().message).toBe(
98
100
  "Can set only one of customer OR anonymousId",
99
101
  );
100
102
  });
101
103
 
102
104
  test("create cart with existing customer", async () => {
103
105
  const customer = await customerDraftFactory(ctMock).create();
104
- const response = await supertest(ctMock.app).post("/dummy/carts").send({
105
- currency: "EUR",
106
- customerId: customer.id,
106
+ const response = await ctMock.app.inject({
107
+ method: "POST",
108
+ url: "/dummy/carts",
109
+ payload: {
110
+ currency: "EUR",
111
+ customerId: customer.id,
112
+ },
107
113
  });
108
- expect(response.status).toBe(201);
109
- expect(response.body.customerId).toBe(customer.id);
114
+ expect(response.statusCode).toBe(201);
115
+ expect(response.json().customerId).toBe(customer.id);
110
116
  });
111
117
  });
112
118
 
@@ -114,90 +120,33 @@ describe("Cart Update Actions", () => {
114
120
  const ctMock = new CommercetoolsMock();
115
121
  let cart: Cart | undefined;
116
122
  let taxCategory: TaxCategory;
123
+ let productDraft: Parameters<
124
+ ReturnType<typeof productDraftFactory>["create"]
125
+ >[0];
117
126
 
118
- const createCart = async (currency: string) => {
119
- const response = await supertest(ctMock.app).post("/dummy/carts").send({
120
- currency,
121
- country: "NL",
122
- });
123
- expect(response.status).toBe(201);
124
- cart = response.body;
125
- };
127
+ const cartFactory = cartDraftFactory(ctMock);
128
+ const taxCategoryFactory = taxCategoryDraftFactory(ctMock);
129
+ const productFactory = productDraftFactory(ctMock);
130
+ const typeFactory = typeDraftFactory(ctMock);
131
+ const zoneFactory = zoneDraftFactory(ctMock);
132
+ const shippingMethodFactory = shippingMethodDraftFactory(ctMock);
126
133
 
127
- const createZone = async (country: string): Promise<Zone> => {
128
- const response = await supertest(ctMock.app)
129
- .post("/dummy/zones")
130
- .send({
131
- name: country,
132
- locations: [
133
- {
134
- country,
135
- },
136
- ],
137
- });
138
- expect(response.status).toBe(201);
139
- return response.body;
140
- };
141
-
142
- const createTaxCategory = async (
143
- draft: TaxCategoryDraft,
144
- ): Promise<TaxCategory> => {
145
- const response = await supertest(ctMock.app)
146
- .post("/dummy/tax-categories")
147
- .send(draft);
148
- expect(response.status).toBe(201);
149
- return response.body;
150
- };
151
-
152
- const createShippingMethod = async (
153
- draft: ShippingMethodDraft,
154
- ): Promise<ShippingMethod> => {
155
- const response = await supertest(ctMock.app)
156
- .post("/dummy/shipping-methods")
157
- .send(draft);
158
- expect(response.status).toBe(201);
159
- return response.body;
160
- };
161
-
162
- const productDraft: ProductDraft = {
163
- name: {
164
- "nl-NL": "test product",
165
- },
166
- productType: {
167
- typeId: "product-type",
168
- id: "some-uuid",
169
- },
170
- masterVariant: {
171
- sku: "1337",
172
- prices: [
173
- {
174
- value: {
175
- type: "centPrecision",
176
- currencyCode: "EUR",
177
- centAmount: 14900,
178
- fractionDigits: 2,
179
- } as CentPrecisionMoney,
180
- },
181
- {
182
- value: {
183
- type: "centPrecision",
184
- currencyCode: "GBP",
185
- centAmount: 18900,
186
- fractionDigits: 2,
187
- } as CentPrecisionMoney,
188
- },
189
- ],
134
+ beforeEach(async () => {
135
+ const productType = await productTypeDraftFactory(ctMock).create({
136
+ name: "Test Product Type",
137
+ description: "Product type for cart tests",
138
+ });
190
139
 
191
- attributes: [
192
- {
193
- name: "test",
194
- value: "test",
195
- },
196
- ],
197
- },
198
- variants: [
199
- {
200
- sku: "1338",
140
+ productDraft = {
141
+ name: {
142
+ "nl-NL": "test product",
143
+ },
144
+ productType: {
145
+ typeId: "product-type" as const,
146
+ id: productType.id,
147
+ },
148
+ masterVariant: {
149
+ sku: "1337",
201
150
  prices: [
202
151
  {
203
152
  value: {
@@ -207,24 +156,55 @@ describe("Cart Update Actions", () => {
207
156
  fractionDigits: 2,
208
157
  } as CentPrecisionMoney,
209
158
  },
159
+ {
160
+ value: {
161
+ type: "centPrecision",
162
+ currencyCode: "GBP",
163
+ centAmount: 18900,
164
+ fractionDigits: 2,
165
+ } as CentPrecisionMoney,
166
+ },
210
167
  ],
168
+
211
169
  attributes: [
212
170
  {
213
- name: "test2",
214
- value: "test2",
171
+ name: "test",
172
+ value: "test",
215
173
  },
216
174
  ],
217
175
  },
218
- ],
219
- slug: {
220
- "nl-NL": "test-product",
221
- },
222
- publish: true,
223
- };
176
+ variants: [
177
+ {
178
+ sku: "1338",
179
+ prices: [
180
+ {
181
+ value: {
182
+ type: "centPrecision",
183
+ currencyCode: "EUR",
184
+ centAmount: 14900,
185
+ fractionDigits: 2,
186
+ } as CentPrecisionMoney,
187
+ },
188
+ ],
189
+ attributes: [
190
+ {
191
+ name: "test2",
192
+ value: "test2",
193
+ },
194
+ ],
195
+ },
196
+ ],
197
+ slug: {
198
+ "nl-NL": "test-product",
199
+ },
200
+ publish: true,
201
+ };
224
202
 
225
- beforeEach(async () => {
226
- await createCart("EUR");
227
- taxCategory = await createTaxCategory({
203
+ cart = await cartFactory.create({
204
+ currency: "EUR",
205
+ country: "NL",
206
+ });
207
+ taxCategory = await taxCategoryFactory.create({
228
208
  name: "Standard VAT",
229
209
  key: "standard-vat",
230
210
  rates: [
@@ -245,39 +225,41 @@ describe("Cart Update Actions", () => {
245
225
  test("no update", async () => {
246
226
  assert(cart, "cart not created");
247
227
 
248
- const response = await supertest(ctMock.app)
249
- .post(`/dummy/carts/${cart.id}`)
250
- .send({
228
+ const response = await ctMock.app.inject({
229
+ method: "POST",
230
+ url: `/dummy/carts/${cart.id}`,
231
+ payload: {
251
232
  version: 1,
252
233
  actions: [{ action: "setLocale", locale: "nl-NL" }],
253
- });
254
- expect(response.status).toBe(200);
255
- expect(response.body.version).toBe(2);
256
- expect(response.body.locale).toBe("nl-NL");
257
-
258
- const responseAgain = await supertest(ctMock.app)
259
- .post(`/dummy/carts/${cart.id}`)
260
- .send({
234
+ },
235
+ });
236
+ expect(response.statusCode).toBe(200);
237
+ expect(response.json().version).toBe(2);
238
+ expect(response.json().locale).toBe("nl-NL");
239
+
240
+ const responseAgain = await ctMock.app.inject({
241
+ method: "POST",
242
+ url: `/dummy/carts/${cart.id}`,
243
+ payload: {
261
244
  version: 2,
262
245
  actions: [{ action: "setLocale", locale: "nl-NL" }],
263
- });
264
- expect(responseAgain.status).toBe(200);
265
- expect(responseAgain.body.version).toBe(2);
266
- expect(responseAgain.body.locale).toBe("nl-NL");
246
+ },
247
+ });
248
+ expect(responseAgain.statusCode).toBe(200);
249
+ expect(responseAgain.json().version).toBe(2);
250
+ expect(responseAgain.json().locale).toBe("nl-NL");
267
251
  });
268
252
 
269
253
  test("addLineItem", async () => {
270
- const product = await supertest(ctMock.app)
271
- .post("/dummy/products")
272
- .send(productDraft)
273
- .then((x) => x.body);
254
+ const product = await productFactory.create(productDraft);
274
255
 
275
256
  assert(cart, "cart not created");
276
257
  assert(product, "product not created");
277
258
 
278
- const response = await supertest(ctMock.app)
279
- .post(`/dummy/carts/${cart.id}`)
280
- .send({
259
+ const response = await ctMock.app.inject({
260
+ method: "POST",
261
+ url: `/dummy/carts/${cart.id}`,
262
+ payload: {
281
263
  version: 1,
282
264
  actions: [
283
265
  {
@@ -286,100 +268,99 @@ describe("Cart Update Actions", () => {
286
268
  variantId: product.masterData.current.variants[0].id,
287
269
  },
288
270
  ],
289
- });
290
- expect(response.status).toBe(200);
291
- expect(response.body.version).toBe(2);
292
- expect(response.body.lineItems).toHaveLength(1);
293
- expect(response.body.totalPrice.centAmount).toEqual(14900);
271
+ },
272
+ });
273
+ expect(response.statusCode).toBe(200);
274
+ expect(response.json().version).toBe(2);
275
+ expect(response.json().lineItems).toHaveLength(1);
276
+ expect(response.json().totalPrice.centAmount).toEqual(14900);
294
277
  });
295
278
 
296
279
  test("addLineItem by SKU", async () => {
297
- const product = await supertest(ctMock.app)
298
- .post("/dummy/products")
299
- .send(productDraft)
300
- .then((x) => x.body);
280
+ const product = await productFactory.create(productDraft);
301
281
 
302
282
  assert(cart, "cart not created");
303
283
  assert(product, "product not created");
304
284
 
305
- const response = await supertest(ctMock.app)
306
- .post(`/dummy/carts/${cart.id}`)
307
- .send({
285
+ const response = await ctMock.app.inject({
286
+ method: "POST",
287
+ url: `/dummy/carts/${cart.id}`,
288
+ payload: {
308
289
  version: 1,
309
290
  actions: [{ action: "addLineItem", sku: "1337", quantity: 2 }],
310
- });
311
- expect(response.status).toBe(200);
312
- expect(response.body.version).toBe(2);
313
- expect(response.body.lineItems).toHaveLength(1);
314
- expect(response.body.totalPrice.centAmount).toEqual(29800);
291
+ },
292
+ });
293
+ expect(response.statusCode).toBe(200);
294
+ expect(response.json().version).toBe(2);
295
+ expect(response.json().lineItems).toHaveLength(1);
296
+ expect(response.json().totalPrice.centAmount).toEqual(29800);
315
297
  });
316
298
 
317
299
  test.each([
318
300
  ["EUR", 29800],
319
301
  ["GBP", 37800],
320
302
  ])("addLineItem with price selection", async (currency, total) => {
321
- await createCart(currency);
303
+ cart = await cartFactory.create({
304
+ currency,
305
+ country: "NL",
306
+ });
322
307
 
323
- const product = await supertest(ctMock.app)
324
- .post("/dummy/products")
325
- .send(productDraft)
326
- .then((x) => x.body);
308
+ const product = await productFactory.create(productDraft);
327
309
 
328
310
  assert(cart, "cart not created");
329
311
  assert(product, "product not created");
330
312
 
331
- const response = await supertest(ctMock.app)
332
- .post(`/dummy/carts/${cart.id}`)
333
- .send({
313
+ const response = await ctMock.app.inject({
314
+ method: "POST",
315
+ url: `/dummy/carts/${cart.id}`,
316
+ payload: {
334
317
  version: 1,
335
318
  actions: [{ action: "addLineItem", sku: "1337", quantity: 2 }],
336
- });
337
- expect(response.status).toBe(200);
338
- expect(response.body.version).toBe(2);
339
- expect(response.body.lineItems).toHaveLength(1);
340
- expect(response.body.lineItems[0].price.value.currencyCode).toBe(currency);
341
- expect(response.body.totalPrice.centAmount).toEqual(total);
319
+ },
320
+ });
321
+ expect(response.statusCode).toBe(200);
322
+ expect(response.json().version).toBe(2);
323
+ expect(response.json().lineItems).toHaveLength(1);
324
+ expect(response.json().lineItems[0].price.value.currencyCode).toBe(
325
+ currency,
326
+ );
327
+ expect(response.json().totalPrice.centAmount).toEqual(total);
342
328
  });
343
329
 
344
330
  test("addLineItem with custom field", async () => {
345
- const product = await supertest(ctMock.app)
346
- .post("/dummy/products")
347
- .send(productDraft)
348
- .then((x) => x.body);
349
-
350
- const type = await supertest(ctMock.app)
351
- .post("/dummy/types")
352
- .send({
353
- key: "my-type",
354
- name: {
355
- en: "My Type",
356
- },
357
- description: {
358
- en: "My Type Description",
359
- },
360
- fieldDefinitions: [
361
- {
362
- name: "foo",
363
- label: {
364
- en: "foo",
365
- },
366
- required: false,
367
- type: {
368
- name: "String",
369
- },
370
- inputHint: "SingleLine",
331
+ const product = await productFactory.create(productDraft);
332
+
333
+ const type = await typeFactory.create({
334
+ key: "my-type",
335
+ name: {
336
+ en: "My Type",
337
+ },
338
+ description: {
339
+ en: "My Type Description",
340
+ },
341
+ fieldDefinitions: [
342
+ {
343
+ name: "foo",
344
+ label: {
345
+ en: "foo",
371
346
  },
372
- ],
373
- })
374
- .then((x) => x.body);
347
+ required: false,
348
+ type: {
349
+ name: "String",
350
+ },
351
+ inputHint: "SingleLine",
352
+ },
353
+ ],
354
+ });
375
355
 
376
356
  assert(type, "type not created");
377
357
  assert(cart, "cart not created");
378
358
  assert(product, "product not created");
379
359
 
380
- const response = await supertest(ctMock.app)
381
- .post(`/dummy/carts/${cart.id}`)
382
- .send({
360
+ const response = await ctMock.app.inject({
361
+ method: "POST",
362
+ url: `/dummy/carts/${cart.id}`,
363
+ payload: {
383
364
  version: 1,
384
365
  actions: [
385
366
  {
@@ -392,55 +373,51 @@ describe("Cart Update Actions", () => {
392
373
  },
393
374
  },
394
375
  ],
395
- });
396
- expect(response.status).toBe(200);
397
- expect(response.body.version).toBe(2);
398
- expect(response.body.lineItems).toHaveLength(1);
399
- expect(response.body.lineItems[0].custom).toEqual({
376
+ },
377
+ });
378
+ expect(response.statusCode).toBe(200);
379
+ expect(response.json().version).toBe(2);
380
+ expect(response.json().lineItems).toHaveLength(1);
381
+ expect(response.json().lineItems[0].custom).toEqual({
400
382
  type: { typeId: "type", id: expect.any(String) },
401
383
  fields: { foo: "bar" },
402
384
  });
403
385
  });
404
386
 
405
387
  test("addLineItem with key", async () => {
406
- const product = await supertest(ctMock.app)
407
- .post("/dummy/products")
408
- .send(productDraft)
409
- .then((x) => x.body);
410
-
411
- const type = await supertest(ctMock.app)
412
- .post("/dummy/types")
413
- .send({
414
- key: "my-type",
415
- name: {
416
- en: "My Type",
417
- },
418
- description: {
419
- en: "My Type Description",
420
- },
421
- fieldDefinitions: [
422
- {
423
- name: "foo",
424
- label: {
425
- en: "foo",
426
- },
427
- required: false,
428
- type: {
429
- name: "String",
430
- },
431
- inputHint: "SingleLine",
388
+ const product = await productFactory.create(productDraft);
389
+
390
+ const type = await typeFactory.create({
391
+ key: "my-type",
392
+ name: {
393
+ en: "My Type",
394
+ },
395
+ description: {
396
+ en: "My Type Description",
397
+ },
398
+ fieldDefinitions: [
399
+ {
400
+ name: "foo",
401
+ label: {
402
+ en: "foo",
432
403
  },
433
- ],
434
- })
435
- .then((x) => x.body);
404
+ required: false,
405
+ type: {
406
+ name: "String",
407
+ },
408
+ inputHint: "SingleLine",
409
+ },
410
+ ],
411
+ });
436
412
 
437
413
  assert(type, "type not created");
438
414
  assert(cart, "cart not created");
439
415
  assert(product, "product not created");
440
416
 
441
- const response = await supertest(ctMock.app)
442
- .post(`/dummy/carts/${cart.id}`)
443
- .send({
417
+ const response = await ctMock.app.inject({
418
+ method: "POST",
419
+ url: `/dummy/carts/${cart.id}`,
420
+ payload: {
444
421
  version: 1,
445
422
  actions: [
446
423
  {
@@ -454,38 +431,39 @@ describe("Cart Update Actions", () => {
454
431
  },
455
432
  },
456
433
  ],
457
- });
458
- expect(response.status).toBe(200);
459
- expect(response.body.version).toBe(2);
460
- expect(response.body.lineItems).toHaveLength(1);
461
- expect(response.body.lineItems[0].key).toBeDefined();
462
- expect(response.body.lineItems[0].key).toBe("my-key");
434
+ },
435
+ });
436
+ expect(response.statusCode).toBe(200);
437
+ expect(response.json().version).toBe(2);
438
+ expect(response.json().lineItems).toHaveLength(1);
439
+ expect(response.json().lineItems[0].key).toBeDefined();
440
+ expect(response.json().lineItems[0].key).toBe("my-key");
463
441
  });
464
442
 
465
443
  test("addLineItem unknown product", async () => {
466
444
  assert(cart, "cart not created");
467
445
 
468
- const response = await supertest(ctMock.app)
469
- .post(`/dummy/carts/${cart.id}`)
470
- .send({
446
+ const response = await ctMock.app.inject({
447
+ method: "POST",
448
+ url: `/dummy/carts/${cart.id}`,
449
+ payload: {
471
450
  version: 1,
472
451
  actions: [{ action: "addLineItem", productId: "123", variantId: 1 }],
473
- });
474
- expect(response.status).toBe(400);
475
- expect(response.body.message).toBe("A product with ID '123' not found.");
452
+ },
453
+ });
454
+ expect(response.statusCode).toBe(400);
455
+ expect(response.json().message).toBe("A product with ID '123' not found.");
476
456
  });
477
457
 
478
458
  test("addItemShippingAddress", async () => {
479
- await supertest(ctMock.app)
480
- .post("/dummy/products")
481
- .send(productDraft)
482
- .then((x) => x.body);
459
+ await productFactory.create(productDraft);
483
460
 
484
461
  assert(cart, "cart not created");
485
462
 
486
- const response = await supertest(ctMock.app)
487
- .post(`/dummy/carts/${cart.id}`)
488
- .send({
463
+ const response = await ctMock.app.inject({
464
+ method: "POST",
465
+ url: `/dummy/carts/${cart.id}`,
466
+ payload: {
489
467
  version: 1,
490
468
  actions: [
491
469
  {
@@ -498,20 +476,22 @@ describe("Cart Update Actions", () => {
498
476
  },
499
477
  },
500
478
  ],
501
- });
479
+ },
480
+ });
502
481
 
503
- expect(response.body.itemShippingAddresses).toHaveLength(1);
504
- expect(response.status).toBe(200);
505
- expect(response.body.version).toBe(2);
506
- expect(response.body.lineItems).toHaveLength(0);
482
+ expect(response.json().itemShippingAddresses).toHaveLength(1);
483
+ expect(response.statusCode).toBe(200);
484
+ expect(response.json().version).toBe(2);
485
+ expect(response.json().lineItems).toHaveLength(0);
507
486
  });
508
487
 
509
488
  test("changeTaxRoundingMode", async () => {
510
489
  assert(cart, "cart not created");
511
490
 
512
- const response = await supertest(ctMock.app)
513
- .post(`/dummy/carts/${cart.id}`)
514
- .send({
491
+ const response = await ctMock.app.inject({
492
+ method: "POST",
493
+ url: `/dummy/carts/${cart.id}`,
494
+ payload: {
515
495
  version: 1,
516
496
  actions: [
517
497
  {
@@ -519,24 +499,23 @@ describe("Cart Update Actions", () => {
519
499
  taxRoundingMode: "HalfUp",
520
500
  },
521
501
  ],
522
- });
502
+ },
503
+ });
523
504
 
524
- expect(response.status).toBe(200);
525
- expect(response.body.version).toBe(2);
526
- expect(response.body.taxRoundingMode).toBe("HalfUp");
505
+ expect(response.statusCode).toBe(200);
506
+ expect(response.json().version).toBe(2);
507
+ expect(response.json().taxRoundingMode).toBe("HalfUp");
527
508
  });
528
509
 
529
510
  test("recalculate", async () => {
530
- await supertest(ctMock.app)
531
- .post("/dummy/products")
532
- .send(productDraft)
533
- .then((x) => x.body);
511
+ await productFactory.create(productDraft);
534
512
 
535
513
  assert(cart, "cart not created");
536
514
 
537
- const response = await supertest(ctMock.app)
538
- .post(`/dummy/carts/${cart.id}`)
539
- .send({
515
+ const response = await ctMock.app.inject({
516
+ method: "POST",
517
+ url: `/dummy/carts/${cart.id}`,
518
+ payload: {
540
519
  version: 1,
541
520
  actions: [
542
521
  {
@@ -544,24 +523,23 @@ describe("Cart Update Actions", () => {
544
523
  updateProductData: true,
545
524
  },
546
525
  ],
547
- });
526
+ },
527
+ });
548
528
 
549
- expect(response.status).toBe(200);
550
- expect(response.body.version).toBe(1);
529
+ expect(response.statusCode).toBe(200);
530
+ expect(response.json().version).toBe(1);
551
531
  });
552
532
 
553
533
  test("removeLineItem", async () => {
554
- const product = await supertest(ctMock.app)
555
- .post("/dummy/products")
556
- .send(productDraft)
557
- .then((x) => x.body);
534
+ const product = await productFactory.create(productDraft);
558
535
 
559
536
  assert(cart, "cart not created");
560
537
  assert(product, "product not created");
561
538
 
562
- const updatedCart = await supertest(ctMock.app)
563
- .post(`/dummy/carts/${cart.id}`)
564
- .send({
539
+ const updatedCart = await ctMock.app.inject({
540
+ method: "POST",
541
+ url: `/dummy/carts/${cart.id}`,
542
+ payload: {
565
543
  version: 1,
566
544
  actions: [
567
545
  {
@@ -570,35 +548,36 @@ describe("Cart Update Actions", () => {
570
548
  variantId: product.masterData.current.variants[0].id,
571
549
  },
572
550
  ],
573
- });
574
- const lineItem = updatedCart.body.lineItems[0];
551
+ },
552
+ });
553
+ const lineItem = updatedCart.json().lineItems[0];
575
554
  assert(lineItem, "lineItem not created");
576
555
 
577
- expect(updatedCart.body.lineItems).toHaveLength(1);
556
+ expect(updatedCart.json().lineItems).toHaveLength(1);
578
557
 
579
- const response = await supertest(ctMock.app)
580
- .post(`/dummy/carts/${cart.id}`)
581
- .send({
582
- version: updatedCart.body.version,
558
+ const response = await ctMock.app.inject({
559
+ method: "POST",
560
+ url: `/dummy/carts/${cart.id}`,
561
+ payload: {
562
+ version: updatedCart.json().version,
583
563
  actions: [{ action: "removeLineItem", lineItemId: lineItem.id }],
584
- });
585
- expect(response.status).toBe(200);
586
- expect(response.body.version).toBe(3);
587
- expect(response.body.lineItems).toHaveLength(0);
564
+ },
565
+ });
566
+ expect(response.statusCode).toBe(200);
567
+ expect(response.json().version).toBe(3);
568
+ expect(response.json().lineItems).toHaveLength(0);
588
569
  });
589
570
 
590
571
  test("removeLineItem decrease quantity", async () => {
591
- const product = await supertest(ctMock.app)
592
- .post("/dummy/products")
593
- .send(productDraft)
594
- .then((x) => x.body);
572
+ const product = await productFactory.create(productDraft);
595
573
 
596
574
  assert(cart, "cart not created");
597
575
  assert(product, "product not created");
598
576
 
599
- const updatedCart = await supertest(ctMock.app)
600
- .post(`/dummy/carts/${cart.id}`)
601
- .send({
577
+ const updatedCart = await ctMock.app.inject({
578
+ method: "POST",
579
+ url: `/dummy/carts/${cart.id}`,
580
+ payload: {
602
581
  version: 1,
603
582
  actions: [
604
583
  {
@@ -608,25 +587,28 @@ describe("Cart Update Actions", () => {
608
587
  quantity: 2,
609
588
  },
610
589
  ],
611
- });
612
- const lineItem = updatedCart.body.lineItems[0];
590
+ },
591
+ });
592
+ const lineItem = updatedCart.json().lineItems[0];
613
593
  assert(lineItem, "lineItem not created");
614
594
 
615
- expect(updatedCart.body.lineItems).toHaveLength(1);
616
- expect(updatedCart.body.lineItems[0].quantity).toBe(2);
595
+ expect(updatedCart.json().lineItems).toHaveLength(1);
596
+ expect(updatedCart.json().lineItems[0].quantity).toBe(2);
617
597
 
618
- const response = await supertest(ctMock.app)
619
- .post(`/dummy/carts/${cart.id}`)
620
- .send({
621
- version: updatedCart.body.version,
598
+ const response = await ctMock.app.inject({
599
+ method: "POST",
600
+ url: `/dummy/carts/${cart.id}`,
601
+ payload: {
602
+ version: updatedCart.json().version,
622
603
  actions: [
623
604
  { action: "removeLineItem", lineItemId: lineItem.id, quantity: 1 },
624
605
  ],
625
- });
626
- expect(response.status).toBe(200);
627
- expect(response.body.version).toBe(3);
628
- expect(response.body.lineItems).toHaveLength(1);
629
- expect(response.body.lineItems[0].quantity).toBe(1);
606
+ },
607
+ });
608
+ expect(response.statusCode).toBe(200);
609
+ expect(response.json().version).toBe(3);
610
+ expect(response.json().lineItems).toHaveLength(1);
611
+ expect(response.json().lineItems[0].quantity).toBe(1);
630
612
  });
631
613
 
632
614
  test("setBillingAddress", async () => {
@@ -638,15 +620,17 @@ describe("Cart Update Actions", () => {
638
620
  country: "NL",
639
621
  };
640
622
 
641
- const response = await supertest(ctMock.app)
642
- .post(`/dummy/carts/${cart.id}`)
643
- .send({
623
+ const response = await ctMock.app.inject({
624
+ method: "POST",
625
+ url: `/dummy/carts/${cart.id}`,
626
+ payload: {
644
627
  version: 1,
645
628
  actions: [{ action: "setBillingAddress", address }],
646
- });
647
- expect(response.status).toBe(200);
648
- expect(response.body.version).toBe(2);
649
- expect(response.body.billingAddress).toEqual({
629
+ },
630
+ });
631
+ expect(response.statusCode).toBe(200);
632
+ expect(response.json().version).toBe(2);
633
+ expect(response.json().billingAddress).toEqual({
650
634
  ...address,
651
635
  id: expect.any(String),
652
636
  });
@@ -655,23 +639,26 @@ describe("Cart Update Actions", () => {
655
639
  test("setCountry", async () => {
656
640
  assert(cart, "cart not created");
657
641
 
658
- const response = await supertest(ctMock.app)
659
- .post(`/dummy/carts/${cart.id}`)
660
- .send({
642
+ const response = await ctMock.app.inject({
643
+ method: "POST",
644
+ url: `/dummy/carts/${cart.id}`,
645
+ payload: {
661
646
  version: 1,
662
647
  actions: [{ action: "setCountry", country: "BE" }],
663
- });
664
- expect(response.status).toBe(200);
665
- expect(response.body.version).toBe(2);
666
- expect(response.body.country).toBe("BE");
648
+ },
649
+ });
650
+ expect(response.statusCode).toBe(200);
651
+ expect(response.json().version).toBe(2);
652
+ expect(response.json().country).toBe("BE");
667
653
  });
668
654
 
669
655
  test("setDirectDiscounts", async () => {
670
656
  assert(cart, "cart not created");
671
657
 
672
- const response = await supertest(ctMock.app)
673
- .post(`/dummy/carts/${cart.id}`)
674
- .send({
658
+ const response = await ctMock.app.inject({
659
+ method: "POST",
660
+ url: `/dummy/carts/${cart.id}`,
661
+ payload: {
675
662
  version: 1,
676
663
  actions: [
677
664
  {
@@ -694,10 +681,11 @@ describe("Cart Update Actions", () => {
694
681
  ],
695
682
  },
696
683
  ],
697
- });
698
- expect(response.status).toBe(200);
699
- expect(response.body.version).toBe(2);
700
- expect(response.body.directDiscounts).toMatchObject([
684
+ },
685
+ });
686
+ expect(response.statusCode).toBe(200);
687
+ expect(response.json().version).toBe(2);
688
+ expect(response.json().directDiscounts).toMatchObject([
701
689
  {
702
690
  id: expect.any(String),
703
691
  target: { type: "totalPrice" },
@@ -717,22 +705,16 @@ describe("Cart Update Actions", () => {
717
705
  });
718
706
 
719
707
  test("setLineItemPrice sets an external price for a line item", async () => {
720
- const product = await supertest(ctMock.app)
721
- .post("/dummy/products")
722
- .send(productDraft)
723
- .then((x) => x.body);
708
+ const product = await productFactory.create(productDraft);
724
709
 
725
710
  assert(product, "product not created");
726
711
 
727
- const baseCartResponse = await supertest(ctMock.app)
728
- .post("/dummy/carts")
729
- .send({ currency: "EUR" });
730
- expect(baseCartResponse.status).toBe(201);
731
- const baseCart = baseCartResponse.body as Cart;
712
+ const baseCart = await cartFactory.create({ currency: "EUR" });
732
713
 
733
- const addLineItemResponse = await supertest(ctMock.app)
734
- .post(`/dummy/carts/${baseCart.id}`)
735
- .send({
714
+ const addLineItemResponse = await ctMock.app.inject({
715
+ method: "POST",
716
+ url: `/dummy/carts/${baseCart.id}`,
717
+ payload: {
736
718
  version: baseCart.version,
737
719
  actions: [
738
720
  {
@@ -742,9 +724,10 @@ describe("Cart Update Actions", () => {
742
724
  key: "line-item-key",
743
725
  },
744
726
  ],
745
- });
746
- expect(addLineItemResponse.status).toBe(200);
747
- const cartWithLineItem = addLineItemResponse.body as Cart;
727
+ },
728
+ });
729
+ expect(addLineItemResponse.statusCode).toBe(200);
730
+ const cartWithLineItem = addLineItemResponse.json() as Cart;
748
731
  const lineItem = cartWithLineItem.lineItems[0];
749
732
  assert(lineItem, "lineItem not created");
750
733
 
@@ -755,9 +738,10 @@ describe("Cart Update Actions", () => {
755
738
  fractionDigits: 2,
756
739
  };
757
740
 
758
- const response = await supertest(ctMock.app)
759
- .post(`/dummy/carts/${cartWithLineItem.id}`)
760
- .send({
741
+ const response = await ctMock.app.inject({
742
+ method: "POST",
743
+ url: `/dummy/carts/${cartWithLineItem.id}`,
744
+ payload: {
761
745
  version: cartWithLineItem.version,
762
746
  actions: [
763
747
  {
@@ -766,13 +750,14 @@ describe("Cart Update Actions", () => {
766
750
  externalPrice,
767
751
  },
768
752
  ],
769
- });
753
+ },
754
+ });
770
755
 
771
- expect(response.status).toBe(200);
772
- expect(response.body.version).toBe(cartWithLineItem.version + 1);
773
- expect(response.body.lineItems).toHaveLength(1);
756
+ expect(response.statusCode).toBe(200);
757
+ expect(response.json().version).toBe(cartWithLineItem.version + 1);
758
+ expect(response.json().lineItems).toHaveLength(1);
774
759
 
775
- const updatedLineItem = response.body.lineItems[0];
760
+ const updatedLineItem = response.json().lineItems[0];
776
761
  expect(updatedLineItem.priceMode).toBe("ExternalPrice");
777
762
  expect(updatedLineItem.price.value.centAmount).toBe(
778
763
  externalPrice.centAmount,
@@ -783,28 +768,22 @@ describe("Cart Update Actions", () => {
783
768
  expect(updatedLineItem.totalPrice.centAmount).toBe(
784
769
  externalPrice.centAmount * updatedLineItem.quantity,
785
770
  );
786
- expect(response.body.totalPrice.centAmount).toBe(
771
+ expect(response.json().totalPrice.centAmount).toBe(
787
772
  externalPrice.centAmount * updatedLineItem.quantity,
788
773
  );
789
774
  });
790
775
 
791
776
  test("setLineItemPrice supports high precision external price", async () => {
792
- const product = await supertest(ctMock.app)
793
- .post("/dummy/products")
794
- .send(productDraft)
795
- .then((x) => x.body);
777
+ const product = await productFactory.create(productDraft);
796
778
 
797
779
  assert(product, "product not created");
798
780
 
799
- const baseCartResponse = await supertest(ctMock.app)
800
- .post("/dummy/carts")
801
- .send({ currency: "EUR" });
802
- expect(baseCartResponse.status).toBe(201);
803
- const baseCart = baseCartResponse.body as Cart;
781
+ const baseCart = await cartFactory.create({ currency: "EUR" });
804
782
 
805
- const addLineItemResponse = await supertest(ctMock.app)
806
- .post(`/dummy/carts/${baseCart.id}`)
807
- .send({
783
+ const addLineItemResponse = await ctMock.app.inject({
784
+ method: "POST",
785
+ url: `/dummy/carts/${baseCart.id}`,
786
+ payload: {
808
787
  version: baseCart.version,
809
788
  actions: [
810
789
  {
@@ -813,9 +792,10 @@ describe("Cart Update Actions", () => {
813
792
  quantity: 2,
814
793
  },
815
794
  ],
816
- });
817
- expect(addLineItemResponse.status).toBe(200);
818
- const cartWithLineItem = addLineItemResponse.body as Cart;
795
+ },
796
+ });
797
+ expect(addLineItemResponse.statusCode).toBe(200);
798
+ const cartWithLineItem = addLineItemResponse.json() as Cart;
819
799
  const lineItem = cartWithLineItem.lineItems[0];
820
800
  assert(lineItem, "lineItem not created");
821
801
 
@@ -834,9 +814,10 @@ describe("Cart Update Actions", () => {
834
814
  2,
835
815
  );
836
816
 
837
- const response = await supertest(ctMock.app)
838
- .post(`/dummy/carts/${cartWithLineItem.id}`)
839
- .send({
817
+ const response = await ctMock.app.inject({
818
+ method: "POST",
819
+ url: `/dummy/carts/${cartWithLineItem.id}`,
820
+ payload: {
840
821
  version: cartWithLineItem.version,
841
822
  actions: [
842
823
  {
@@ -845,13 +826,14 @@ describe("Cart Update Actions", () => {
845
826
  externalPrice,
846
827
  },
847
828
  ],
848
- });
829
+ },
830
+ });
849
831
 
850
- expect(response.status).toBe(200);
851
- expect(response.body.version).toBe(cartWithLineItem.version + 1);
852
- expect(response.body.lineItems).toHaveLength(1);
832
+ expect(response.statusCode).toBe(200);
833
+ expect(response.json().version).toBe(cartWithLineItem.version + 1);
834
+ expect(response.json().lineItems).toHaveLength(1);
853
835
 
854
- const updatedLineItem = response.body.lineItems[0];
836
+ const updatedLineItem = response.json().lineItems[0];
855
837
  expect(updatedLineItem.priceMode).toBe("ExternalPrice");
856
838
  expect(updatedLineItem.price.value.type).toBe("highPrecision");
857
839
  expect(updatedLineItem.price.value.currencyCode).toBe(
@@ -865,26 +847,20 @@ describe("Cart Update Actions", () => {
865
847
  );
866
848
  expect(updatedLineItem.price.value.centAmount).toBe(expectedUnitCentAmount);
867
849
  expect(updatedLineItem.totalPrice.centAmount).toBe(expectedTotalCentAmount);
868
- expect(response.body.totalPrice.centAmount).toBe(expectedTotalCentAmount);
850
+ expect(response.json().totalPrice.centAmount).toBe(expectedTotalCentAmount);
869
851
  });
870
852
 
871
853
  test("setLineItemPrice supports high precision external price with fractionDigits 5", async () => {
872
- const product = await supertest(ctMock.app)
873
- .post("/dummy/products")
874
- .send(productDraft)
875
- .then((x) => x.body);
854
+ const product = await productFactory.create(productDraft);
876
855
 
877
856
  assert(product, "product not created");
878
857
 
879
- const baseCartResponse = await supertest(ctMock.app)
880
- .post("/dummy/carts")
881
- .send({ currency: "EUR" });
882
- expect(baseCartResponse.status).toBe(201);
883
- const baseCart = baseCartResponse.body as Cart;
858
+ const baseCart = await cartFactory.create({ currency: "EUR" });
884
859
 
885
- const addLineItemResponse = await supertest(ctMock.app)
886
- .post(`/dummy/carts/${baseCart.id}`)
887
- .send({
860
+ const addLineItemResponse = await ctMock.app.inject({
861
+ method: "POST",
862
+ url: `/dummy/carts/${baseCart.id}`,
863
+ payload: {
888
864
  version: baseCart.version,
889
865
  actions: [
890
866
  {
@@ -893,9 +869,10 @@ describe("Cart Update Actions", () => {
893
869
  quantity: 2,
894
870
  },
895
871
  ],
896
- });
897
- expect(addLineItemResponse.status).toBe(200);
898
- const cartWithLineItem = addLineItemResponse.body as Cart;
872
+ },
873
+ });
874
+ expect(addLineItemResponse.statusCode).toBe(200);
875
+ const cartWithLineItem = addLineItemResponse.json() as Cart;
899
876
  const lineItem = cartWithLineItem.lineItems[0];
900
877
  assert(lineItem, "lineItem not created");
901
878
 
@@ -914,9 +891,10 @@ describe("Cart Update Actions", () => {
914
891
  2,
915
892
  );
916
893
 
917
- const response = await supertest(ctMock.app)
918
- .post(`/dummy/carts/${cartWithLineItem.id}`)
919
- .send({
894
+ const response = await ctMock.app.inject({
895
+ method: "POST",
896
+ url: `/dummy/carts/${cartWithLineItem.id}`,
897
+ payload: {
920
898
  version: cartWithLineItem.version,
921
899
  actions: [
922
900
  {
@@ -925,13 +903,14 @@ describe("Cart Update Actions", () => {
925
903
  externalPrice,
926
904
  },
927
905
  ],
928
- });
906
+ },
907
+ });
929
908
 
930
- expect(response.status).toBe(200);
931
- expect(response.body.version).toBe(cartWithLineItem.version + 1);
932
- expect(response.body.lineItems).toHaveLength(1);
909
+ expect(response.statusCode).toBe(200);
910
+ expect(response.json().version).toBe(cartWithLineItem.version + 1);
911
+ expect(response.json().lineItems).toHaveLength(1);
933
912
 
934
- const updatedLineItem = response.body.lineItems[0];
913
+ const updatedLineItem = response.json().lineItems[0];
935
914
  expect(updatedLineItem.priceMode).toBe("ExternalPrice");
936
915
  expect(updatedLineItem.price.value.type).toBe("highPrecision");
937
916
  expect(updatedLineItem.price.value.currencyCode).toBe(
@@ -945,26 +924,20 @@ describe("Cart Update Actions", () => {
945
924
  );
946
925
  expect(updatedLineItem.price.value.centAmount).toBe(expectedUnitCentAmount);
947
926
  expect(updatedLineItem.totalPrice.centAmount).toBe(expectedTotalCentAmount);
948
- expect(response.body.totalPrice.centAmount).toBe(expectedTotalCentAmount);
927
+ expect(response.json().totalPrice.centAmount).toBe(expectedTotalCentAmount);
949
928
  });
950
929
 
951
930
  test("setLineItemPrice fails when the money uses another currency", async () => {
952
- const product = await supertest(ctMock.app)
953
- .post("/dummy/products")
954
- .send(productDraft)
955
- .then((x) => x.body);
931
+ const product = await productFactory.create(productDraft);
956
932
 
957
933
  assert(product, "product not created");
958
934
 
959
- const baseCartResponse = await supertest(ctMock.app)
960
- .post("/dummy/carts")
961
- .send({ currency: "EUR" });
962
- expect(baseCartResponse.status).toBe(201);
963
- const baseCart = baseCartResponse.body as Cart;
935
+ const baseCart = await cartFactory.create({ currency: "EUR" });
964
936
 
965
- const addLineItemResponse = await supertest(ctMock.app)
966
- .post(`/dummy/carts/${baseCart.id}`)
967
- .send({
937
+ const addLineItemResponse = await ctMock.app.inject({
938
+ method: "POST",
939
+ url: `/dummy/carts/${baseCart.id}`,
940
+ payload: {
968
941
  version: baseCart.version,
969
942
  actions: [
970
943
  {
@@ -973,15 +946,17 @@ describe("Cart Update Actions", () => {
973
946
  quantity: 1,
974
947
  },
975
948
  ],
976
- });
977
- expect(addLineItemResponse.status).toBe(200);
978
- const cartWithLineItem = addLineItemResponse.body as Cart;
949
+ },
950
+ });
951
+ expect(addLineItemResponse.statusCode).toBe(200);
952
+ const cartWithLineItem = addLineItemResponse.json() as Cart;
979
953
  const lineItem = cartWithLineItem.lineItems[0];
980
954
  assert(lineItem, "lineItem not created");
981
955
 
982
- const response = await supertest(ctMock.app)
983
- .post(`/dummy/carts/${cartWithLineItem.id}`)
984
- .send({
956
+ const response = await ctMock.app.inject({
957
+ method: "POST",
958
+ url: `/dummy/carts/${cartWithLineItem.id}`,
959
+ payload: {
985
960
  version: cartWithLineItem.version,
986
961
  actions: [
987
962
  {
@@ -995,29 +970,24 @@ describe("Cart Update Actions", () => {
995
970
  },
996
971
  },
997
972
  ],
998
- });
973
+ },
974
+ });
999
975
 
1000
- expect(response.status).toBe(400);
1001
- expect(response.body.message).toContain("Currency mismatch");
976
+ expect(response.statusCode).toBe(400);
977
+ expect(response.json().message).toContain("Currency mismatch");
1002
978
  });
1003
979
 
1004
980
  test("setLineItemPrice removes external price when no value is provided", async () => {
1005
- const product = await supertest(ctMock.app)
1006
- .post("/dummy/products")
1007
- .send(productDraft)
1008
- .then((x) => x.body);
981
+ const product = await productFactory.create(productDraft);
1009
982
 
1010
983
  assert(product, "product not created");
1011
984
 
1012
- const baseCartResponse = await supertest(ctMock.app)
1013
- .post("/dummy/carts")
1014
- .send({ currency: "EUR" });
1015
- expect(baseCartResponse.status).toBe(201);
1016
- const baseCart = baseCartResponse.body as Cart;
985
+ const baseCart = await cartFactory.create({ currency: "EUR" });
1017
986
 
1018
- const addLineItemResponse = await supertest(ctMock.app)
1019
- .post(`/dummy/carts/${baseCart.id}`)
1020
- .send({
987
+ const addLineItemResponse = await ctMock.app.inject({
988
+ method: "POST",
989
+ url: `/dummy/carts/${baseCart.id}`,
990
+ payload: {
1021
991
  version: baseCart.version,
1022
992
  actions: [
1023
993
  {
@@ -1026,9 +996,10 @@ describe("Cart Update Actions", () => {
1026
996
  quantity: 1,
1027
997
  },
1028
998
  ],
1029
- });
1030
- expect(addLineItemResponse.status).toBe(200);
1031
- const cartWithLineItem = addLineItemResponse.body as Cart;
999
+ },
1000
+ });
1001
+ expect(addLineItemResponse.statusCode).toBe(200);
1002
+ const cartWithLineItem = addLineItemResponse.json() as Cart;
1032
1003
  const lineItem = cartWithLineItem.lineItems[0];
1033
1004
  assert(lineItem, "lineItem not created");
1034
1005
 
@@ -1039,9 +1010,10 @@ describe("Cart Update Actions", () => {
1039
1010
  fractionDigits: 2,
1040
1011
  };
1041
1012
 
1042
- const setExternalPriceResponse = await supertest(ctMock.app)
1043
- .post(`/dummy/carts/${cartWithLineItem.id}`)
1044
- .send({
1013
+ const setExternalPriceResponse = await ctMock.app.inject({
1014
+ method: "POST",
1015
+ url: `/dummy/carts/${cartWithLineItem.id}`,
1016
+ payload: {
1045
1017
  version: cartWithLineItem.version,
1046
1018
  actions: [
1047
1019
  {
@@ -1050,14 +1022,16 @@ describe("Cart Update Actions", () => {
1050
1022
  externalPrice,
1051
1023
  },
1052
1024
  ],
1053
- });
1054
- expect(setExternalPriceResponse.status).toBe(200);
1055
- const cartWithExternalPrice = setExternalPriceResponse.body as Cart;
1025
+ },
1026
+ });
1027
+ expect(setExternalPriceResponse.statusCode).toBe(200);
1028
+ const cartWithExternalPrice = setExternalPriceResponse.json() as Cart;
1056
1029
  expect(cartWithExternalPrice.lineItems[0].priceMode).toBe("ExternalPrice");
1057
1030
 
1058
- const resetResponse = await supertest(ctMock.app)
1059
- .post(`/dummy/carts/${cartWithExternalPrice.id}`)
1060
- .send({
1031
+ const resetResponse = await ctMock.app.inject({
1032
+ method: "POST",
1033
+ url: `/dummy/carts/${cartWithExternalPrice.id}`,
1034
+ payload: {
1061
1035
  version: cartWithExternalPrice.version,
1062
1036
  actions: [
1063
1037
  {
@@ -1065,13 +1039,16 @@ describe("Cart Update Actions", () => {
1065
1039
  lineItemId: lineItem.id,
1066
1040
  },
1067
1041
  ],
1068
- });
1042
+ },
1043
+ });
1069
1044
 
1070
- expect(resetResponse.status).toBe(200);
1071
- expect(resetResponse.body.version).toBe(cartWithExternalPrice.version + 1);
1072
- expect(resetResponse.body.lineItems).toHaveLength(1);
1045
+ expect(resetResponse.statusCode).toBe(200);
1046
+ expect(resetResponse.json().version).toBe(
1047
+ cartWithExternalPrice.version + 1,
1048
+ );
1049
+ expect(resetResponse.json().lineItems).toHaveLength(1);
1073
1050
 
1074
- const revertedLineItem = resetResponse.body.lineItems[0];
1051
+ const revertedLineItem = resetResponse.json().lineItems[0];
1075
1052
  const expectedCentAmount =
1076
1053
  product.masterData.current.masterVariant.prices?.[0].value.centAmount;
1077
1054
  if (typeof expectedCentAmount !== "number") {
@@ -1082,73 +1059,65 @@ describe("Cart Update Actions", () => {
1082
1059
  expect(revertedLineItem.totalPrice.centAmount).toBe(
1083
1060
  expectedCentAmount * revertedLineItem.quantity,
1084
1061
  );
1085
- expect(resetResponse.body.totalPrice.centAmount).toBe(
1062
+ expect(resetResponse.json().totalPrice.centAmount).toBe(
1086
1063
  expectedCentAmount * revertedLineItem.quantity,
1087
1064
  );
1088
1065
  });
1089
1066
 
1090
1067
  test("setLineItemCustomField", async () => {
1091
- const product = await supertest(ctMock.app)
1092
- .post("/dummy/products")
1093
- .send(productDraft)
1094
- .then((x) => x.body);
1068
+ const product = await productFactory.create(productDraft);
1095
1069
 
1096
1070
  assert(product, "product not created");
1097
1071
 
1098
- const type = await supertest(ctMock.app)
1099
- .post("/dummy/types")
1100
- .send({
1101
- key: "my-type",
1102
- name: {
1103
- en: "My Type",
1104
- },
1105
- description: {
1106
- en: "My Type Description",
1107
- },
1108
- fieldDefinitions: [
1109
- {
1110
- name: "foo",
1111
- label: {
1112
- en: "foo",
1113
- },
1114
- required: false,
1115
- type: {
1116
- name: "String",
1117
- },
1118
- inputHint: "SingleLine",
1072
+ const type = await typeFactory.create({
1073
+ key: "my-type",
1074
+ name: {
1075
+ en: "My Type",
1076
+ },
1077
+ description: {
1078
+ en: "My Type Description",
1079
+ },
1080
+ fieldDefinitions: [
1081
+ {
1082
+ name: "foo",
1083
+ label: {
1084
+ en: "foo",
1119
1085
  },
1120
- ],
1121
- })
1122
- .then((x) => x.body);
1086
+ required: false,
1087
+ type: {
1088
+ name: "String",
1089
+ },
1090
+ inputHint: "SingleLine",
1091
+ },
1092
+ ],
1093
+ });
1123
1094
 
1124
1095
  assert(type, "type not created");
1125
1096
 
1126
- const myCart = await supertest(ctMock.app)
1127
- .post("/dummy/carts")
1128
- .send({
1129
- currency: "EUR",
1130
- lineItems: [
1131
- {
1132
- sku: product.masterData.current.masterVariant.sku,
1133
- quantity: 1,
1134
- custom: {
1135
- type: {
1136
- typeId: "type",
1137
- key: "my-type",
1138
- },
1139
- fields: {},
1097
+ const myCart = await cartFactory.create({
1098
+ currency: "EUR",
1099
+ lineItems: [
1100
+ {
1101
+ sku: product.masterData.current.masterVariant.sku,
1102
+ quantity: 1,
1103
+ custom: {
1104
+ type: {
1105
+ typeId: "type",
1106
+ key: "my-type",
1140
1107
  },
1108
+ fields: {},
1141
1109
  },
1142
- ],
1143
- })
1144
- .then((x) => x.body);
1110
+ },
1111
+ ],
1112
+ });
1145
1113
 
1146
1114
  const lineItem = myCart.lineItems[0];
1147
1115
  assert(lineItem, "lineItem not created");
1148
1116
 
1149
- const response = await supertest(ctMock.app)
1150
- .post(`/dummy/carts/${myCart.id}`)
1151
- .send({
1117
+ const response = await ctMock.app.inject({
1118
+ method: "POST",
1119
+ url: `/dummy/carts/${myCart.id}`,
1120
+ payload: {
1152
1121
  version: myCart.version,
1153
1122
  actions: [
1154
1123
  {
@@ -1158,11 +1127,12 @@ describe("Cart Update Actions", () => {
1158
1127
  value: "bar",
1159
1128
  },
1160
1129
  ],
1161
- });
1130
+ },
1131
+ });
1162
1132
 
1163
- expect(response.status).toBe(200);
1164
- expect(response.body.version).toBe(2);
1165
- expect(response.body.lineItems).toMatchObject([
1133
+ expect(response.statusCode).toBe(200);
1134
+ expect(response.json().version).toBe(2);
1135
+ expect(response.json().lineItems).toMatchObject([
1166
1136
  {
1167
1137
  id: lineItem.id,
1168
1138
  custom: {
@@ -1175,60 +1145,52 @@ describe("Cart Update Actions", () => {
1175
1145
  });
1176
1146
 
1177
1147
  test("setLineItemCustomType", async () => {
1178
- const product = await supertest(ctMock.app)
1179
- .post("/dummy/products")
1180
- .send(productDraft)
1181
- .then((x) => x.body);
1148
+ const product = await productFactory.create(productDraft);
1182
1149
 
1183
1150
  assert(product, "product not created");
1184
1151
 
1185
- const type = await supertest(ctMock.app)
1186
- .post("/dummy/types")
1187
- .send({
1188
- key: "my-type",
1189
- name: {
1190
- en: "My Type",
1191
- },
1192
- description: {
1193
- en: "My Type Description",
1194
- },
1195
- fieldDefinitions: [
1196
- {
1197
- name: "foo",
1198
- label: {
1199
- en: "foo",
1200
- },
1201
- required: false,
1202
- type: {
1203
- name: "String",
1204
- },
1205
- inputHint: "SingleLine",
1152
+ const type = await typeFactory.create({
1153
+ key: "my-type",
1154
+ name: {
1155
+ en: "My Type",
1156
+ },
1157
+ description: {
1158
+ en: "My Type Description",
1159
+ },
1160
+ fieldDefinitions: [
1161
+ {
1162
+ name: "foo",
1163
+ label: {
1164
+ en: "foo",
1206
1165
  },
1207
- ],
1208
- })
1209
- .then((x) => x.body);
1166
+ required: false,
1167
+ type: {
1168
+ name: "String",
1169
+ },
1170
+ inputHint: "SingleLine",
1171
+ },
1172
+ ],
1173
+ });
1210
1174
 
1211
1175
  assert(type, "type not created");
1212
1176
 
1213
- const myCart = await supertest(ctMock.app)
1214
- .post("/dummy/carts")
1215
- .send({
1216
- currency: "EUR",
1217
- lineItems: [
1218
- {
1219
- sku: product.masterData.current.masterVariant.sku,
1220
- quantity: 1,
1221
- },
1222
- ],
1223
- })
1224
- .then((x) => x.body);
1177
+ const myCart = await cartFactory.create({
1178
+ currency: "EUR",
1179
+ lineItems: [
1180
+ {
1181
+ sku: product.masterData.current.masterVariant.sku,
1182
+ quantity: 1,
1183
+ },
1184
+ ],
1185
+ });
1225
1186
 
1226
1187
  const lineItem = myCart.lineItems[0];
1227
1188
  assert(lineItem, "lineItem not created");
1228
1189
 
1229
- const response = await supertest(ctMock.app)
1230
- .post(`/dummy/carts/${myCart.id}`)
1231
- .send({
1190
+ const response = await ctMock.app.inject({
1191
+ method: "POST",
1192
+ url: `/dummy/carts/${myCart.id}`,
1193
+ payload: {
1232
1194
  version: myCart.version,
1233
1195
  actions: [
1234
1196
  {
@@ -1240,11 +1202,12 @@ describe("Cart Update Actions", () => {
1240
1202
  },
1241
1203
  },
1242
1204
  ],
1243
- });
1205
+ },
1206
+ });
1244
1207
 
1245
- expect(response.status).toBe(200);
1246
- expect(response.body.version).toBe(2);
1247
- expect(response.body.lineItems).toMatchObject([
1208
+ expect(response.statusCode).toBe(200);
1209
+ expect(response.json().version).toBe(2);
1210
+ expect(response.json().lineItems).toMatchObject([
1248
1211
  {
1249
1212
  id: lineItem.id,
1250
1213
  custom: {
@@ -1260,15 +1223,17 @@ describe("Cart Update Actions", () => {
1260
1223
  test("setCustomerEmail", async () => {
1261
1224
  assert(cart, "cart not created");
1262
1225
 
1263
- const response = await supertest(ctMock.app)
1264
- .post(`/dummy/carts/${cart.id}`)
1265
- .send({
1226
+ const response = await ctMock.app.inject({
1227
+ method: "POST",
1228
+ url: `/dummy/carts/${cart.id}`,
1229
+ payload: {
1266
1230
  version: 1,
1267
1231
  actions: [{ action: "setCustomerEmail", email: "john@doe.com" }],
1268
- });
1269
- expect(response.status).toBe(200);
1270
- expect(response.body.version).toBe(2);
1271
- expect(response.body.customerEmail).toBe("john@doe.com");
1232
+ },
1233
+ });
1234
+ expect(response.statusCode).toBe(200);
1235
+ expect(response.json().version).toBe(2);
1236
+ expect(response.json().customerEmail).toBe("john@doe.com");
1272
1237
  });
1273
1238
 
1274
1239
  test("setShippingAddress", async () => {
@@ -1280,15 +1245,17 @@ describe("Cart Update Actions", () => {
1280
1245
  country: "NL",
1281
1246
  };
1282
1247
 
1283
- const response = await supertest(ctMock.app)
1284
- .post(`/dummy/carts/${cart.id}`)
1285
- .send({
1248
+ const response = await ctMock.app.inject({
1249
+ method: "POST",
1250
+ url: `/dummy/carts/${cart.id}`,
1251
+ payload: {
1286
1252
  version: 1,
1287
1253
  actions: [{ action: "setShippingAddress", address }],
1288
- });
1289
- expect(response.status).toBe(200);
1290
- expect(response.body.version).toBe(2);
1291
- expect(response.body.shippingAddress).toEqual(address);
1254
+ },
1255
+ });
1256
+ expect(response.statusCode).toBe(200);
1257
+ expect(response.json().version).toBe(2);
1258
+ expect(response.json().shippingAddress).toEqual(address);
1292
1259
  });
1293
1260
 
1294
1261
  test("setBillingAddressCustomType", async () => {
@@ -1300,37 +1267,35 @@ describe("Cart Update Actions", () => {
1300
1267
  country: "NL",
1301
1268
  };
1302
1269
 
1303
- const type = await supertest(ctMock.app)
1304
- .post("/dummy/types")
1305
- .send({
1306
- key: "my-type",
1307
- name: {
1308
- en: "My Type",
1309
- },
1310
- description: {
1311
- en: "My Type Description",
1312
- },
1313
- fieldDefinitions: [
1314
- {
1315
- name: "foo",
1316
- label: {
1317
- en: "foo",
1318
- },
1319
- required: false,
1320
- type: {
1321
- name: "String",
1322
- },
1323
- inputHint: "SingleLine",
1270
+ const type = await typeFactory.create({
1271
+ key: "my-type",
1272
+ name: {
1273
+ en: "My Type",
1274
+ },
1275
+ description: {
1276
+ en: "My Type Description",
1277
+ },
1278
+ fieldDefinitions: [
1279
+ {
1280
+ name: "foo",
1281
+ label: {
1282
+ en: "foo",
1324
1283
  },
1325
- ],
1326
- })
1327
- .then((x) => x.body);
1284
+ required: false,
1285
+ type: {
1286
+ name: "String",
1287
+ },
1288
+ inputHint: "SingleLine",
1289
+ },
1290
+ ],
1291
+ });
1328
1292
 
1329
1293
  assert(type, "type not created");
1330
1294
 
1331
- const response = await supertest(ctMock.app)
1332
- .post(`/dummy/carts/${cart.id}`)
1333
- .send({
1295
+ const response = await ctMock.app.inject({
1296
+ method: "POST",
1297
+ url: `/dummy/carts/${cart.id}`,
1298
+ payload: {
1334
1299
  version: 1,
1335
1300
  actions: [
1336
1301
  { action: "setBillingAddress", address },
@@ -1346,11 +1311,12 @@ describe("Cart Update Actions", () => {
1346
1311
  },
1347
1312
  },
1348
1313
  ],
1349
- });
1314
+ },
1315
+ });
1350
1316
 
1351
- expect(response.status).toBe(200);
1352
- expect(response.body.version).toBe(3);
1353
- expect(response.body.billingAddress).toEqual({
1317
+ expect(response.statusCode).toBe(200);
1318
+ expect(response.json().version).toBe(3);
1319
+ expect(response.json().billingAddress).toEqual({
1354
1320
  ...address,
1355
1321
  id: expect.any(String),
1356
1322
  custom: {
@@ -1369,37 +1335,35 @@ describe("Cart Update Actions", () => {
1369
1335
  country: "NL",
1370
1336
  };
1371
1337
 
1372
- const type = await supertest(ctMock.app)
1373
- .post("/dummy/types")
1374
- .send({
1375
- key: "my-type",
1376
- name: {
1377
- en: "My Type",
1378
- },
1379
- description: {
1380
- en: "My Type Description",
1381
- },
1382
- fieldDefinitions: [
1383
- {
1384
- name: "foo",
1385
- label: {
1386
- en: "foo",
1387
- },
1388
- required: false,
1389
- type: {
1390
- name: "String",
1391
- },
1392
- inputHint: "SingleLine",
1338
+ const type = await typeFactory.create({
1339
+ key: "my-type",
1340
+ name: {
1341
+ en: "My Type",
1342
+ },
1343
+ description: {
1344
+ en: "My Type Description",
1345
+ },
1346
+ fieldDefinitions: [
1347
+ {
1348
+ name: "foo",
1349
+ label: {
1350
+ en: "foo",
1393
1351
  },
1394
- ],
1395
- })
1396
- .then((x) => x.body);
1352
+ required: false,
1353
+ type: {
1354
+ name: "String",
1355
+ },
1356
+ inputHint: "SingleLine",
1357
+ },
1358
+ ],
1359
+ });
1397
1360
 
1398
1361
  assert(type, "type not created");
1399
1362
 
1400
- const response = await supertest(ctMock.app)
1401
- .post(`/dummy/carts/${cart.id}`)
1402
- .send({
1363
+ const response = await ctMock.app.inject({
1364
+ method: "POST",
1365
+ url: `/dummy/carts/${cart.id}`,
1366
+ payload: {
1403
1367
  version: 1,
1404
1368
  actions: [
1405
1369
  { action: "setShippingAddress", address },
@@ -1415,11 +1379,12 @@ describe("Cart Update Actions", () => {
1415
1379
  },
1416
1380
  },
1417
1381
  ],
1418
- });
1382
+ },
1383
+ });
1419
1384
 
1420
- expect(response.status).toBe(200);
1421
- expect(response.body.version).toBe(3);
1422
- expect(response.body.shippingAddress).toEqual({
1385
+ expect(response.statusCode).toBe(200);
1386
+ expect(response.json().version).toBe(3);
1387
+ expect(response.json().shippingAddress).toEqual({
1423
1388
  ...address,
1424
1389
  custom: {
1425
1390
  type: { typeId: "type", id: type.id },
@@ -1433,9 +1398,15 @@ describe("Cart Update Actions", () => {
1433
1398
  let standardExcludedShippingMethod: ShippingMethod;
1434
1399
  beforeEach(async () => {
1435
1400
  assert(cart, "cart not created");
1436
- const nlZone = await createZone("NL");
1437
- const frZone = await createZone("FR");
1438
- const standardTax = await createTaxCategory({
1401
+ const nlZone = await zoneFactory.create({
1402
+ name: "NL",
1403
+ locations: [{ country: "NL" }],
1404
+ });
1405
+ const frZone = await zoneFactory.create({
1406
+ name: "FR",
1407
+ locations: [{ country: "FR" }],
1408
+ });
1409
+ const standardTax = await taxCategoryFactory.create({
1439
1410
  name: "Standard tax category",
1440
1411
  key: "standard",
1441
1412
  rates: [
@@ -1453,7 +1424,7 @@ describe("Cart Update Actions", () => {
1453
1424
  },
1454
1425
  ],
1455
1426
  });
1456
- await createTaxCategory({
1427
+ await taxCategoryFactory.create({
1457
1428
  name: "Reduced tax category",
1458
1429
  key: "reduced",
1459
1430
  rates: [
@@ -1471,7 +1442,7 @@ describe("Cart Update Actions", () => {
1471
1442
  },
1472
1443
  ],
1473
1444
  });
1474
- const standardExcludedTax = await createTaxCategory({
1445
+ const standardExcludedTax = await taxCategoryFactory.create({
1475
1446
  name: "Tax category that is excluded from price",
1476
1447
  key: "standard-excluded",
1477
1448
  rates: [
@@ -1489,7 +1460,7 @@ describe("Cart Update Actions", () => {
1489
1460
  },
1490
1461
  ],
1491
1462
  });
1492
- standardShippingMethod = await createShippingMethod({
1463
+ standardShippingMethod = await shippingMethodFactory.create({
1493
1464
  isDefault: false,
1494
1465
  key: "standard",
1495
1466
  name: "Standard shipping",
@@ -1533,7 +1504,7 @@ describe("Cart Update Actions", () => {
1533
1504
  ],
1534
1505
  });
1535
1506
 
1536
- standardExcludedShippingMethod = await createShippingMethod({
1507
+ standardExcludedShippingMethod = await shippingMethodFactory.create({
1537
1508
  isDefault: false,
1538
1509
  key: "standard-excluded",
1539
1510
  name: "Standard shipping with tax excluded from price",
@@ -1576,7 +1547,7 @@ describe("Cart Update Actions", () => {
1576
1547
  },
1577
1548
  ],
1578
1549
  });
1579
- await createShippingMethod({
1550
+ await shippingMethodFactory.create({
1580
1551
  isDefault: false,
1581
1552
  key: "express",
1582
1553
  name: "Express shipping",
@@ -1622,9 +1593,10 @@ describe("Cart Update Actions", () => {
1622
1593
 
1623
1594
  expect(
1624
1595
  (
1625
- await supertest(ctMock.app)
1626
- .post(`/dummy/carts/${cart.id}`)
1627
- .send({
1596
+ await ctMock.app.inject({
1597
+ method: "POST",
1598
+ url: `/dummy/carts/${cart.id}`,
1599
+ payload: {
1628
1600
  version: 1,
1629
1601
  actions: [
1630
1602
  {
@@ -1636,8 +1608,9 @@ describe("Cart Update Actions", () => {
1636
1608
  },
1637
1609
  },
1638
1610
  ],
1639
- })
1640
- ).status,
1611
+ },
1612
+ })
1613
+ ).statusCode,
1641
1614
  ).toBe(200);
1642
1615
  });
1643
1616
 
@@ -1649,15 +1622,17 @@ describe("Cart Update Actions", () => {
1649
1622
  id: standardShippingMethod.id,
1650
1623
  };
1651
1624
 
1652
- const response = await supertest(ctMock.app)
1653
- .post(`/dummy/carts/${cart.id}`)
1654
- .send({
1625
+ const response = await ctMock.app.inject({
1626
+ method: "POST",
1627
+ url: `/dummy/carts/${cart.id}`,
1628
+ payload: {
1655
1629
  version: 2,
1656
1630
  actions: [{ action: "setShippingMethod", shippingMethod }],
1657
- });
1658
- expect(response.status).toBe(200);
1659
- expect(response.body.version).toBe(3);
1660
- expect(response.body.shippingInfo.shippingMethod.id).toEqual(
1631
+ },
1632
+ });
1633
+ expect(response.statusCode).toBe(200);
1634
+ expect(response.json().version).toBe(3);
1635
+ expect(response.json().shippingInfo.shippingMethod.id).toEqual(
1661
1636
  standardShippingMethod.id,
1662
1637
  );
1663
1638
  });
@@ -1670,17 +1645,20 @@ describe("Cart Update Actions", () => {
1670
1645
  id: standardShippingMethod.id,
1671
1646
  };
1672
1647
 
1673
- const response = await supertest(ctMock.app)
1674
- .post(`/dummy/carts/${cart.id}`)
1675
- .send({
1648
+ const response = await ctMock.app.inject({
1649
+ method: "POST",
1650
+ url: `/dummy/carts/${cart.id}`,
1651
+ payload: {
1676
1652
  version: 2,
1677
1653
  actions: [{ action: "setShippingMethod", shippingMethod }],
1678
- });
1679
- expect(response.status).toBe(200);
1654
+ },
1655
+ });
1656
+ expect(response.statusCode).toBe(200);
1680
1657
 
1681
- const removeResponse = await supertest(ctMock.app)
1682
- .post(`/dummy/carts/${cart.id}`)
1683
- .send({
1658
+ const removeResponse = await ctMock.app.inject({
1659
+ method: "POST",
1660
+ url: `/dummy/carts/${cart.id}`,
1661
+ payload: {
1684
1662
  version: 3,
1685
1663
  actions: [
1686
1664
  {
@@ -1688,9 +1666,10 @@ describe("Cart Update Actions", () => {
1688
1666
  shippingKey: standardShippingMethod.key,
1689
1667
  },
1690
1668
  ],
1691
- });
1692
- expect(removeResponse.status).toBe(200);
1693
- expect(removeResponse.body.shippingInfo).toBeUndefined();
1669
+ },
1670
+ });
1671
+ expect(removeResponse.statusCode).toBe(200);
1672
+ expect(removeResponse.json().shippingInfo).toBeUndefined();
1694
1673
  });
1695
1674
 
1696
1675
  test("correctly sets shippingInfo rates + tax when includedInPrice: true", async () => {
@@ -1702,33 +1681,35 @@ describe("Cart Update Actions", () => {
1702
1681
  id: standardShippingMethod.id,
1703
1682
  };
1704
1683
 
1705
- const response = await supertest(ctMock.app)
1706
- .post(`/dummy/carts/${cart.id}`)
1707
- .send({
1684
+ const response = await ctMock.app.inject({
1685
+ method: "POST",
1686
+ url: `/dummy/carts/${cart.id}`,
1687
+ payload: {
1708
1688
  version: 2,
1709
1689
  actions: [{ action: "setShippingMethod", shippingMethod }],
1710
- });
1711
- expect(response.status).toBe(200);
1712
- expect(response.body.version).toBe(3);
1713
- expect(response.body.shippingInfo.shippingRate.price).toMatchObject({
1690
+ },
1691
+ });
1692
+ expect(response.statusCode).toBe(200);
1693
+ expect(response.json().version).toBe(3);
1694
+ expect(response.json().shippingInfo.shippingRate.price).toMatchObject({
1714
1695
  centAmount: 499,
1715
1696
  currencyCode: "EUR",
1716
1697
  fractionDigits: 2,
1717
1698
  type: "centPrecision",
1718
1699
  });
1719
- expect(response.body.shippingInfo.price).toMatchObject({
1700
+ expect(response.json().shippingInfo.price).toMatchObject({
1720
1701
  centAmount: 499,
1721
1702
  currencyCode: "EUR",
1722
1703
  fractionDigits: 2,
1723
1704
  type: "centPrecision",
1724
1705
  });
1725
- expect(response.body.shippingInfo.taxRate).toMatchObject({
1706
+ expect(response.json().shippingInfo.taxRate).toMatchObject({
1726
1707
  name: "NL standard tax rate",
1727
1708
  amount: 0.21,
1728
1709
  includedInPrice: true,
1729
1710
  country: "NL",
1730
1711
  });
1731
- expect(response.body.shippingInfo.taxedPrice).toMatchObject({
1712
+ expect(response.json().shippingInfo.taxedPrice).toMatchObject({
1732
1713
  totalNet: {
1733
1714
  type: "centPrecision",
1734
1715
  centAmount: 412,
@@ -1771,34 +1752,36 @@ describe("Cart Update Actions", () => {
1771
1752
  id: standardExcludedShippingMethod.id,
1772
1753
  };
1773
1754
 
1774
- const response = await supertest(ctMock.app)
1775
- .post(`/dummy/carts/${cart.id}`)
1776
- .send({
1755
+ const response = await ctMock.app.inject({
1756
+ method: "POST",
1757
+ url: `/dummy/carts/${cart.id}`,
1758
+ payload: {
1777
1759
  version: 2,
1778
1760
  actions: [{ action: "setShippingMethod", shippingMethod }],
1779
- });
1780
- expect(response.status).toBe(200);
1781
- expect(response.body.version).toBe(3);
1782
- expect(response.body.shippingInfo.shippingRate.price).toMatchObject({
1761
+ },
1762
+ });
1763
+ expect(response.statusCode).toBe(200);
1764
+ expect(response.json().version).toBe(3);
1765
+ expect(response.json().shippingInfo.shippingRate.price).toMatchObject({
1783
1766
  centAmount: 499,
1784
1767
  currencyCode: "EUR",
1785
1768
  fractionDigits: 2,
1786
1769
  type: "centPrecision",
1787
1770
  });
1788
1771
  // TODO: should this be gross or net? docs unclear (currently always just returns the shipping rate (tier) price)
1789
- expect(response.body.shippingInfo.price).toMatchObject({
1772
+ expect(response.json().shippingInfo.price).toMatchObject({
1790
1773
  centAmount: 499,
1791
1774
  currencyCode: "EUR",
1792
1775
  fractionDigits: 2,
1793
1776
  type: "centPrecision",
1794
1777
  });
1795
- expect(response.body.shippingInfo.taxRate).toMatchObject({
1778
+ expect(response.json().shippingInfo.taxRate).toMatchObject({
1796
1779
  name: "NL standard-excluded tax rate",
1797
1780
  amount: 0.21,
1798
1781
  includedInPrice: false,
1799
1782
  country: "NL",
1800
1783
  });
1801
- expect(response.body.shippingInfo.taxedPrice).toMatchObject({
1784
+ expect(response.json().shippingInfo.taxedPrice).toMatchObject({
1802
1785
  totalNet: {
1803
1786
  type: "centPrecision",
1804
1787
  centAmount: 499,
@@ -1834,17 +1817,15 @@ describe("Cart Update Actions", () => {
1834
1817
  });
1835
1818
 
1836
1819
  test("setLineItemShippingDetails", async () => {
1837
- const product = await supertest(ctMock.app)
1838
- .post("/dummy/products")
1839
- .send(productDraft)
1840
- .then((x) => x.body);
1820
+ const product = await productFactory.create(productDraft);
1841
1821
 
1842
1822
  assert(cart, "cart not created");
1843
1823
  assert(product, "product not created");
1844
1824
 
1845
- const updatedCart = await supertest(ctMock.app)
1846
- .post(`/dummy/carts/${cart.id}`)
1847
- .send({
1825
+ const updatedCart = await ctMock.app.inject({
1826
+ method: "POST",
1827
+ url: `/dummy/carts/${cart.id}`,
1828
+ payload: {
1848
1829
  version: 1,
1849
1830
  actions: [
1850
1831
  {
@@ -1853,17 +1834,19 @@ describe("Cart Update Actions", () => {
1853
1834
  variantId: product.masterData.current.variants[0].id,
1854
1835
  },
1855
1836
  ],
1856
- });
1857
- const lineItem = updatedCart.body.lineItems[0];
1837
+ },
1838
+ });
1839
+ const lineItem = updatedCart.json().lineItems[0];
1858
1840
  assert(lineItem, "lineItem not created");
1859
1841
 
1860
- expect(updatedCart.body.version).toBe(2);
1861
- expect(updatedCart.body.lineItems).toHaveLength(1);
1842
+ expect(updatedCart.json().version).toBe(2);
1843
+ expect(updatedCart.json().lineItems).toHaveLength(1);
1862
1844
 
1863
- const response = await supertest(ctMock.app)
1864
- .post(`/dummy/carts/${cart.id}`)
1865
- .send({
1866
- version: updatedCart.body.version,
1845
+ const response = await ctMock.app.inject({
1846
+ method: "POST",
1847
+ url: `/dummy/carts/${cart.id}`,
1848
+ payload: {
1849
+ version: updatedCart.json().version,
1867
1850
  actions: [
1868
1851
  {
1869
1852
  action: "setLineItemShippingDetails",
@@ -1878,40 +1861,39 @@ describe("Cart Update Actions", () => {
1878
1861
  },
1879
1862
  },
1880
1863
  ],
1881
- });
1864
+ },
1865
+ });
1882
1866
 
1883
- expect(response.status).toBe(200);
1884
- expect(response.body.version).toBe(3);
1885
- expect(response.body.lineItems).toHaveLength(1);
1867
+ expect(response.statusCode).toBe(200);
1868
+ expect(response.json().version).toBe(3);
1869
+ expect(response.json().lineItems).toHaveLength(1);
1886
1870
 
1887
- const updatedLineItem = response.body.lineItems[0];
1871
+ const updatedLineItem = response.json().lineItems[0];
1888
1872
  expect(updatedLineItem.shippingDetails).toBeDefined();
1889
1873
  expect(updatedLineItem.shippingDetails.targets).toHaveLength(1);
1890
1874
  });
1891
1875
 
1892
1876
  test("addCustomLineItem", async () => {
1893
1877
  assert(cart, "cart not created");
1894
- const type = await supertest(ctMock.app)
1895
- .post("/dummy/types")
1896
- .send({
1897
- key: "custom-line-item-type",
1898
- name: { en: "Custom Line Item Type" },
1899
- resourceTypeIds: ["custom-line-item"],
1900
- fieldDefinitions: [
1901
- {
1902
- name: "description",
1903
- label: { en: "Description" },
1904
- required: false,
1905
- type: { name: "String" },
1906
- inputHint: "SingleLine",
1907
- },
1908
- ],
1909
- })
1910
- .then((res) => res.body);
1878
+ const type = await typeFactory.create({
1879
+ key: "custom-line-item-type",
1880
+ name: { en: "Custom Line Item Type" },
1881
+ resourceTypeIds: ["custom-line-item"],
1882
+ fieldDefinitions: [
1883
+ {
1884
+ name: "description",
1885
+ label: { en: "Description" },
1886
+ required: false,
1887
+ type: { name: "String" },
1888
+ inputHint: "SingleLine",
1889
+ },
1890
+ ],
1891
+ });
1911
1892
 
1912
- const response = await supertest(ctMock.app)
1913
- .post(`/dummy/carts/${cart.id}`)
1914
- .send({
1893
+ const response = await ctMock.app.inject({
1894
+ method: "POST",
1895
+ url: `/dummy/carts/${cart.id}`,
1896
+ payload: {
1915
1897
  version: 1,
1916
1898
  actions: [
1917
1899
  {
@@ -1933,13 +1915,14 @@ describe("Cart Update Actions", () => {
1933
1915
  },
1934
1916
  },
1935
1917
  ],
1936
- });
1918
+ },
1919
+ });
1937
1920
 
1938
- expect(response.status).toBe(200);
1939
- expect(response.body.version).toBe(2);
1940
- expect(response.body.customLineItems).toHaveLength(1);
1921
+ expect(response.statusCode).toBe(200);
1922
+ expect(response.json().version).toBe(2);
1923
+ expect(response.json().customLineItems).toHaveLength(1);
1941
1924
 
1942
- const customLineItem = response.body.customLineItems[0];
1925
+ const customLineItem = response.json().customLineItems[0];
1943
1926
  expect(customLineItem.name).toEqual({ en: "Custom Service Fee" });
1944
1927
  expect(customLineItem.slug).toBe("service-fee");
1945
1928
  expect(customLineItem.money.centAmount).toBe(1000);
@@ -1959,9 +1942,10 @@ describe("Cart Update Actions", () => {
1959
1942
  test("removeCustomLineItem by ID", async () => {
1960
1943
  assert(cart, "cart not created");
1961
1944
 
1962
- const addResponse = await supertest(ctMock.app)
1963
- .post(`/dummy/carts/${cart.id}`)
1964
- .send({
1945
+ const addResponse = await ctMock.app.inject({
1946
+ method: "POST",
1947
+ url: `/dummy/carts/${cart.id}`,
1948
+ payload: {
1965
1949
  version: 1,
1966
1950
  actions: [
1967
1951
  {
@@ -1975,34 +1959,38 @@ describe("Cart Update Actions", () => {
1975
1959
  quantity: 1,
1976
1960
  },
1977
1961
  ],
1978
- });
1962
+ },
1963
+ });
1979
1964
 
1980
- expect(addResponse.status).toBe(200);
1981
- expect(addResponse.body.customLineItems).toHaveLength(1);
1965
+ expect(addResponse.statusCode).toBe(200);
1966
+ expect(addResponse.json().customLineItems).toHaveLength(1);
1982
1967
 
1983
- const customLineItemId = addResponse.body.customLineItems[0].id;
1984
- const removeResponse = await supertest(ctMock.app)
1985
- .post(`/dummy/carts/${cart.id}`)
1986
- .send({
1987
- version: addResponse.body.version,
1968
+ const customLineItemId = addResponse.json().customLineItems[0].id;
1969
+ const removeResponse = await ctMock.app.inject({
1970
+ method: "POST",
1971
+ url: `/dummy/carts/${cart.id}`,
1972
+ payload: {
1973
+ version: addResponse.json().version,
1988
1974
  actions: [
1989
1975
  {
1990
1976
  action: "removeCustomLineItem",
1991
1977
  customLineItemId,
1992
1978
  },
1993
1979
  ],
1994
- });
1980
+ },
1981
+ });
1995
1982
 
1996
- expect(removeResponse.status).toBe(200);
1997
- expect(removeResponse.body.customLineItems).toHaveLength(0);
1983
+ expect(removeResponse.statusCode).toBe(200);
1984
+ expect(removeResponse.json().customLineItems).toHaveLength(0);
1998
1985
  });
1999
1986
 
2000
1987
  test("removeCustomLineItem by key", async () => {
2001
1988
  assert(cart, "cart not created");
2002
1989
 
2003
- const addResponse = await supertest(ctMock.app)
2004
- .post(`/dummy/carts/${cart.id}`)
2005
- .send({
1990
+ const addResponse = await ctMock.app.inject({
1991
+ method: "POST",
1992
+ url: `/dummy/carts/${cart.id}`,
1993
+ payload: {
2006
1994
  version: 1,
2007
1995
  actions: [
2008
1996
  {
@@ -2017,32 +2005,36 @@ describe("Cart Update Actions", () => {
2017
2005
  quantity: 1,
2018
2006
  },
2019
2007
  ],
2020
- });
2008
+ },
2009
+ });
2021
2010
 
2022
- expect(addResponse.status).toBe(200);
2023
- expect(addResponse.body.customLineItems).toHaveLength(1);
2011
+ expect(addResponse.statusCode).toBe(200);
2012
+ expect(addResponse.json().customLineItems).toHaveLength(1);
2024
2013
 
2025
- const removeResponse = await supertest(ctMock.app)
2026
- .post(`/dummy/carts/${cart.id}`)
2027
- .send({
2028
- version: addResponse.body.version,
2014
+ const removeResponse = await ctMock.app.inject({
2015
+ method: "POST",
2016
+ url: `/dummy/carts/${cart.id}`,
2017
+ payload: {
2018
+ version: addResponse.json().version,
2029
2019
  actions: [
2030
2020
  {
2031
2021
  action: "removeCustomLineItem",
2032
2022
  customLineItemKey: "custom-service-fee",
2033
2023
  },
2034
2024
  ],
2035
- });
2025
+ },
2026
+ });
2036
2027
 
2037
- expect(removeResponse.status).toBe(200);
2038
- expect(removeResponse.body.customLineItems).toHaveLength(0);
2028
+ expect(removeResponse.statusCode).toBe(200);
2029
+ expect(removeResponse.json().customLineItems).toHaveLength(0);
2039
2030
  });
2040
2031
 
2041
2032
  test("changeCustomLineItemQuantity", async () => {
2042
2033
  assert(cart, "cart not created");
2043
- const addResponse = await supertest(ctMock.app)
2044
- .post(`/dummy/carts/${cart.id}`)
2045
- .send({
2034
+ const addResponse = await ctMock.app.inject({
2035
+ method: "POST",
2036
+ url: `/dummy/carts/${cart.id}`,
2037
+ payload: {
2046
2038
  version: 1,
2047
2039
  actions: [
2048
2040
  {
@@ -2056,13 +2048,15 @@ describe("Cart Update Actions", () => {
2056
2048
  quantity: 1,
2057
2049
  },
2058
2050
  ],
2059
- });
2051
+ },
2052
+ });
2060
2053
 
2061
- const customLineItemId = addResponse.body.customLineItems[0].id;
2062
- const changeResponse = await supertest(ctMock.app)
2063
- .post(`/dummy/carts/${cart.id}`)
2064
- .send({
2065
- version: addResponse.body.version,
2054
+ const customLineItemId = addResponse.json().customLineItems[0].id;
2055
+ const changeResponse = await ctMock.app.inject({
2056
+ method: "POST",
2057
+ url: `/dummy/carts/${cart.id}`,
2058
+ payload: {
2059
+ version: addResponse.json().version,
2066
2060
  actions: [
2067
2061
  {
2068
2062
  action: "changeCustomLineItemQuantity",
@@ -2070,21 +2064,23 @@ describe("Cart Update Actions", () => {
2070
2064
  quantity: 3,
2071
2065
  },
2072
2066
  ],
2073
- });
2067
+ },
2068
+ });
2074
2069
 
2075
- expect(changeResponse.status).toBe(200);
2076
- expect(changeResponse.body.customLineItems).toHaveLength(1);
2070
+ expect(changeResponse.statusCode).toBe(200);
2071
+ expect(changeResponse.json().customLineItems).toHaveLength(1);
2077
2072
 
2078
- const customLineItem = changeResponse.body.customLineItems[0];
2073
+ const customLineItem = changeResponse.json().customLineItems[0];
2079
2074
  expect(customLineItem.quantity).toBe(3);
2080
2075
  expect(customLineItem.totalPrice.centAmount).toBe(3000);
2081
2076
  });
2082
2077
 
2083
2078
  test("changeCustomLineItemMoney", async () => {
2084
2079
  assert(cart, "cart not created");
2085
- const addResponse = await supertest(ctMock.app)
2086
- .post(`/dummy/carts/${cart.id}`)
2087
- .send({
2080
+ const addResponse = await ctMock.app.inject({
2081
+ method: "POST",
2082
+ url: `/dummy/carts/${cart.id}`,
2083
+ payload: {
2088
2084
  version: 1,
2089
2085
  actions: [
2090
2086
  {
@@ -2098,13 +2094,15 @@ describe("Cart Update Actions", () => {
2098
2094
  quantity: 2,
2099
2095
  },
2100
2096
  ],
2101
- });
2097
+ },
2098
+ });
2102
2099
 
2103
- const customLineItemId = addResponse.body.customLineItems[0].id;
2104
- const changeResponse = await supertest(ctMock.app)
2105
- .post(`/dummy/carts/${cart.id}`)
2106
- .send({
2107
- version: addResponse.body.version,
2100
+ const customLineItemId = addResponse.json().customLineItems[0].id;
2101
+ const changeResponse = await ctMock.app.inject({
2102
+ method: "POST",
2103
+ url: `/dummy/carts/${cart.id}`,
2104
+ payload: {
2105
+ version: addResponse.json().version,
2108
2106
  actions: [
2109
2107
  {
2110
2108
  action: "changeCustomLineItemMoney",
@@ -2115,12 +2113,13 @@ describe("Cart Update Actions", () => {
2115
2113
  },
2116
2114
  },
2117
2115
  ],
2118
- });
2116
+ },
2117
+ });
2119
2118
 
2120
- expect(changeResponse.status).toBe(200);
2121
- expect(changeResponse.body.customLineItems).toHaveLength(1);
2119
+ expect(changeResponse.statusCode).toBe(200);
2120
+ expect(changeResponse.json().customLineItems).toHaveLength(1);
2122
2121
 
2123
- const customLineItem = changeResponse.body.customLineItems[0];
2122
+ const customLineItem = changeResponse.json().customLineItems[0];
2124
2123
  expect(customLineItem.money.centAmount).toBe(1500);
2125
2124
  expect(customLineItem.totalPrice.centAmount).toBe(3000);
2126
2125
  });
@@ -2128,9 +2127,10 @@ describe("Cart Update Actions", () => {
2128
2127
  test("addCustomLineItem with tax calculation", async () => {
2129
2128
  assert(cart, "cart not created");
2130
2129
 
2131
- const response = await supertest(ctMock.app)
2132
- .post(`/dummy/carts/${cart.id}`)
2133
- .send({
2130
+ const response = await ctMock.app.inject({
2131
+ method: "POST",
2132
+ url: `/dummy/carts/${cart.id}`,
2133
+ payload: {
2134
2134
  version: 1,
2135
2135
  actions: [
2136
2136
  {
@@ -2148,10 +2148,11 @@ describe("Cart Update Actions", () => {
2148
2148
  },
2149
2149
  },
2150
2150
  ],
2151
- });
2151
+ },
2152
+ });
2152
2153
 
2153
- expect(response.status).toBe(200);
2154
- const customLineItem = response.body.customLineItems[0];
2154
+ expect(response.statusCode).toBe(200);
2155
+ const customLineItem = response.json().customLineItems[0];
2155
2156
 
2156
2157
  expect(customLineItem.taxedPrice).toBeDefined();
2157
2158
  expect(customLineItem.taxedPrice.totalNet.centAmount).toBe(1000);