@labdigital/commercetools-mock 2.31.1 → 2.32.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 +69 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +69 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/cart/actions.ts +9 -1
- package/src/repositories/customer/actions.ts +82 -0
- package/src/repositories/shopping-list/actions.ts +8 -2
- package/src/services/customer.test.ts +125 -0
package/dist/index.cjs
CHANGED
|
@@ -2438,7 +2438,14 @@ var CartUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
2438
2438
|
resource.itemShippingAddresses.push(newAddress);
|
|
2439
2439
|
}
|
|
2440
2440
|
}
|
|
2441
|
-
addLineItem(context, resource, {
|
|
2441
|
+
addLineItem(context, resource, {
|
|
2442
|
+
productId,
|
|
2443
|
+
variantId,
|
|
2444
|
+
sku,
|
|
2445
|
+
custom,
|
|
2446
|
+
quantity = 1,
|
|
2447
|
+
addedAt
|
|
2448
|
+
}) {
|
|
2442
2449
|
let product = null;
|
|
2443
2450
|
if (productId && variantId) {
|
|
2444
2451
|
product = this._storage.get(context.projectKey, "product", productId, {});
|
|
@@ -2504,6 +2511,7 @@ var CartUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
2504
2511
|
}
|
|
2505
2512
|
resource.lineItems.push({
|
|
2506
2513
|
id: (0, import_uuid5.v4)(),
|
|
2514
|
+
addedAt: addedAt ? addedAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
2507
2515
|
productId: product.id,
|
|
2508
2516
|
productKey: product.key,
|
|
2509
2517
|
productSlug: product.masterData.current.slug,
|
|
@@ -3326,6 +3334,58 @@ var CustomObjectRepository = class extends AbstractResourceRepository {
|
|
|
3326
3334
|
|
|
3327
3335
|
// src/repositories/customer/actions.ts
|
|
3328
3336
|
var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
3337
|
+
addAddress(_context, resource, { address }) {
|
|
3338
|
+
resource.addresses.push({
|
|
3339
|
+
...address,
|
|
3340
|
+
id: address.id ?? generateRandomString(5)
|
|
3341
|
+
});
|
|
3342
|
+
}
|
|
3343
|
+
addBillingAddressId(_context, resource, { addressId, addressKey }) {
|
|
3344
|
+
const address = resource.addresses.find((a) => {
|
|
3345
|
+
if (a.id != void 0 && addressId != void 0 && a.id === addressId) {
|
|
3346
|
+
return true;
|
|
3347
|
+
}
|
|
3348
|
+
return a.key != void 0 && addressKey != void 0 && a.key === addressKey;
|
|
3349
|
+
});
|
|
3350
|
+
if (!address) {
|
|
3351
|
+
throw new CommercetoolsError(
|
|
3352
|
+
{
|
|
3353
|
+
code: "InvalidInput",
|
|
3354
|
+
message: `Address with id '${addressId}' or key '${addressKey}' not found.`
|
|
3355
|
+
},
|
|
3356
|
+
400
|
|
3357
|
+
);
|
|
3358
|
+
}
|
|
3359
|
+
const billingAddressId = String(address.id);
|
|
3360
|
+
if (resource.billingAddressIds?.length) {
|
|
3361
|
+
resource.billingAddressIds.push(billingAddressId);
|
|
3362
|
+
} else if (address) {
|
|
3363
|
+
resource.billingAddressIds = [billingAddressId];
|
|
3364
|
+
}
|
|
3365
|
+
}
|
|
3366
|
+
addShippingAddressId(_context, resource, { addressId, addressKey }) {
|
|
3367
|
+
const address = resource.addresses.find((a) => {
|
|
3368
|
+
if (a.id != void 0 && addressId != void 0 && a.id === addressId) {
|
|
3369
|
+
return true;
|
|
3370
|
+
}
|
|
3371
|
+
return a.key != void 0 && addressKey != void 0 && a.key === addressKey;
|
|
3372
|
+
});
|
|
3373
|
+
if (!address) {
|
|
3374
|
+
throw new CommercetoolsError(
|
|
3375
|
+
{
|
|
3376
|
+
code: "InvalidInput",
|
|
3377
|
+
message: `Address with id '${addressId}' or key '${addressKey}' not found.`
|
|
3378
|
+
},
|
|
3379
|
+
400
|
|
3380
|
+
);
|
|
3381
|
+
}
|
|
3382
|
+
const shippingAddressId = String(address.id);
|
|
3383
|
+
if (resource.shippingAddressIds?.length) {
|
|
3384
|
+
resource.shippingAddressIds.push(shippingAddressId);
|
|
3385
|
+
} else if (address) {
|
|
3386
|
+
resource.shippingAddressIds = [shippingAddressId];
|
|
3387
|
+
}
|
|
3388
|
+
}
|
|
3329
3389
|
changeAddress(context, resource, { addressId, addressKey, address }) {
|
|
3330
3390
|
const oldAddressIndex = resource.addresses.findIndex((a) => {
|
|
3331
3391
|
if (a.id != void 0 && addressId != void 0 && a.id === addressId) {
|
|
@@ -6816,7 +6876,13 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
6816
6876
|
// src/repositories/shopping-list/actions.ts
|
|
6817
6877
|
var import_uuid11 = require("uuid");
|
|
6818
6878
|
var ShoppingListUpdateHandler = class extends AbstractUpdateHandler {
|
|
6819
|
-
addLineItem(context, resource, {
|
|
6879
|
+
addLineItem(context, resource, {
|
|
6880
|
+
productId,
|
|
6881
|
+
variantId,
|
|
6882
|
+
sku,
|
|
6883
|
+
quantity = 1,
|
|
6884
|
+
addedAt
|
|
6885
|
+
}) {
|
|
6820
6886
|
let product = null;
|
|
6821
6887
|
if (productId) {
|
|
6822
6888
|
product = this._storage.get(context.projectKey, "product", productId, {});
|
|
@@ -6857,7 +6923,7 @@ var ShoppingListUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6857
6923
|
});
|
|
6858
6924
|
} else {
|
|
6859
6925
|
resource.lineItems.push({
|
|
6860
|
-
addedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6926
|
+
addedAt: addedAt ? addedAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
6861
6927
|
id: (0, import_uuid11.v4)(),
|
|
6862
6928
|
productId: product.id,
|
|
6863
6929
|
productSlug: product.masterData.current.slug,
|