@labdigital/commercetools-mock 2.43.3 → 2.44.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.
- package/dist/index.cjs +6 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/cart/actions.ts +2 -0
- package/src/repositories/shopping-list/actions.ts +2 -0
- package/src/services/cart.test.ts +60 -0
- package/src/services/shopping-list.test.ts +24 -0
package/package.json
CHANGED
|
@@ -92,6 +92,7 @@ export class CartUpdateHandler
|
|
|
92
92
|
custom,
|
|
93
93
|
quantity = 1,
|
|
94
94
|
addedAt,
|
|
95
|
+
key,
|
|
95
96
|
}: CartAddLineItemAction,
|
|
96
97
|
) {
|
|
97
98
|
let product: Product | null = null;
|
|
@@ -176,6 +177,7 @@ export class CartUpdateHandler
|
|
|
176
177
|
}
|
|
177
178
|
resource.lineItems.push({
|
|
178
179
|
id: uuidv4(),
|
|
180
|
+
key,
|
|
179
181
|
addedAt: addedAt ? addedAt : new Date().toISOString(),
|
|
180
182
|
productId: product.id,
|
|
181
183
|
productKey: product.key,
|
|
@@ -39,6 +39,7 @@ export class ShoppingListUpdateHandler
|
|
|
39
39
|
sku,
|
|
40
40
|
quantity = 1,
|
|
41
41
|
addedAt,
|
|
42
|
+
key,
|
|
42
43
|
}: ShoppingListAddLineItemAction,
|
|
43
44
|
) {
|
|
44
45
|
let product: Product | null = null;
|
|
@@ -95,6 +96,7 @@ export class ShoppingListUpdateHandler
|
|
|
95
96
|
resource.lineItems.push({
|
|
96
97
|
addedAt: addedAt ? addedAt : new Date().toISOString(),
|
|
97
98
|
id: uuidv4(),
|
|
99
|
+
key,
|
|
98
100
|
productId: product.id,
|
|
99
101
|
productSlug: product.masterData.current.slug,
|
|
100
102
|
productType: product.productType,
|
|
@@ -361,6 +361,66 @@ describe("Cart Update Actions", () => {
|
|
|
361
361
|
});
|
|
362
362
|
});
|
|
363
363
|
|
|
364
|
+
test("addLineItem with key", async () => {
|
|
365
|
+
const product = await supertest(ctMock.app)
|
|
366
|
+
.post(`/dummy/products`)
|
|
367
|
+
.send(productDraft)
|
|
368
|
+
.then((x) => x.body);
|
|
369
|
+
|
|
370
|
+
const type = await supertest(ctMock.app)
|
|
371
|
+
.post(`/dummy/types`)
|
|
372
|
+
.send({
|
|
373
|
+
key: "my-type",
|
|
374
|
+
name: {
|
|
375
|
+
en: "My Type",
|
|
376
|
+
},
|
|
377
|
+
description: {
|
|
378
|
+
en: "My Type Description",
|
|
379
|
+
},
|
|
380
|
+
fieldDefinitions: [
|
|
381
|
+
{
|
|
382
|
+
name: "foo",
|
|
383
|
+
label: {
|
|
384
|
+
en: "foo",
|
|
385
|
+
},
|
|
386
|
+
required: false,
|
|
387
|
+
type: {
|
|
388
|
+
name: "String",
|
|
389
|
+
},
|
|
390
|
+
inputHint: "SingleLine",
|
|
391
|
+
},
|
|
392
|
+
],
|
|
393
|
+
})
|
|
394
|
+
.then((x) => x.body);
|
|
395
|
+
|
|
396
|
+
assert(type, "type not created");
|
|
397
|
+
assert(cart, "cart not created");
|
|
398
|
+
assert(product, "product not created");
|
|
399
|
+
|
|
400
|
+
const response = await supertest(ctMock.app)
|
|
401
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
402
|
+
.send({
|
|
403
|
+
version: 1,
|
|
404
|
+
actions: [
|
|
405
|
+
{
|
|
406
|
+
action: "addLineItem",
|
|
407
|
+
sku: "1337",
|
|
408
|
+
key: "my-key",
|
|
409
|
+
quantity: 2,
|
|
410
|
+
custom: {
|
|
411
|
+
type: { typeId: "type", key: "my-type" },
|
|
412
|
+
fields: { foo: "bar" },
|
|
413
|
+
},
|
|
414
|
+
},
|
|
415
|
+
],
|
|
416
|
+
});
|
|
417
|
+
expect(response.status).toBe(200);
|
|
418
|
+
expect(response.body.version).toBe(2);
|
|
419
|
+
expect(response.body.lineItems).toHaveLength(1);
|
|
420
|
+
expect(response.body.lineItems[0].key).toBeDefined();
|
|
421
|
+
expect(response.body.lineItems[0].key).toBe("my-key");
|
|
422
|
+
});
|
|
423
|
+
|
|
364
424
|
test("addLineItem unknown product", async () => {
|
|
365
425
|
assert(cart, "cart not created");
|
|
366
426
|
|
|
@@ -234,6 +234,30 @@ describe("Shopping List Update Actions", () => {
|
|
|
234
234
|
expect(response.body.message).toBe("A product with ID '123' not found.");
|
|
235
235
|
});
|
|
236
236
|
|
|
237
|
+
test("addLineItem by productID", async () => {
|
|
238
|
+
ctMock.clear();
|
|
239
|
+
ctMock.project().add("product", product);
|
|
240
|
+
ctMock.project().add("shopping-list", { ...shoppingList, lineItems: [] });
|
|
241
|
+
|
|
242
|
+
const response = await supertest(ctMock.app)
|
|
243
|
+
.post(`/dummy/shopping-lists/${shoppingList.id}`)
|
|
244
|
+
.send({
|
|
245
|
+
version: 1,
|
|
246
|
+
actions: [
|
|
247
|
+
{
|
|
248
|
+
action: "addLineItem",
|
|
249
|
+
productId: product.id,
|
|
250
|
+
key: "my-key",
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
});
|
|
254
|
+
expect(response.status).toBe(200);
|
|
255
|
+
expect(response.body.version).toBe(2);
|
|
256
|
+
expect(response.body.lineItems).toHaveLength(1);
|
|
257
|
+
expect(response.body.lineItems[0].key).toBeDefined();
|
|
258
|
+
expect(response.body.lineItems[0].key).toEqual("my-key");
|
|
259
|
+
});
|
|
260
|
+
|
|
237
261
|
test("removeLineItem", async () => {
|
|
238
262
|
const response = await supertest(ctMock.app)
|
|
239
263
|
.post(`/dummy/shopping-lists/${shoppingList.id}`)
|