@labdigital/commercetools-mock 2.31.0 → 2.31.2
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 +19 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/cart/actions.ts +10 -1
- package/src/repositories/shopping-list/actions.ts +8 -2
- package/src/services/cart.test.ts +61 -0
package/package.json
CHANGED
|
@@ -73,7 +73,14 @@ export class CartUpdateHandler
|
|
|
73
73
|
addLineItem(
|
|
74
74
|
context: RepositoryContext,
|
|
75
75
|
resource: Writable<Cart>,
|
|
76
|
-
{
|
|
76
|
+
{
|
|
77
|
+
productId,
|
|
78
|
+
variantId,
|
|
79
|
+
sku,
|
|
80
|
+
custom,
|
|
81
|
+
quantity = 1,
|
|
82
|
+
addedAt,
|
|
83
|
+
}: CartAddLineItemAction,
|
|
77
84
|
) {
|
|
78
85
|
let product: Product | null = null;
|
|
79
86
|
|
|
@@ -157,6 +164,7 @@ export class CartUpdateHandler
|
|
|
157
164
|
}
|
|
158
165
|
resource.lineItems.push({
|
|
159
166
|
id: uuidv4(),
|
|
167
|
+
addedAt: addedAt ? addedAt : new Date().toISOString(),
|
|
160
168
|
productId: product.id,
|
|
161
169
|
productKey: product.key,
|
|
162
170
|
productSlug: product.masterData.current.slug,
|
|
@@ -176,6 +184,7 @@ export class CartUpdateHandler
|
|
|
176
184
|
lineItemMode: "Standard",
|
|
177
185
|
priceMode: "Platform",
|
|
178
186
|
state: [],
|
|
187
|
+
custom: createCustomFields(custom, context.projectKey, this._storage),
|
|
179
188
|
});
|
|
180
189
|
}
|
|
181
190
|
|
|
@@ -36,7 +36,13 @@ export class ShoppingListUpdateHandler
|
|
|
36
36
|
addLineItem(
|
|
37
37
|
context: RepositoryContext,
|
|
38
38
|
resource: Writable<ShoppingList>,
|
|
39
|
-
{
|
|
39
|
+
{
|
|
40
|
+
productId,
|
|
41
|
+
variantId,
|
|
42
|
+
sku,
|
|
43
|
+
quantity = 1,
|
|
44
|
+
addedAt,
|
|
45
|
+
}: ShoppingListAddLineItemAction,
|
|
40
46
|
) {
|
|
41
47
|
let product: Product | null = null;
|
|
42
48
|
|
|
@@ -90,7 +96,7 @@ export class ShoppingListUpdateHandler
|
|
|
90
96
|
} else {
|
|
91
97
|
// add line item
|
|
92
98
|
resource.lineItems.push({
|
|
93
|
-
addedAt: new Date().toISOString(),
|
|
99
|
+
addedAt: addedAt ? addedAt : new Date().toISOString(),
|
|
94
100
|
id: uuidv4(),
|
|
95
101
|
productId: product.id,
|
|
96
102
|
productSlug: product.masterData.current.slug,
|
|
@@ -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
|
|