@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.js
CHANGED
|
@@ -2401,7 +2401,14 @@ var CartUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
2401
2401
|
resource.itemShippingAddresses.push(newAddress);
|
|
2402
2402
|
}
|
|
2403
2403
|
}
|
|
2404
|
-
addLineItem(context, resource, {
|
|
2404
|
+
addLineItem(context, resource, {
|
|
2405
|
+
productId,
|
|
2406
|
+
variantId,
|
|
2407
|
+
sku,
|
|
2408
|
+
custom,
|
|
2409
|
+
quantity = 1,
|
|
2410
|
+
addedAt
|
|
2411
|
+
}) {
|
|
2405
2412
|
let product = null;
|
|
2406
2413
|
if (productId && variantId) {
|
|
2407
2414
|
product = this._storage.get(context.projectKey, "product", productId, {});
|
|
@@ -2467,6 +2474,7 @@ var CartUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
2467
2474
|
}
|
|
2468
2475
|
resource.lineItems.push({
|
|
2469
2476
|
id: uuidv45(),
|
|
2477
|
+
addedAt: addedAt ? addedAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
2470
2478
|
productId: product.id,
|
|
2471
2479
|
productKey: product.key,
|
|
2472
2480
|
productSlug: product.masterData.current.slug,
|
|
@@ -3289,6 +3297,58 @@ var CustomObjectRepository = class extends AbstractResourceRepository {
|
|
|
3289
3297
|
|
|
3290
3298
|
// src/repositories/customer/actions.ts
|
|
3291
3299
|
var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
3300
|
+
addAddress(_context, resource, { address }) {
|
|
3301
|
+
resource.addresses.push({
|
|
3302
|
+
...address,
|
|
3303
|
+
id: address.id ?? generateRandomString(5)
|
|
3304
|
+
});
|
|
3305
|
+
}
|
|
3306
|
+
addBillingAddressId(_context, resource, { addressId, addressKey }) {
|
|
3307
|
+
const address = resource.addresses.find((a) => {
|
|
3308
|
+
if (a.id != void 0 && addressId != void 0 && a.id === addressId) {
|
|
3309
|
+
return true;
|
|
3310
|
+
}
|
|
3311
|
+
return a.key != void 0 && addressKey != void 0 && a.key === addressKey;
|
|
3312
|
+
});
|
|
3313
|
+
if (!address) {
|
|
3314
|
+
throw new CommercetoolsError(
|
|
3315
|
+
{
|
|
3316
|
+
code: "InvalidInput",
|
|
3317
|
+
message: `Address with id '${addressId}' or key '${addressKey}' not found.`
|
|
3318
|
+
},
|
|
3319
|
+
400
|
|
3320
|
+
);
|
|
3321
|
+
}
|
|
3322
|
+
const billingAddressId = String(address.id);
|
|
3323
|
+
if (resource.billingAddressIds?.length) {
|
|
3324
|
+
resource.billingAddressIds.push(billingAddressId);
|
|
3325
|
+
} else if (address) {
|
|
3326
|
+
resource.billingAddressIds = [billingAddressId];
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
3329
|
+
addShippingAddressId(_context, resource, { addressId, addressKey }) {
|
|
3330
|
+
const address = resource.addresses.find((a) => {
|
|
3331
|
+
if (a.id != void 0 && addressId != void 0 && a.id === addressId) {
|
|
3332
|
+
return true;
|
|
3333
|
+
}
|
|
3334
|
+
return a.key != void 0 && addressKey != void 0 && a.key === addressKey;
|
|
3335
|
+
});
|
|
3336
|
+
if (!address) {
|
|
3337
|
+
throw new CommercetoolsError(
|
|
3338
|
+
{
|
|
3339
|
+
code: "InvalidInput",
|
|
3340
|
+
message: `Address with id '${addressId}' or key '${addressKey}' not found.`
|
|
3341
|
+
},
|
|
3342
|
+
400
|
|
3343
|
+
);
|
|
3344
|
+
}
|
|
3345
|
+
const shippingAddressId = String(address.id);
|
|
3346
|
+
if (resource.shippingAddressIds?.length) {
|
|
3347
|
+
resource.shippingAddressIds.push(shippingAddressId);
|
|
3348
|
+
} else if (address) {
|
|
3349
|
+
resource.shippingAddressIds = [shippingAddressId];
|
|
3350
|
+
}
|
|
3351
|
+
}
|
|
3292
3352
|
changeAddress(context, resource, { addressId, addressKey, address }) {
|
|
3293
3353
|
const oldAddressIndex = resource.addresses.findIndex((a) => {
|
|
3294
3354
|
if (a.id != void 0 && addressId != void 0 && a.id === addressId) {
|
|
@@ -6779,7 +6839,13 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
6779
6839
|
// src/repositories/shopping-list/actions.ts
|
|
6780
6840
|
import { v4 as uuidv411 } from "uuid";
|
|
6781
6841
|
var ShoppingListUpdateHandler = class extends AbstractUpdateHandler {
|
|
6782
|
-
addLineItem(context, resource, {
|
|
6842
|
+
addLineItem(context, resource, {
|
|
6843
|
+
productId,
|
|
6844
|
+
variantId,
|
|
6845
|
+
sku,
|
|
6846
|
+
quantity = 1,
|
|
6847
|
+
addedAt
|
|
6848
|
+
}) {
|
|
6783
6849
|
let product = null;
|
|
6784
6850
|
if (productId) {
|
|
6785
6851
|
product = this._storage.get(context.projectKey, "product", productId, {});
|
|
@@ -6820,7 +6886,7 @@ var ShoppingListUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6820
6886
|
});
|
|
6821
6887
|
} else {
|
|
6822
6888
|
resource.lineItems.push({
|
|
6823
|
-
addedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6889
|
+
addedAt: addedAt ? addedAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
6824
6890
|
id: uuidv411(),
|
|
6825
6891
|
productId: product.id,
|
|
6826
6892
|
productSlug: product.masterData.current.slug,
|