@labdigital/commercetools-mock 2.31.0 → 2.31.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labdigital/commercetools-mock",
3
- "version": "2.31.0",
3
+ "version": "2.31.1",
4
4
  "license": "MIT",
5
5
  "author": "Michael van Tellingen",
6
6
  "type": "module",
@@ -73,7 +73,7 @@ export class CartUpdateHandler
73
73
  addLineItem(
74
74
  context: RepositoryContext,
75
75
  resource: Writable<Cart>,
76
- { productId, variantId, sku, quantity = 1 }: CartAddLineItemAction,
76
+ { productId, variantId, sku, custom, quantity = 1 }: CartAddLineItemAction,
77
77
  ) {
78
78
  let product: Product | null = null;
79
79
 
@@ -176,6 +176,7 @@ export class CartUpdateHandler
176
176
  lineItemMode: "Standard",
177
177
  priceMode: "Platform",
178
178
  state: [],
179
+ custom: createCustomFields(custom, context.projectKey, this._storage),
179
180
  });
180
181
  }
181
182
 
@@ -259,6 +259,67 @@ describe("Cart Update Actions", () => {
259
259
  expect(response.body.totalPrice.centAmount).toEqual(total);
260
260
  });
261
261
 
262
+ test("addLineItem with custom field", async () => {
263
+ const product = await supertest(ctMock.app)
264
+ .post(`/dummy/products`)
265
+ .send(productDraft)
266
+ .then((x) => x.body);
267
+
268
+ const type = await supertest(ctMock.app)
269
+ .post(`/dummy/types`)
270
+ .send({
271
+ key: "my-type",
272
+ name: {
273
+ en: "My Type",
274
+ },
275
+ description: {
276
+ en: "My Type Description",
277
+ },
278
+ fieldDefinitions: [
279
+ {
280
+ name: "foo",
281
+ label: {
282
+ en: "foo",
283
+ },
284
+ required: false,
285
+ type: {
286
+ name: "String",
287
+ },
288
+ inputHint: "SingleLine",
289
+ },
290
+ ],
291
+ })
292
+ .then((x) => x.body);
293
+
294
+ assert(type, "type not created");
295
+ assert(cart, "cart not created");
296
+ assert(product, "product not created");
297
+
298
+ const response = await supertest(ctMock.app)
299
+ .post(`/dummy/carts/${cart.id}`)
300
+ .send({
301
+ version: 1,
302
+ actions: [
303
+ {
304
+ action: "addLineItem",
305
+ sku: "1337",
306
+ quantity: 2,
307
+ custom: {
308
+ type: { typeId: "type", key: "my-type" },
309
+ fields: { foo: "bar" },
310
+ },
311
+ },
312
+ ],
313
+ });
314
+ expect(response.status).toBe(200);
315
+ expect(response.body.version).toBe(2);
316
+ expect(response.body.lineItems).toHaveLength(1);
317
+ expect(response.body.lineItems[0].custom).toEqual({
318
+ type: { typeId: "type", id: expect.any(String) },
319
+ fields: { foo: "bar" },
320
+ });
321
+ });
322
+
262
323
  test("addLineItem unknown product", async () => {
263
324
  assert(cart, "cart not created");
264
325