@labdigital/commercetools-mock 2.31.2 → 2.33.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 +55 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/customer/actions.ts +82 -0
- package/src/repositories/order/actions.ts +9 -0
- package/src/services/customer.test.ts +125 -0
- package/src/services/order.test.ts +16 -0
package/dist/index.js
CHANGED
|
@@ -3297,6 +3297,58 @@ var CustomObjectRepository = class extends AbstractResourceRepository {
|
|
|
3297
3297
|
|
|
3298
3298
|
// src/repositories/customer/actions.ts
|
|
3299
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
|
+
}
|
|
3300
3352
|
changeAddress(context, resource, { addressId, addressKey, address }) {
|
|
3301
3353
|
const oldAddressIndex = resource.addresses.findIndex((a) => {
|
|
3302
3354
|
if (a.id != void 0 && addressId != void 0 && a.id === addressId) {
|
|
@@ -4025,6 +4077,9 @@ var OrderUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
4025
4077
|
setOrderNumber(context, resource, { orderNumber }) {
|
|
4026
4078
|
resource.orderNumber = orderNumber;
|
|
4027
4079
|
}
|
|
4080
|
+
setPurchaseOrderNumber(context, resource, { purchaseOrderNumber }) {
|
|
4081
|
+
resource.purchaseOrderNumber = purchaseOrderNumber;
|
|
4082
|
+
}
|
|
4028
4083
|
setShippingAddress(context, resource, { address }) {
|
|
4029
4084
|
resource.shippingAddress = createAddress(
|
|
4030
4085
|
address,
|