@labdigital/commercetools-mock 2.65.1 → 3.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/README.md +31 -8
  2. package/dist/abstract-BKFcva6S.mjs +1044 -0
  3. package/dist/abstract-BKFcva6S.mjs.map +1 -0
  4. package/dist/config-BcNSzPZz.d.mts +1718 -0
  5. package/dist/index.d.mts +50 -1633
  6. package/dist/index.mjs +3771 -2654
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/storage/sqlite.d.mts +59 -0
  9. package/dist/storage/sqlite.mjs +234 -0
  10. package/dist/storage/sqlite.mjs.map +1 -0
  11. package/package.json +26 -29
  12. package/src/ctMock.ts +125 -136
  13. package/src/helpers.ts +14 -6
  14. package/src/index.ts +5 -0
  15. package/src/lib/masking.ts +4 -5
  16. package/src/lib/product-review-statistics.test.ts +257 -294
  17. package/src/lib/review-statistics.ts +17 -4
  18. package/src/oauth/helpers.ts +7 -4
  19. package/src/oauth/server.test.ts +102 -62
  20. package/src/oauth/server.ts +215 -213
  21. package/src/oauth/store.ts +20 -6
  22. package/src/orderSearch.ts +3 -3
  23. package/src/product-projection-search.ts +38 -20
  24. package/src/product-search-availability.test.ts +31 -52
  25. package/src/product-search.ts +19 -10
  26. package/src/projectAPI.ts +6 -22
  27. package/src/repositories/abstract.ts +182 -48
  28. package/src/repositories/as-associate.test.ts +19 -19
  29. package/src/repositories/associate-role.ts +12 -23
  30. package/src/repositories/attribute-group.test.ts +23 -23
  31. package/src/repositories/attribute-group.ts +6 -4
  32. package/src/repositories/business-unit.test.ts +63 -57
  33. package/src/repositories/business-unit.ts +107 -55
  34. package/src/repositories/cart/actions.ts +96 -65
  35. package/src/repositories/cart/helpers.ts +15 -11
  36. package/src/repositories/cart/index.test.ts +136 -30
  37. package/src/repositories/cart/index.ts +76 -59
  38. package/src/repositories/cart-discount/actions.ts +12 -44
  39. package/src/repositories/cart-discount/index.ts +20 -8
  40. package/src/repositories/category/actions.ts +27 -27
  41. package/src/repositories/category/index.test.ts +13 -9
  42. package/src/repositories/category/index.ts +40 -23
  43. package/src/repositories/channel.test.ts +53 -51
  44. package/src/repositories/channel.ts +12 -22
  45. package/src/repositories/custom-object.ts +34 -25
  46. package/src/repositories/customer/actions.ts +47 -25
  47. package/src/repositories/customer/index.test.ts +11 -11
  48. package/src/repositories/customer/index.ts +65 -35
  49. package/src/repositories/customer-group.test.ts +44 -42
  50. package/src/repositories/customer-group.ts +12 -22
  51. package/src/repositories/discount-code/actions.ts +3 -19
  52. package/src/repositories/discount-code/index.ts +9 -4
  53. package/src/repositories/discount-group/index.ts +8 -3
  54. package/src/repositories/extension.test.ts +27 -27
  55. package/src/repositories/extension.ts +10 -5
  56. package/src/repositories/helpers.ts +126 -47
  57. package/src/repositories/inventory-entry/actions.ts +3 -24
  58. package/src/repositories/inventory-entry/index.ts +19 -11
  59. package/src/repositories/my-customer.ts +13 -12
  60. package/src/repositories/my-order.ts +5 -2
  61. package/src/repositories/order/actions.ts +89 -56
  62. package/src/repositories/order/index.test.ts +36 -31
  63. package/src/repositories/order/index.ts +83 -49
  64. package/src/repositories/order-edit.ts +8 -3
  65. package/src/repositories/payment/actions.ts +64 -44
  66. package/src/repositories/payment/helpers.ts +3 -3
  67. package/src/repositories/payment/index.ts +28 -12
  68. package/src/repositories/product/actions.ts +133 -98
  69. package/src/repositories/product/helpers.ts +29 -16
  70. package/src/repositories/product/index.ts +42 -25
  71. package/src/repositories/product-discount.ts +6 -4
  72. package/src/repositories/product-projection.ts +41 -21
  73. package/src/repositories/product-selection.ts +8 -15
  74. package/src/repositories/product-tailoring.ts +22 -3
  75. package/src/repositories/product-type.ts +45 -4
  76. package/src/repositories/project.ts +57 -13
  77. package/src/repositories/quote/actions.ts +5 -28
  78. package/src/repositories/quote/index.ts +29 -6
  79. package/src/repositories/quote-request/actions.ts +5 -28
  80. package/src/repositories/quote-request/index.test.ts +3 -3
  81. package/src/repositories/quote-request/index.ts +31 -11
  82. package/src/repositories/quote-staged/actions.ts +5 -28
  83. package/src/repositories/quote-staged/index.ts +22 -8
  84. package/src/repositories/recurrence-policy/index.ts +6 -4
  85. package/src/repositories/recurring-order/actions.ts +7 -32
  86. package/src/repositories/recurring-order/index.ts +8 -6
  87. package/src/repositories/review.test.ts +147 -142
  88. package/src/repositories/review.ts +31 -37
  89. package/src/repositories/shipping-method/actions.ts +11 -28
  90. package/src/repositories/shipping-method/index.ts +26 -15
  91. package/src/repositories/shopping-list/actions.ts +21 -31
  92. package/src/repositories/shopping-list/index.ts +44 -22
  93. package/src/repositories/standalone-price.ts +6 -4
  94. package/src/repositories/state.ts +15 -9
  95. package/src/repositories/store.ts +21 -32
  96. package/src/repositories/subscription.test.ts +22 -22
  97. package/src/repositories/subscription.ts +8 -3
  98. package/src/repositories/tax-category/index.ts +8 -3
  99. package/src/repositories/type/actions.ts +21 -3
  100. package/src/repositories/type/index.ts +5 -3
  101. package/src/repositories/zone.test.ts +112 -77
  102. package/src/repositories/zone.ts +5 -3
  103. package/src/schemas/generated/associate-role.ts +13 -0
  104. package/src/schemas/generated/attribute-group.ts +12 -0
  105. package/src/schemas/generated/business-unit.ts +38 -0
  106. package/src/schemas/generated/cart-discount.ts +33 -0
  107. package/src/schemas/generated/cart.ts +61 -0
  108. package/src/schemas/generated/category.ts +25 -0
  109. package/src/schemas/generated/channel.ts +21 -0
  110. package/src/schemas/generated/common.ts +1372 -0
  111. package/src/schemas/generated/custom-object.ts +11 -0
  112. package/src/schemas/generated/customer-group.ts +11 -0
  113. package/src/schemas/generated/customer.ts +47 -0
  114. package/src/schemas/generated/discount-code.ts +25 -0
  115. package/src/schemas/generated/discount-group.ts +13 -0
  116. package/src/schemas/generated/extension.ts +15 -0
  117. package/src/schemas/generated/index.ts +42 -0
  118. package/src/schemas/generated/inventory-entry.ts +20 -0
  119. package/src/schemas/generated/my-quote-request.ts +10 -0
  120. package/src/schemas/generated/order-edit.ts +18 -0
  121. package/src/schemas/generated/order-from-cart.ts +25 -0
  122. package/src/schemas/generated/payment.ts +30 -0
  123. package/src/schemas/generated/product-discount.ts +20 -0
  124. package/src/schemas/generated/product-selection.ts +18 -0
  125. package/src/schemas/generated/product-tailoring.ts +26 -0
  126. package/src/schemas/generated/product-type.ts +12 -0
  127. package/src/schemas/generated/product.ts +37 -0
  128. package/src/schemas/generated/quote-request.ts +19 -0
  129. package/src/schemas/generated/quote.ts +18 -0
  130. package/src/schemas/generated/recurrence-policy.ts +15 -0
  131. package/src/schemas/generated/recurring-order.ts +19 -0
  132. package/src/schemas/generated/review.ts +24 -0
  133. package/src/schemas/generated/shipping-method.ts +24 -0
  134. package/src/schemas/generated/shopping-list.ts +28 -0
  135. package/src/schemas/generated/staged-quote.ts +18 -0
  136. package/src/schemas/generated/standalone-price.ts +32 -0
  137. package/src/schemas/generated/state.ts +20 -0
  138. package/src/schemas/generated/store.ts +23 -0
  139. package/src/schemas/generated/subscription.ts +20 -0
  140. package/src/schemas/generated/tax-category.ts +12 -0
  141. package/src/schemas/generated/type.ts +17 -0
  142. package/src/schemas/generated/zone.ts +12 -0
  143. package/src/schemas/update-request.ts +3 -5
  144. package/src/server.ts +32 -4
  145. package/src/services/abstract.ts +207 -101
  146. package/src/services/as-associate-cart.test.ts +28 -36
  147. package/src/services/as-associate-cart.ts +15 -12
  148. package/src/services/as-associate-order.test.ts +33 -40
  149. package/src/services/as-associate-order.ts +15 -12
  150. package/src/services/as-associate-quote-request.ts +15 -12
  151. package/src/services/as-associate-shopping-list.test.ts +25 -35
  152. package/src/services/as-associate-shopping-list.ts +15 -12
  153. package/src/services/as-associate.test.ts +21 -15
  154. package/src/services/as-associate.ts +23 -22
  155. package/src/services/associate-roles.test.ts +16 -22
  156. package/src/services/associate-roles.ts +2 -2
  157. package/src/services/attribute-group.test.ts +40 -44
  158. package/src/services/attribute-group.ts +2 -2
  159. package/src/services/business-units.test.ts +227 -163
  160. package/src/services/business-units.ts +2 -2
  161. package/src/services/cart-discount.test.ts +253 -187
  162. package/src/services/cart-discount.ts +2 -2
  163. package/src/services/cart.test.ts +833 -832
  164. package/src/services/cart.ts +31 -12
  165. package/src/services/category.test.ts +208 -130
  166. package/src/services/category.ts +2 -2
  167. package/src/services/channel.test.ts +39 -44
  168. package/src/services/channel.ts +2 -2
  169. package/src/services/custom-object.test.ts +103 -79
  170. package/src/services/custom-object.ts +106 -38
  171. package/src/services/customer-group.test.ts +39 -44
  172. package/src/services/customer-group.ts +2 -2
  173. package/src/services/customer.test.ts +357 -292
  174. package/src/services/customer.ts +70 -23
  175. package/src/services/discount-code.test.ts +57 -68
  176. package/src/services/discount-code.ts +2 -2
  177. package/src/services/discount-group.test.ts +111 -134
  178. package/src/services/discount-group.ts +2 -2
  179. package/src/services/draft-validation.test.ts +255 -0
  180. package/src/services/extension.test.ts +39 -44
  181. package/src/services/extension.ts +2 -2
  182. package/src/services/inventory-entry.test.ts +106 -87
  183. package/src/services/inventory-entry.ts +2 -2
  184. package/src/services/my-business-unit.test.ts +82 -112
  185. package/src/services/my-business-unit.ts +25 -19
  186. package/src/services/my-cart.test.ts +46 -41
  187. package/src/services/my-cart.ts +32 -28
  188. package/src/services/my-customer.test.ts +153 -88
  189. package/src/services/my-customer.ts +130 -61
  190. package/src/services/my-order.ts +15 -12
  191. package/src/services/my-payment.test.ts +30 -24
  192. package/src/services/my-payment.ts +2 -2
  193. package/src/services/my-shopping-list.ts +2 -2
  194. package/src/services/order.test.ts +332 -276
  195. package/src/services/order.ts +45 -27
  196. package/src/services/payment.test.ts +31 -29
  197. package/src/services/payment.ts +2 -2
  198. package/src/services/product-discount.test.ts +39 -46
  199. package/src/services/product-discount.ts +2 -2
  200. package/src/services/product-projection.test.ts +176 -166
  201. package/src/services/product-projection.ts +31 -15
  202. package/src/services/product-selection.test.ts +17 -9
  203. package/src/services/product-selection.ts +2 -2
  204. package/src/services/product-type.test.ts +80 -21
  205. package/src/services/product-type.ts +2 -2
  206. package/src/services/product.test.ts +569 -534
  207. package/src/services/product.ts +14 -7
  208. package/src/services/project.test.ts +22 -12
  209. package/src/services/project.ts +28 -13
  210. package/src/services/quote-request.test.ts +36 -39
  211. package/src/services/quote-request.ts +2 -2
  212. package/src/services/quote-staged.ts +2 -2
  213. package/src/services/quote.ts +2 -2
  214. package/src/services/recurrence-policy.test.ts +114 -139
  215. package/src/services/recurrence-policy.ts +2 -2
  216. package/src/services/recurring-order.test.ts +149 -194
  217. package/src/services/recurring-order.ts +2 -2
  218. package/src/services/reviews.test.ts +127 -106
  219. package/src/services/reviews.ts +2 -2
  220. package/src/services/shipping-method.test.ts +96 -125
  221. package/src/services/shipping-method.ts +24 -12
  222. package/src/services/shopping-list.test.ts +183 -141
  223. package/src/services/shopping-list.ts +2 -2
  224. package/src/services/standalone-price.test.ts +60 -46
  225. package/src/services/standalone-price.ts +2 -2
  226. package/src/services/state.test.ts +20 -25
  227. package/src/services/state.ts +2 -2
  228. package/src/services/store.test.ts +26 -45
  229. package/src/services/store.ts +2 -2
  230. package/src/services/subscription.test.ts +39 -44
  231. package/src/services/subscription.ts +2 -2
  232. package/src/services/tax-category.test.ts +33 -36
  233. package/src/services/tax-category.ts +2 -2
  234. package/src/services/type.test.ts +45 -44
  235. package/src/services/type.ts +2 -2
  236. package/src/services/zone.test.ts +40 -44
  237. package/src/services/zone.ts +2 -2
  238. package/src/shipping.ts +41 -11
  239. package/src/storage/abstract.ts +248 -17
  240. package/src/storage/in-memory.ts +147 -290
  241. package/src/storage/sqlite.ts +429 -0
  242. package/src/storage/storage-map.ts +75 -0
  243. package/src/storage/storage.test-helpers.ts +97 -0
  244. package/src/storage/storage.test.ts +802 -0
  245. package/src/testing/associate-role.ts +28 -0
  246. package/src/testing/attribute-group.ts +27 -0
  247. package/src/testing/business-unit.ts +9 -8
  248. package/src/testing/cart-discount.ts +34 -0
  249. package/src/testing/cart.ts +20 -0
  250. package/src/testing/category.ts +25 -0
  251. package/src/testing/channel.ts +23 -0
  252. package/src/testing/custom-object.ts +27 -0
  253. package/src/testing/customer-group.ts +26 -0
  254. package/src/testing/customer.ts +36 -33
  255. package/src/testing/discount-code.ts +29 -0
  256. package/src/testing/discount-group.ts +27 -0
  257. package/src/testing/extension.ts +32 -0
  258. package/src/testing/index.ts +33 -0
  259. package/src/testing/inventory-entry.ts +26 -0
  260. package/src/testing/order.ts +27 -0
  261. package/src/testing/payment.ts +23 -0
  262. package/src/testing/product-discount.ts +33 -0
  263. package/src/testing/product-selection.ts +28 -0
  264. package/src/testing/product-type.ts +27 -0
  265. package/src/testing/product.ts +38 -0
  266. package/src/testing/quote-request.ts +29 -0
  267. package/src/testing/recurrence-policy.ts +33 -0
  268. package/src/testing/recurring-order.ts +32 -0
  269. package/src/testing/review.ts +24 -0
  270. package/src/testing/shipping-method.ts +31 -0
  271. package/src/testing/shopping-list.ts +25 -0
  272. package/src/testing/standalone-price.ts +31 -0
  273. package/src/testing/state.ts +21 -0
  274. package/src/testing/store.ts +26 -0
  275. package/src/testing/subscription.ts +38 -0
  276. package/src/testing/tax-category.ts +27 -0
  277. package/src/testing/type.ts +9 -6
  278. package/src/testing/zone.ts +22 -0
  279. package/src/validate.test.ts +122 -0
  280. package/src/validate.ts +78 -7
  281. package/src/.env +0 -0
@@ -0,0 +1,28 @@
1
+ import type {
2
+ AssociateRole,
3
+ AssociateRoleDraft,
4
+ } from "@commercetools/platform-sdk";
5
+ import { Factory } from "fishery";
6
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
7
+
8
+ export const associateRoleDraftFactory = (m: CommercetoolsMock) =>
9
+ Factory.define<AssociateRoleDraft, AssociateRoleDraft, AssociateRole>(
10
+ ({ sequence, onCreate }) => {
11
+ onCreate(async (draft) => {
12
+ const response = await m.app.inject({
13
+ method: "POST",
14
+ url: "/dummy/associate-roles",
15
+ payload: draft,
16
+ });
17
+
18
+ return response.json();
19
+ });
20
+
21
+ return {
22
+ key: `associate-role-${sequence}`,
23
+ name: `Associate Role ${sequence}`,
24
+ buyerAssignable: false,
25
+ permissions: ["ViewMyQuotes", "ViewMyOrders", "ViewMyCarts"],
26
+ };
27
+ },
28
+ );
@@ -0,0 +1,27 @@
1
+ import type {
2
+ AttributeGroup,
3
+ AttributeGroupDraft,
4
+ } from "@commercetools/platform-sdk";
5
+ import { Factory } from "fishery";
6
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
7
+
8
+ export const attributeGroupDraftFactory = (m: CommercetoolsMock) =>
9
+ Factory.define<AttributeGroupDraft, AttributeGroupDraft, AttributeGroup>(
10
+ ({ sequence, onCreate }) => {
11
+ onCreate(async (draft) => {
12
+ const response = await m.app.inject({
13
+ method: "POST",
14
+ url: "/dummy/attribute-groups",
15
+ payload: draft,
16
+ });
17
+
18
+ return response.json();
19
+ });
20
+
21
+ return {
22
+ key: `attribute-group-${sequence}`,
23
+ name: { en: `Attribute Group ${sequence}` },
24
+ attributes: [{ key: `attribute-${sequence}` }],
25
+ };
26
+ },
27
+ );
@@ -3,24 +3,25 @@ import type {
3
3
  BusinessUnitDraft,
4
4
  } from "@commercetools/platform-sdk";
5
5
  import { Factory } from "fishery";
6
- import supertest from "supertest";
7
6
  import type { CommercetoolsMock } from "#src/ctMock.ts";
8
7
 
9
8
  export const businessUnitDraftFactory = (m: CommercetoolsMock) =>
10
9
  Factory.define<BusinessUnitDraft, BusinessUnitDraft, BusinessUnit>(
11
- ({ onCreate }) => {
10
+ ({ sequence, onCreate }) => {
12
11
  onCreate(async (draft) => {
13
- const response = await supertest(m.app)
14
- .post("/dummy/business-units")
15
- .send(draft);
12
+ const response = await m.app.inject({
13
+ method: "POST",
14
+ url: "/dummy/business-units",
15
+ payload: draft,
16
+ });
16
17
 
17
- return response.body;
18
+ return response.json();
18
19
  });
19
20
 
20
21
  return {
21
- key: "test-business-unit",
22
+ key: `business-unit-${sequence}`,
22
23
  unitType: "Company",
23
- name: "Test Business Unit",
24
+ name: `Test Business Unit ${sequence}`,
24
25
  status: "Active",
25
26
  contactEmail: "contact@businessunit.com",
26
27
  storeMode: "Explicit",
@@ -0,0 +1,34 @@
1
+ import type {
2
+ CartDiscount,
3
+ CartDiscountDraft,
4
+ } from "@commercetools/platform-sdk";
5
+ import { Factory } from "fishery";
6
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
7
+
8
+ export const cartDiscountDraftFactory = (m: CommercetoolsMock) =>
9
+ Factory.define<CartDiscountDraft, CartDiscountDraft, CartDiscount>(
10
+ ({ sequence, onCreate }) => {
11
+ onCreate(async (draft) => {
12
+ const response = await m.app.inject({
13
+ method: "POST",
14
+ url: "/dummy/cart-discounts",
15
+ payload: draft,
16
+ });
17
+
18
+ return response.json();
19
+ });
20
+
21
+ return {
22
+ key: `cart-discount-${sequence}`,
23
+ name: { en: `Cart Discount ${sequence}` },
24
+ value: {
25
+ type: "relative",
26
+ permyriad: 1000,
27
+ },
28
+ sortOrder: `0.${sequence}`,
29
+ cartPredicate: "1=1",
30
+ isActive: false,
31
+ requiresDiscountCode: false,
32
+ };
33
+ },
34
+ );
@@ -0,0 +1,20 @@
1
+ import type { Cart, CartDraft } from "@commercetools/platform-sdk";
2
+ import { Factory } from "fishery";
3
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
4
+
5
+ export const cartDraftFactory = (m: CommercetoolsMock) =>
6
+ Factory.define<CartDraft, CartDraft, Cart>(({ onCreate }) => {
7
+ onCreate(async (draft) => {
8
+ const response = await m.app.inject({
9
+ method: "POST",
10
+ url: "/dummy/carts",
11
+ payload: draft,
12
+ });
13
+
14
+ return response.json();
15
+ });
16
+
17
+ return {
18
+ currency: "EUR",
19
+ };
20
+ });
@@ -0,0 +1,25 @@
1
+ import type { Category, CategoryDraft } from "@commercetools/platform-sdk";
2
+ import { Factory } from "fishery";
3
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
4
+
5
+ export const categoryDraftFactory = (m: CommercetoolsMock) =>
6
+ Factory.define<CategoryDraft, CategoryDraft, Category>(
7
+ ({ sequence, onCreate }) => {
8
+ onCreate(async (draft) => {
9
+ const response = await m.app.inject({
10
+ method: "POST",
11
+ url: "/dummy/categories",
12
+ payload: draft,
13
+ });
14
+
15
+ return response.json();
16
+ });
17
+
18
+ return {
19
+ key: `category-${sequence}`,
20
+ name: { en: `Category ${sequence}` },
21
+ slug: { en: `category-${sequence}` },
22
+ orderHint: "0.1",
23
+ };
24
+ },
25
+ );
@@ -0,0 +1,23 @@
1
+ import type { Channel, ChannelDraft } from "@commercetools/platform-sdk";
2
+ import { Factory } from "fishery";
3
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
4
+
5
+ export const channelDraftFactory = (m: CommercetoolsMock) =>
6
+ Factory.define<ChannelDraft, ChannelDraft, Channel>(
7
+ ({ sequence, onCreate }) => {
8
+ onCreate(async (draft) => {
9
+ const response = await m.app.inject({
10
+ method: "POST",
11
+ url: "/dummy/channels",
12
+ payload: draft,
13
+ });
14
+
15
+ return response.json();
16
+ });
17
+
18
+ return {
19
+ key: `channel-${sequence}`,
20
+ roles: ["InventorySupply"],
21
+ };
22
+ },
23
+ );
@@ -0,0 +1,27 @@
1
+ import type {
2
+ CustomObject,
3
+ CustomObjectDraft,
4
+ } from "@commercetools/platform-sdk";
5
+ import { Factory } from "fishery";
6
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
7
+
8
+ export const customObjectDraftFactory = (m: CommercetoolsMock) =>
9
+ Factory.define<CustomObjectDraft, CustomObjectDraft, CustomObject>(
10
+ ({ sequence, onCreate }) => {
11
+ onCreate(async (draft) => {
12
+ const response = await m.app.inject({
13
+ method: "POST",
14
+ url: "/dummy/custom-objects",
15
+ payload: draft,
16
+ });
17
+
18
+ return response.json();
19
+ });
20
+
21
+ return {
22
+ container: `container-${sequence}`,
23
+ key: `key-${sequence}`,
24
+ value: `value-${sequence}`,
25
+ };
26
+ },
27
+ );
@@ -0,0 +1,26 @@
1
+ import type {
2
+ CustomerGroup,
3
+ CustomerGroupDraft,
4
+ } from "@commercetools/platform-sdk";
5
+ import { Factory } from "fishery";
6
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
7
+
8
+ export const customerGroupDraftFactory = (m: CommercetoolsMock) =>
9
+ Factory.define<CustomerGroupDraft, CustomerGroupDraft, CustomerGroup>(
10
+ ({ sequence, onCreate }) => {
11
+ onCreate(async (draft) => {
12
+ const response = await m.app.inject({
13
+ method: "POST",
14
+ url: "/dummy/customer-groups",
15
+ payload: draft,
16
+ });
17
+
18
+ return response.json();
19
+ });
20
+
21
+ return {
22
+ key: `customer-group-${sequence}`,
23
+ groupName: `Customer Group ${sequence}`,
24
+ };
25
+ },
26
+ );
@@ -1,40 +1,43 @@
1
1
  import type { Customer, CustomerDraft } from "@commercetools/platform-sdk";
2
2
  import { Factory } from "fishery";
3
- import supertest from "supertest";
4
3
  import type { CommercetoolsMock } from "#src/ctMock.ts";
5
4
 
6
5
  export const customerDraftFactory = (m: CommercetoolsMock) =>
7
- Factory.define<CustomerDraft, CustomerDraft, Customer>(({ onCreate }) => {
8
- onCreate(async (draft) => {
9
- const response = await supertest(m.app)
10
- .post("/dummy/customers")
11
- .send(draft);
6
+ Factory.define<CustomerDraft, CustomerDraft, Customer>(
7
+ ({ sequence, onCreate }) => {
8
+ onCreate(async (draft) => {
9
+ const response = await m.app.inject({
10
+ method: "POST",
11
+ url: "/dummy/customers",
12
+ payload: draft,
13
+ });
12
14
 
13
- return response.body.customer;
14
- });
15
+ return response.json().customer;
16
+ });
15
17
 
16
- return {
17
- email: "customer@example.com",
18
- firstName: "John",
19
- lastName: "Doe",
20
- locale: "nl-NL",
21
- password: "my-secret-pw",
22
- addresses: [
23
- {
24
- firstName: "John",
25
- lastName: "Doe",
26
- streetName: "Street name",
27
- streetNumber: "42",
28
- postalCode: "1234 AB",
29
- city: "Utrecht",
30
- country: "NL",
31
- company: "Lab Digital",
32
- phone: "+31612345678",
33
- email: "customer@example.com",
34
- },
35
- ],
36
- isEmailVerified: false,
37
- stores: [],
38
- authenticationMode: "Password",
39
- };
40
- });
18
+ return {
19
+ email: `customer-${sequence}@example.com`,
20
+ firstName: "John",
21
+ lastName: "Doe",
22
+ locale: "nl-NL",
23
+ password: "my-secret-pw",
24
+ addresses: [
25
+ {
26
+ firstName: "John",
27
+ lastName: "Doe",
28
+ streetName: "Street name",
29
+ streetNumber: "42",
30
+ postalCode: "1234 AB",
31
+ city: "Utrecht",
32
+ country: "NL",
33
+ company: "Lab Digital",
34
+ phone: "+31612345678",
35
+ email: "customer@example.com",
36
+ },
37
+ ],
38
+ isEmailVerified: false,
39
+ stores: [],
40
+ authenticationMode: "Password",
41
+ };
42
+ },
43
+ );
@@ -0,0 +1,29 @@
1
+ import type {
2
+ DiscountCode,
3
+ DiscountCodeDraft,
4
+ } from "@commercetools/platform-sdk";
5
+ import { Factory } from "fishery";
6
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
7
+
8
+ export const discountCodeDraftFactory = (m: CommercetoolsMock) =>
9
+ Factory.define<DiscountCodeDraft, DiscountCodeDraft, DiscountCode>(
10
+ ({ sequence, onCreate }) => {
11
+ onCreate(async (draft) => {
12
+ const response = await m.app.inject({
13
+ method: "POST",
14
+ url: "/dummy/discount-codes",
15
+ payload: draft,
16
+ });
17
+
18
+ return response.json();
19
+ });
20
+
21
+ return {
22
+ key: `discount-code-${sequence}`,
23
+ code: `SAVE${sequence}`,
24
+ name: { en: `Discount Code ${sequence}` },
25
+ cartDiscounts: [],
26
+ isActive: true,
27
+ };
28
+ },
29
+ );
@@ -0,0 +1,27 @@
1
+ import type {
2
+ DiscountGroup,
3
+ DiscountGroupDraft,
4
+ } from "@commercetools/platform-sdk";
5
+ import { Factory } from "fishery";
6
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
7
+
8
+ export const discountGroupDraftFactory = (m: CommercetoolsMock) =>
9
+ Factory.define<DiscountGroupDraft, DiscountGroupDraft, DiscountGroup>(
10
+ ({ sequence, onCreate }) => {
11
+ onCreate(async (draft) => {
12
+ const response = await m.app.inject({
13
+ method: "POST",
14
+ url: "/dummy/discount-groups",
15
+ payload: draft,
16
+ });
17
+
18
+ return response.json();
19
+ });
20
+
21
+ return {
22
+ key: `discount-group-${sequence}`,
23
+ name: { en: `Discount Group ${sequence}` },
24
+ sortOrder: `0.${sequence}`,
25
+ };
26
+ },
27
+ );
@@ -0,0 +1,32 @@
1
+ import type { Extension, ExtensionDraft } from "@commercetools/platform-sdk";
2
+ import { Factory } from "fishery";
3
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
4
+
5
+ export const extensionDraftFactory = (m: CommercetoolsMock) =>
6
+ Factory.define<ExtensionDraft, ExtensionDraft, Extension>(
7
+ ({ sequence, onCreate }) => {
8
+ onCreate(async (draft) => {
9
+ const response = await m.app.inject({
10
+ method: "POST",
11
+ url: "/dummy/extensions",
12
+ payload: draft,
13
+ });
14
+
15
+ return response.json();
16
+ });
17
+
18
+ return {
19
+ key: `extension-${sequence}`,
20
+ destination: {
21
+ type: "HTTP",
22
+ url: `https://example.com/webhook-${sequence}`,
23
+ },
24
+ triggers: [
25
+ {
26
+ resourceTypeId: "order",
27
+ actions: ["Create"],
28
+ },
29
+ ],
30
+ };
31
+ },
32
+ );
@@ -0,0 +1,33 @@
1
+ export { associateRoleDraftFactory } from "./associate-role.ts";
2
+ export { attributeGroupDraftFactory } from "./attribute-group.ts";
3
+ export { businessUnitDraftFactory } from "./business-unit.ts";
4
+ export { cartDraftFactory } from "./cart.ts";
5
+ export { cartDiscountDraftFactory } from "./cart-discount.ts";
6
+ export { categoryDraftFactory } from "./category.ts";
7
+ export { channelDraftFactory } from "./channel.ts";
8
+ export { customObjectDraftFactory } from "./custom-object.ts";
9
+ export { customerDraftFactory } from "./customer.ts";
10
+ export { customerGroupDraftFactory } from "./customer-group.ts";
11
+ export { discountCodeDraftFactory } from "./discount-code.ts";
12
+ export { discountGroupDraftFactory } from "./discount-group.ts";
13
+ export { extensionDraftFactory } from "./extension.ts";
14
+ export { inventoryEntryDraftFactory } from "./inventory-entry.ts";
15
+ export { orderDraftFactory } from "./order.ts";
16
+ export { paymentDraftFactory } from "./payment.ts";
17
+ export { productDraftFactory } from "./product.ts";
18
+ export { productDiscountDraftFactory } from "./product-discount.ts";
19
+ export { productSelectionDraftFactory } from "./product-selection.ts";
20
+ export { productTypeDraftFactory } from "./product-type.ts";
21
+ export { quoteRequestDraftFactory } from "./quote-request.ts";
22
+ export { recurrencePolicyDraftFactory } from "./recurrence-policy.ts";
23
+ export { recurringOrderDraftFactory } from "./recurring-order.ts";
24
+ export { reviewDraftFactory } from "./review.ts";
25
+ export { shippingMethodDraftFactory } from "./shipping-method.ts";
26
+ export { shoppingListDraftFactory } from "./shopping-list.ts";
27
+ export { standalonePriceDraftFactory } from "./standalone-price.ts";
28
+ export { stateDraftFactory } from "./state.ts";
29
+ export { storeDraftFactory } from "./store.ts";
30
+ export { subscriptionDraftFactory } from "./subscription.ts";
31
+ export { taxCategoryDraftFactory } from "./tax-category.ts";
32
+ export { typeDraftFactory } from "./type.ts";
33
+ export { zoneDraftFactory } from "./zone.ts";
@@ -0,0 +1,26 @@
1
+ import type {
2
+ InventoryEntry,
3
+ InventoryEntryDraft,
4
+ } from "@commercetools/platform-sdk";
5
+ import { Factory } from "fishery";
6
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
7
+
8
+ export const inventoryEntryDraftFactory = (m: CommercetoolsMock) =>
9
+ Factory.define<InventoryEntryDraft, InventoryEntryDraft, InventoryEntry>(
10
+ ({ sequence, onCreate }) => {
11
+ onCreate(async (draft) => {
12
+ const response = await m.app.inject({
13
+ method: "POST",
14
+ url: "/dummy/inventory",
15
+ payload: draft,
16
+ });
17
+
18
+ return response.json();
19
+ });
20
+
21
+ return {
22
+ sku: `sku-${sequence}`,
23
+ quantityOnStock: 100,
24
+ };
25
+ },
26
+ );
@@ -0,0 +1,27 @@
1
+ import type { Order, OrderFromCartDraft } from "@commercetools/platform-sdk";
2
+ import { Factory } from "fishery";
3
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
4
+
5
+ export const orderDraftFactory = (m: CommercetoolsMock) =>
6
+ Factory.define<OrderFromCartDraft, OrderFromCartDraft, Order>(
7
+ ({ sequence, onCreate }) => {
8
+ onCreate(async (draft) => {
9
+ const response = await m.app.inject({
10
+ method: "POST",
11
+ url: "/dummy/orders",
12
+ payload: draft,
13
+ });
14
+
15
+ return response.json();
16
+ });
17
+
18
+ return {
19
+ cart: {
20
+ typeId: "cart" as const,
21
+ id: "cart-id-placeholder",
22
+ },
23
+ version: 1,
24
+ orderNumber: `order-${sequence}`,
25
+ };
26
+ },
27
+ );
@@ -0,0 +1,23 @@
1
+ import type { Payment, PaymentDraft } from "@commercetools/platform-sdk";
2
+ import { Factory } from "fishery";
3
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
4
+
5
+ export const paymentDraftFactory = (m: CommercetoolsMock) =>
6
+ Factory.define<PaymentDraft, PaymentDraft, Payment>(({ onCreate }) => {
7
+ onCreate(async (draft) => {
8
+ const response = await m.app.inject({
9
+ method: "POST",
10
+ url: "/dummy/payments",
11
+ payload: draft,
12
+ });
13
+
14
+ return response.json();
15
+ });
16
+
17
+ return {
18
+ amountPlanned: {
19
+ currencyCode: "EUR",
20
+ centAmount: 1000,
21
+ },
22
+ };
23
+ });
@@ -0,0 +1,33 @@
1
+ import type {
2
+ ProductDiscount,
3
+ ProductDiscountDraft,
4
+ } from "@commercetools/platform-sdk";
5
+ import { Factory } from "fishery";
6
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
7
+
8
+ export const productDiscountDraftFactory = (m: CommercetoolsMock) =>
9
+ Factory.define<ProductDiscountDraft, ProductDiscountDraft, ProductDiscount>(
10
+ ({ sequence, onCreate }) => {
11
+ onCreate(async (draft) => {
12
+ const response = await m.app.inject({
13
+ method: "POST",
14
+ url: "/dummy/product-discounts",
15
+ payload: draft,
16
+ });
17
+
18
+ return response.json();
19
+ });
20
+
21
+ return {
22
+ key: `product-discount-${sequence}`,
23
+ name: { en: `Product Discount ${sequence}` },
24
+ value: {
25
+ type: "relative",
26
+ permyriad: 2000,
27
+ },
28
+ predicate: "1=1",
29
+ sortOrder: `0.${sequence}`,
30
+ isActive: true,
31
+ };
32
+ },
33
+ );
@@ -0,0 +1,28 @@
1
+ import type {
2
+ ProductSelection,
3
+ ProductSelectionDraft,
4
+ } from "@commercetools/platform-sdk";
5
+ import { Factory } from "fishery";
6
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
7
+
8
+ export const productSelectionDraftFactory = (m: CommercetoolsMock) =>
9
+ Factory.define<
10
+ ProductSelectionDraft,
11
+ ProductSelectionDraft,
12
+ ProductSelection
13
+ >(({ sequence, onCreate }) => {
14
+ onCreate(async (draft) => {
15
+ const response = await m.app.inject({
16
+ method: "POST",
17
+ url: "/dummy/product-selections",
18
+ payload: draft,
19
+ });
20
+
21
+ return response.json();
22
+ });
23
+
24
+ return {
25
+ key: `product-selection-${sequence}`,
26
+ name: { en: `Product Selection ${sequence}` },
27
+ };
28
+ });
@@ -0,0 +1,27 @@
1
+ import type {
2
+ ProductType,
3
+ ProductTypeDraft,
4
+ } from "@commercetools/platform-sdk";
5
+ import { Factory } from "fishery";
6
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
7
+
8
+ export const productTypeDraftFactory = (m: CommercetoolsMock) =>
9
+ Factory.define<ProductTypeDraft, ProductTypeDraft, ProductType>(
10
+ ({ sequence, onCreate }) => {
11
+ onCreate(async (draft) => {
12
+ const response = await m.app.inject({
13
+ method: "POST",
14
+ url: "/dummy/product-types",
15
+ payload: draft,
16
+ });
17
+
18
+ return response.json();
19
+ });
20
+
21
+ return {
22
+ key: `product-type-${sequence}`,
23
+ name: `Product Type ${sequence}`,
24
+ description: `Product Type ${sequence} description`,
25
+ };
26
+ },
27
+ );
@@ -0,0 +1,38 @@
1
+ import type { Product, ProductDraft } from "@commercetools/platform-sdk";
2
+ import { Factory } from "fishery";
3
+ import type { CommercetoolsMock } from "#src/ctMock.ts";
4
+
5
+ export const productDraftFactory = (m: CommercetoolsMock) =>
6
+ Factory.define<ProductDraft, ProductDraft, Product>(
7
+ ({ sequence, onCreate }) => {
8
+ onCreate(async (draft) => {
9
+ const response = await m.app.inject({
10
+ method: "POST",
11
+ url: "/dummy/products",
12
+ payload: draft,
13
+ });
14
+
15
+ return response.json();
16
+ });
17
+
18
+ return {
19
+ productType: {
20
+ typeId: "product-type",
21
+ key: `product-type-${sequence}`,
22
+ },
23
+ name: { en: `Product ${sequence}` },
24
+ slug: { en: `product-${sequence}` },
25
+ masterVariant: {
26
+ sku: `sku-${sequence}`,
27
+ prices: [
28
+ {
29
+ value: {
30
+ currencyCode: "EUR",
31
+ centAmount: 1000,
32
+ },
33
+ },
34
+ ],
35
+ },
36
+ };
37
+ },
38
+ );