@labdigital/commercetools-mock 2.66.0 → 3.0.0-beta.1

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 +1370 -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
@@ -15,7 +15,7 @@ describe("AttributeGroup Repository", () => {
15
15
  const config: Config = { storage, strict: false };
16
16
  const repository = new AttributeGroupRepository(config);
17
17
 
18
- test("create attribute group", () => {
18
+ test("create attribute group", async () => {
19
19
  const draft: AttributeGroupDraft = {
20
20
  name: { "en-US": "Size Attributes", "de-DE": "Größenattribute" },
21
21
  description: { "en-US": "Attributes related to product size" },
@@ -31,7 +31,7 @@ describe("AttributeGroup Repository", () => {
31
31
  };
32
32
 
33
33
  const ctx = { projectKey: "dummy" };
34
- const result = repository.create(ctx, draft);
34
+ const result = await repository.create(ctx, draft);
35
35
 
36
36
  expect(result.id).toBeDefined();
37
37
  expect(result.version).toBe(1);
@@ -41,19 +41,19 @@ describe("AttributeGroup Repository", () => {
41
41
  expect(result.attributes).toEqual(draft.attributes);
42
42
 
43
43
  // Test that the attribute group is stored
44
- const items = repository.query(ctx);
44
+ const items = await repository.query(ctx);
45
45
  expect(items.count).toBe(1);
46
46
  expect(items.results[0].id).toBe(result.id);
47
47
  });
48
48
 
49
- test("create attribute group with minimal data", () => {
49
+ test("create attribute group with minimal data", async () => {
50
50
  const draft: AttributeGroupDraft = {
51
51
  name: { "en-US": "Minimal Attributes" },
52
52
  attributes: [],
53
53
  };
54
54
 
55
55
  const ctx = { projectKey: "dummy" };
56
- const result = repository.create(ctx, draft);
56
+ const result = await repository.create(ctx, draft);
57
57
 
58
58
  expect(result.id).toBeDefined();
59
59
  expect(result.name).toEqual(draft.name);
@@ -62,7 +62,7 @@ describe("AttributeGroup Repository", () => {
62
62
  expect(result.attributes).toEqual([]);
63
63
  });
64
64
 
65
- test("update attribute group - changeName", () => {
65
+ test("update attribute group - changeName", async () => {
66
66
  const draft: AttributeGroupDraft = {
67
67
  name: { "en-US": "Original Name" },
68
68
  key: "test-attributes",
@@ -70,9 +70,9 @@ describe("AttributeGroup Repository", () => {
70
70
  };
71
71
 
72
72
  const ctx = { projectKey: "dummy" };
73
- const attributeGroup = repository.create(ctx, draft);
73
+ const attributeGroup = await repository.create(ctx, draft);
74
74
 
75
- const result = repository.processUpdateActions(
75
+ const result = await repository.processUpdateActions(
76
76
  ctx,
77
77
  attributeGroup,
78
78
  attributeGroup.version,
@@ -91,7 +91,7 @@ describe("AttributeGroup Repository", () => {
91
91
  expect(result.version).toBe(attributeGroup.version + 1);
92
92
  });
93
93
 
94
- test("update attribute group - setDescription", () => {
94
+ test("update attribute group - setDescription", async () => {
95
95
  const draft: AttributeGroupDraft = {
96
96
  name: { "en-US": "Test Attributes" },
97
97
  key: "test-attributes-2",
@@ -99,9 +99,9 @@ describe("AttributeGroup Repository", () => {
99
99
  };
100
100
 
101
101
  const ctx = { projectKey: "dummy" };
102
- const attributeGroup = repository.create(ctx, draft);
102
+ const attributeGroup = await repository.create(ctx, draft);
103
103
 
104
- const result = repository.processUpdateActions(
104
+ const result = await repository.processUpdateActions(
105
105
  ctx,
106
106
  attributeGroup,
107
107
  attributeGroup.version,
@@ -123,7 +123,7 @@ describe("AttributeGroup Repository", () => {
123
123
  expect(result.version).toBe(attributeGroup.version + 1);
124
124
  });
125
125
 
126
- test("update attribute group - setKey", () => {
126
+ test("update attribute group - setKey", async () => {
127
127
  const draft: AttributeGroupDraft = {
128
128
  name: { "en-US": "Key Test Attributes" },
129
129
  key: "original-key",
@@ -131,9 +131,9 @@ describe("AttributeGroup Repository", () => {
131
131
  };
132
132
 
133
133
  const ctx = { projectKey: "dummy" };
134
- const attributeGroup = repository.create(ctx, draft);
134
+ const attributeGroup = await repository.create(ctx, draft);
135
135
 
136
- const result = repository.processUpdateActions(
136
+ const result = await repository.processUpdateActions(
137
137
  ctx,
138
138
  attributeGroup,
139
139
  attributeGroup.version,
@@ -149,7 +149,7 @@ describe("AttributeGroup Repository", () => {
149
149
  expect(result.version).toBe(attributeGroup.version + 1);
150
150
  });
151
151
 
152
- test("update attribute group - setAttributes", () => {
152
+ test("update attribute group - setAttributes", async () => {
153
153
  const draft: AttributeGroupDraft = {
154
154
  name: { "en-US": "Attributes Test" },
155
155
  key: "attributes-test",
@@ -161,9 +161,9 @@ describe("AttributeGroup Repository", () => {
161
161
  };
162
162
 
163
163
  const ctx = { projectKey: "dummy" };
164
- const attributeGroup = repository.create(ctx, draft);
164
+ const attributeGroup = await repository.create(ctx, draft);
165
165
 
166
- const result = repository.processUpdateActions(
166
+ const result = await repository.processUpdateActions(
167
167
  ctx,
168
168
  attributeGroup,
169
169
  attributeGroup.version,
@@ -189,7 +189,7 @@ describe("AttributeGroup Repository", () => {
189
189
  expect(result.version).toBe(attributeGroup.version + 1);
190
190
  });
191
191
 
192
- test("get and delete attribute group", () => {
192
+ test("get and delete attribute group", async () => {
193
193
  const draft: AttributeGroupDraft = {
194
194
  name: { "en-US": "Delete Test Attributes" },
195
195
  key: "delete-test",
@@ -197,25 +197,25 @@ describe("AttributeGroup Repository", () => {
197
197
  };
198
198
 
199
199
  const ctx = { projectKey: "dummy" };
200
- const attributeGroup = repository.create(ctx, draft);
200
+ const attributeGroup = await repository.create(ctx, draft);
201
201
 
202
202
  // Test get
203
- const retrieved = repository.get(ctx, attributeGroup.id);
203
+ const retrieved = await repository.get(ctx, attributeGroup.id);
204
204
  expect(retrieved).toBeDefined();
205
205
  expect(retrieved?.id).toBe(attributeGroup.id);
206
206
 
207
207
  // Test getByKey
208
- const retrievedByKey = repository.getByKey(ctx, attributeGroup.key!);
208
+ const retrievedByKey = await repository.getByKey(ctx, attributeGroup.key!);
209
209
  expect(retrievedByKey).toBeDefined();
210
210
  expect(retrievedByKey?.key).toBe(attributeGroup.key);
211
211
 
212
212
  // Test delete
213
- const deleted = repository.delete(ctx, attributeGroup.id);
213
+ const deleted = await repository.delete(ctx, attributeGroup.id);
214
214
  expect(deleted).toBeDefined();
215
215
  expect(deleted?.id).toBe(attributeGroup.id);
216
216
 
217
217
  // Verify it's deleted
218
- const notFound = repository.get(ctx, attributeGroup.id);
218
+ const notFound = await repository.get(ctx, attributeGroup.id);
219
219
  expect(notFound).toBeNull();
220
220
  });
221
221
  });
@@ -8,6 +8,7 @@ import type {
8
8
  AttributeGroupUpdateAction,
9
9
  } from "@commercetools/platform-sdk";
10
10
  import type { Config } from "#src/config.ts";
11
+ import { AttributeGroupDraftSchema } from "#src/schemas/generated/attribute-group.ts";
11
12
  import { getBaseResourceProperties } from "../helpers.ts";
12
13
  import type { Writable } from "../types.ts";
13
14
  import type { UpdateHandlerInterface } from "./abstract.ts";
@@ -21,20 +22,21 @@ export class AttributeGroupRepository extends AbstractResourceRepository<"attrib
21
22
  constructor(config: Config) {
22
23
  super("attribute-group", config);
23
24
  this.actions = new AttributeGroupUpdateHandler(this._storage);
25
+ this.draftSchema = AttributeGroupDraftSchema;
24
26
  }
25
27
 
26
- create(
28
+ async create(
27
29
  context: RepositoryContext,
28
30
  draft: AttributeGroupDraft,
29
- ): AttributeGroup {
31
+ ): Promise<AttributeGroup> {
30
32
  const resource: AttributeGroup = {
31
- ...getBaseResourceProperties(),
33
+ ...getBaseResourceProperties(context.clientId),
32
34
  name: draft.name,
33
35
  description: draft.description,
34
36
  key: draft.key,
35
37
  attributes: draft.attributes,
36
38
  };
37
- return this.saveNew(context, resource);
39
+ return await this.saveNew(context, resource);
38
40
  }
39
41
  }
40
42
 
@@ -8,7 +8,7 @@ import type {
8
8
  CompanyDraft,
9
9
  DivisionDraft,
10
10
  } from "@commercetools/platform-sdk";
11
- import { describe, expect, test } from "vitest";
11
+ import { beforeAll, describe, expect, test } from "vitest";
12
12
  import type { Config } from "#src/config.ts";
13
13
  import { getBaseResourceProperties } from "#src/helpers.ts";
14
14
  import { InMemoryStorage } from "#src/storage/index.ts";
@@ -19,33 +19,36 @@ describe("BusinessUnit Repository", () => {
19
19
  const storage = new InMemoryStorage();
20
20
  const config: Config = { storage, strict: false };
21
21
  const repository = new BusinessUnitRepository(config);
22
-
23
- // Add required dependencies for testing
24
- storage.add("dummy", "store", {
25
- ...getBaseResourceProperties(),
26
- id: "store-123",
27
- key: "test-store",
28
- name: { "en-US": "Test Store" },
29
- languages: ["en-US"],
30
- countries: [{ code: "US" }],
31
- distributionChannels: [],
32
- supplyChannels: [],
33
- productSelections: [],
22
+ let customer: Awaited<ReturnType<CustomerRepository["create"]>>;
23
+
24
+ beforeAll(async () => {
25
+ // Add required dependencies for testing
26
+ await storage.add("dummy", "store", {
27
+ ...getBaseResourceProperties(),
28
+ id: "store-123",
29
+ key: "test-store",
30
+ name: { "en-US": "Test Store" },
31
+ languages: ["en-US"],
32
+ countries: [{ code: "US" }],
33
+ distributionChannels: [],
34
+ supplyChannels: [],
35
+ productSelections: [],
36
+ });
37
+
38
+ // Create a proper customer using the customer repository
39
+ const customerRepository = new CustomerRepository(config);
40
+ customer = await customerRepository.create(
41
+ { projectKey: "dummy" },
42
+ {
43
+ email: "associate@example.com",
44
+ password: "password123",
45
+ firstName: "John",
46
+ lastName: "Associate",
47
+ },
48
+ );
34
49
  });
35
50
 
36
- // Create a proper customer using the customer repository
37
- const customerRepository = new CustomerRepository(config);
38
- const customer = customerRepository.create(
39
- { projectKey: "dummy" },
40
- {
41
- email: "associate@example.com",
42
- password: "password123",
43
- firstName: "John",
44
- lastName: "Associate",
45
- },
46
- );
47
-
48
- test("create company business unit", () => {
51
+ test("create company business unit", async () => {
49
52
  const draft: CompanyDraft = {
50
53
  key: "test-company",
51
54
  unitType: "Company",
@@ -94,7 +97,7 @@ describe("BusinessUnit Repository", () => {
94
97
  };
95
98
 
96
99
  const ctx = { projectKey: "dummy" };
97
- const result = repository.create(ctx, draft);
100
+ const result = await repository.create(ctx, draft);
98
101
 
99
102
  expect(result.id).toBeDefined();
100
103
  expect(result.version).toBe(1);
@@ -112,12 +115,12 @@ describe("BusinessUnit Repository", () => {
112
115
  expect(result.associates).toHaveLength(1);
113
116
 
114
117
  // Test that the business unit is stored
115
- const items = repository.query(ctx);
118
+ const items = await repository.query(ctx);
116
119
  expect(items.count).toBe(1);
117
120
  expect(items.results[0].id).toBe(result.id);
118
121
  });
119
122
 
120
- test("create division business unit", () => {
123
+ test("create division business unit", async () => {
121
124
  // First create a company to be the parent
122
125
  const companyDraft: CompanyDraft = {
123
126
  key: "parent-company",
@@ -126,7 +129,10 @@ describe("BusinessUnit Repository", () => {
126
129
  name: "Parent Company",
127
130
  };
128
131
 
129
- const _company = repository.create({ projectKey: "dummy" }, companyDraft);
132
+ const _company = await repository.create(
133
+ { projectKey: "dummy" },
134
+ companyDraft,
135
+ );
130
136
 
131
137
  const draft: DivisionDraft = {
132
138
  key: "test-division",
@@ -141,7 +147,7 @@ describe("BusinessUnit Repository", () => {
141
147
  };
142
148
 
143
149
  const ctx = { projectKey: "dummy" };
144
- const result = repository.create(ctx, draft);
150
+ const result = await repository.create(ctx, draft);
145
151
 
146
152
  expect(result.id).toBeDefined();
147
153
  expect(result.key).toBe(draft.key);
@@ -155,7 +161,7 @@ describe("BusinessUnit Repository", () => {
155
161
  }
156
162
  });
157
163
 
158
- test("create business unit with minimal data", () => {
164
+ test("create business unit with minimal data", async () => {
159
165
  const draft: CompanyDraft = {
160
166
  key: "minimal-company",
161
167
  unitType: "Company",
@@ -163,7 +169,7 @@ describe("BusinessUnit Repository", () => {
163
169
  };
164
170
 
165
171
  const ctx = { projectKey: "dummy" };
166
- const result = repository.create(ctx, draft);
172
+ const result = await repository.create(ctx, draft);
167
173
 
168
174
  expect(result.id).toBeDefined();
169
175
  expect(result.key).toBe(draft.key);
@@ -174,7 +180,7 @@ describe("BusinessUnit Repository", () => {
174
180
  expect(result.stores).toBeUndefined();
175
181
  });
176
182
 
177
- test("update business unit - changeName", () => {
183
+ test("update business unit - changeName", async () => {
178
184
  const draft: CompanyDraft = {
179
185
  key: "update-test-company",
180
186
  unitType: "Company",
@@ -182,9 +188,9 @@ describe("BusinessUnit Repository", () => {
182
188
  };
183
189
 
184
190
  const ctx = { projectKey: "dummy" };
185
- const businessUnit = repository.create(ctx, draft);
191
+ const businessUnit = await repository.create(ctx, draft);
186
192
 
187
- const result = repository.processUpdateActions(
193
+ const result = await repository.processUpdateActions(
188
194
  ctx,
189
195
  businessUnit,
190
196
  businessUnit.version,
@@ -200,7 +206,7 @@ describe("BusinessUnit Repository", () => {
200
206
  expect(result.version).toBe(businessUnit.version + 1);
201
207
  });
202
208
 
203
- test("update business unit - setContactEmail", () => {
209
+ test("update business unit - setContactEmail", async () => {
204
210
  const draft: CompanyDraft = {
205
211
  key: "email-test-company",
206
212
  unitType: "Company",
@@ -208,9 +214,9 @@ describe("BusinessUnit Repository", () => {
208
214
  };
209
215
 
210
216
  const ctx = { projectKey: "dummy" };
211
- const businessUnit = repository.create(ctx, draft);
217
+ const businessUnit = await repository.create(ctx, draft);
212
218
 
213
- const result = repository.processUpdateActions(
219
+ const result = await repository.processUpdateActions(
214
220
  ctx,
215
221
  businessUnit,
216
222
  businessUnit.version,
@@ -226,7 +232,7 @@ describe("BusinessUnit Repository", () => {
226
232
  expect(result.version).toBe(businessUnit.version + 1);
227
233
  });
228
234
 
229
- test("update business unit - changeStatus", () => {
235
+ test("update business unit - changeStatus", async () => {
230
236
  const draft: CompanyDraft = {
231
237
  key: "status-test-company",
232
238
  unitType: "Company",
@@ -235,9 +241,9 @@ describe("BusinessUnit Repository", () => {
235
241
  };
236
242
 
237
243
  const ctx = { projectKey: "dummy" };
238
- const businessUnit = repository.create(ctx, draft);
244
+ const businessUnit = await repository.create(ctx, draft);
239
245
 
240
- const result = repository.processUpdateActions(
246
+ const result = await repository.processUpdateActions(
241
247
  ctx,
242
248
  businessUnit,
243
249
  businessUnit.version,
@@ -253,7 +259,7 @@ describe("BusinessUnit Repository", () => {
253
259
  expect(result.version).toBe(businessUnit.version + 1);
254
260
  });
255
261
 
256
- test("update business unit - setDefaultShippingAddress", () => {
262
+ test("update business unit - setDefaultShippingAddress", async () => {
257
263
  const draft: CompanyDraft = {
258
264
  key: "default-shipping-company",
259
265
  unitType: "Company",
@@ -278,10 +284,10 @@ describe("BusinessUnit Repository", () => {
278
284
  };
279
285
 
280
286
  const ctx = { projectKey: "dummy" };
281
- const businessUnit = repository.create(ctx, draft);
287
+ const businessUnit = await repository.create(ctx, draft);
282
288
  const addressId = businessUnit.addresses[1].id;
283
289
 
284
- const result = repository.processUpdateActions(
290
+ const result = await repository.processUpdateActions(
285
291
  ctx,
286
292
  businessUnit,
287
293
  businessUnit.version,
@@ -297,7 +303,7 @@ describe("BusinessUnit Repository", () => {
297
303
  expect(result.version).toBe(businessUnit.version + 1);
298
304
  });
299
305
 
300
- test("update business unit - addShippingAddressId", () => {
306
+ test("update business unit - addShippingAddressId", async () => {
301
307
  const draft: CompanyDraft = {
302
308
  key: "add-shipping-address-company",
303
309
  unitType: "Company",
@@ -321,10 +327,10 @@ describe("BusinessUnit Repository", () => {
321
327
  };
322
328
 
323
329
  const ctx = { projectKey: "dummy" };
324
- const businessUnit = repository.create(ctx, draft);
330
+ const businessUnit = await repository.create(ctx, draft);
325
331
  const addressId = businessUnit.addresses[1].id;
326
332
 
327
- const result = repository.processUpdateActions(
333
+ const result = await repository.processUpdateActions(
328
334
  ctx,
329
335
  businessUnit,
330
336
  businessUnit.version,
@@ -340,7 +346,7 @@ describe("BusinessUnit Repository", () => {
340
346
  expect(result.version).toBe(businessUnit.version + 1);
341
347
  });
342
348
 
343
- test("update business unit - removeAddress", () => {
349
+ test("update business unit - removeAddress", async () => {
344
350
  const draft: CompanyDraft = {
345
351
  key: "remove-address-company",
346
352
  unitType: "Company",
@@ -368,11 +374,11 @@ describe("BusinessUnit Repository", () => {
368
374
  };
369
375
 
370
376
  const ctx = { projectKey: "dummy" };
371
- const businessUnit = repository.create(ctx, draft);
377
+ const businessUnit = await repository.create(ctx, draft);
372
378
  const addressIdToRemove = businessUnit.addresses[0].id;
373
379
  const remainingAddressId = businessUnit.addresses[1].id;
374
380
 
375
- const result = repository.processUpdateActions(
381
+ const result = await repository.processUpdateActions(
376
382
  ctx,
377
383
  businessUnit,
378
384
  businessUnit.version,
@@ -393,7 +399,7 @@ describe("BusinessUnit Repository", () => {
393
399
  expect(result.version).toBe(businessUnit.version + 1);
394
400
  });
395
401
 
396
- test("get and delete business unit", () => {
402
+ test("get and delete business unit", async () => {
397
403
  const draft: CompanyDraft = {
398
404
  key: "delete-test",
399
405
  unitType: "Company",
@@ -401,25 +407,25 @@ describe("BusinessUnit Repository", () => {
401
407
  };
402
408
 
403
409
  const ctx = { projectKey: "dummy" };
404
- const businessUnit = repository.create(ctx, draft);
410
+ const businessUnit = await repository.create(ctx, draft);
405
411
 
406
412
  // Test get
407
- const retrieved = repository.get(ctx, businessUnit.id);
413
+ const retrieved = await repository.get(ctx, businessUnit.id);
408
414
  expect(retrieved).toBeDefined();
409
415
  expect(retrieved?.id).toBe(businessUnit.id);
410
416
 
411
417
  // Test getByKey
412
- const retrievedByKey = repository.getByKey(ctx, businessUnit.key!);
418
+ const retrievedByKey = await repository.getByKey(ctx, businessUnit.key!);
413
419
  expect(retrievedByKey).toBeDefined();
414
420
  expect(retrievedByKey?.key).toBe(businessUnit.key);
415
421
 
416
422
  // Test delete
417
- const deleted = repository.delete(ctx, businessUnit.id);
423
+ const deleted = await repository.delete(ctx, businessUnit.id);
418
424
  expect(deleted).toBeDefined();
419
425
  expect(deleted?.id).toBe(businessUnit.id);
420
426
 
421
427
  // Verify it's deleted
422
- const notFound = repository.get(ctx, businessUnit.id);
428
+ const notFound = await repository.get(ctx, businessUnit.id);
423
429
  expect(notFound).toBeNull();
424
430
  });
425
431
  });