@labdigital/commercetools-mock 1.3.0 → 1.3.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.mjs CHANGED
@@ -1254,12 +1254,11 @@ var CartRepository = class extends AbstractResourceRepository {
1254
1254
  (x) => x.productId === product?.id && x.variant.id === variant?.id
1255
1255
  );
1256
1256
  if (alreadyAdded) {
1257
- resource.lineItems.map((x) => {
1257
+ resource.lineItems.forEach((x) => {
1258
1258
  if (x.productId === product?.id && x.variant.id === variant?.id) {
1259
1259
  x.quantity += quantity;
1260
1260
  x.totalPrice.centAmount = calculateLineItemTotalPrice(x);
1261
1261
  }
1262
- return x;
1263
1262
  });
1264
1263
  } else {
1265
1264
  if (!variant.prices?.length) {
@@ -1328,18 +1327,16 @@ var CartRepository = class extends AbstractResourceRepository {
1328
1327
  message: `Either lineItemid or lineItemKey needs to be provided.`
1329
1328
  });
1330
1329
  }
1331
- const shouldDelete = !quantity || quantity >= lineItem.quantity;
1332
- if (shouldDelete) {
1330
+ if (quantity === 0) {
1333
1331
  resource.lineItems = resource.lineItems.filter(
1334
1332
  (x) => x.id !== lineItemId
1335
1333
  );
1336
1334
  } else {
1337
- resource.lineItems.map((x) => {
1335
+ resource.lineItems.forEach((x) => {
1338
1336
  if (x.id === lineItemId && quantity) {
1339
- x.quantity -= quantity;
1337
+ x.quantity = quantity;
1340
1338
  x.totalPrice.centAmount = calculateLineItemTotalPrice(x);
1341
1339
  }
1342
- return x;
1343
1340
  });
1344
1341
  }
1345
1342
  resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
@@ -1358,12 +1355,11 @@ var CartRepository = class extends AbstractResourceRepository {
1358
1355
  (x) => x.id !== lineItemId
1359
1356
  );
1360
1357
  } else {
1361
- resource.lineItems.map((x) => {
1358
+ resource.lineItems.forEach((x) => {
1362
1359
  if (x.id === lineItemId && quantity) {
1363
1360
  x.quantity -= quantity;
1364
1361
  x.totalPrice.centAmount = calculateLineItemTotalPrice(x);
1365
1362
  }
1366
- return x;
1367
1363
  });
1368
1364
  }
1369
1365
  resource.totalPrice.centAmount = calculateCartTotalPrice(resource);