@labdigital/commercetools-mock 2.7.0 → 2.8.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 CHANGED
@@ -1231,11 +1231,13 @@ var InMemoryStorage = class extends AbstractStorage {
1231
1231
  if (reference === void 0)
1232
1232
  return;
1233
1233
  if (reference.typeId !== void 0 && (reference.id !== void 0 || reference.key !== void 0)) {
1234
- reference.obj = this.getByResourceIdentifier(projectKey, {
1235
- typeId: reference.typeId,
1236
- id: reference.id,
1237
- key: reference.key
1238
- });
1234
+ if (!reference.obj) {
1235
+ reference.obj = this.getByResourceIdentifier(projectKey, {
1236
+ typeId: reference.typeId,
1237
+ id: reference.id,
1238
+ key: reference.key
1239
+ });
1240
+ }
1239
1241
  if (expand) {
1240
1242
  this._resolveResource(projectKey, reference.obj, expand);
1241
1243
  }
@@ -1670,7 +1672,7 @@ var getReferenceFromResourceIdentifier = (resourceIdentifier, projectKey, storag
1670
1672
  resourceIdentifier
1671
1673
  );
1672
1674
  if (!resource) {
1673
- const errIdentifier = resourceIdentifier.key ? `key '${resourceIdentifier.key}'` : `identifier '${resourceIdentifier.key}'`;
1675
+ const errIdentifier = resourceIdentifier.key ? `key '${resourceIdentifier.key}'` : `identifier '${resourceIdentifier.id}'`;
1674
1676
  throw new CommercetoolsError(
1675
1677
  {
1676
1678
  code: "ReferencedResourceNotFound",
@@ -3010,7 +3012,8 @@ var CustomerRepository = class extends AbstractResourceRepository {
3010
3012
  email: draft.email.toLowerCase(),
3011
3013
  password: draft.password ? hashPassword(draft.password) : void 0,
3012
3014
  isEmailVerified: draft.isEmailVerified || false,
3013
- addresses: []
3015
+ addresses: [],
3016
+ customerNumber: draft.customerNumber
3014
3017
  };
3015
3018
  this.saveNew(context, resource);
3016
3019
  return resource;
@@ -3516,10 +3519,11 @@ var OrderRepository = class extends AbstractResourceRepository {
3516
3519
  name: draft.name,
3517
3520
  quantity: draft.quantity ?? 0,
3518
3521
  perMethodTaxRate: [],
3519
- priceMode: draft.priceMode,
3522
+ priceMode: draft.priceMode ?? "Standard",
3520
3523
  slug: draft.slug,
3521
3524
  state: [],
3522
- totalPrice: createCentPrecisionMoney(draft.money)
3525
+ totalPrice: createCentPrecisionMoney(draft.money),
3526
+ taxedPricePortions: []
3523
3527
  };
3524
3528
  return lineItem;
3525
3529
  }
@@ -3555,6 +3559,37 @@ var OrderRepository = class extends AbstractResourceRepository {
3555
3559
  id: payment.id
3556
3560
  });
3557
3561
  },
3562
+ addReturnInfo: (context, resource, info) => {
3563
+ if (!resource.returnInfo) {
3564
+ resource.returnInfo = [];
3565
+ }
3566
+ const resolved = {
3567
+ items: info.items.map((item) => {
3568
+ const common = {
3569
+ ...getBaseResourceProperties(),
3570
+ quantity: item.quantity,
3571
+ paymentState: "Initial",
3572
+ shipmentState: "Initial",
3573
+ comment: item.comment
3574
+ };
3575
+ if (item.customLineItemId) {
3576
+ return {
3577
+ ...common,
3578
+ type: "CustomLineItemReturnItem",
3579
+ customLineItemId: item.customLineItemId
3580
+ };
3581
+ }
3582
+ return {
3583
+ ...common,
3584
+ type: "LineItemReturnItem",
3585
+ lineItemId: item.customLineItemId || item.lineItemId
3586
+ };
3587
+ }),
3588
+ returnTrackingId: info.returnTrackingId,
3589
+ returnDate: info.returnDate
3590
+ };
3591
+ resource.returnInfo.push(resolved);
3592
+ },
3558
3593
  changeOrderState: (context, resource, { orderState }) => {
3559
3594
  resource.orderState = orderState;
3560
3595
  },
@@ -3865,9 +3900,9 @@ var ProductRepository = class extends AbstractResourceRepository {
3865
3900
  slug: draft.slug,
3866
3901
  description: draft.description,
3867
3902
  categories: categoryReferences,
3868
- masterVariant: variantFromDraft(1, draft.masterVariant),
3903
+ masterVariant: this.variantFromDraft(context, 1, draft.masterVariant),
3869
3904
  variants: draft.variants?.map(
3870
- (variant, index) => variantFromDraft(index + 2, variant)
3905
+ (variant, index) => this.variantFromDraft(context, index + 2, variant)
3871
3906
  ) ?? [],
3872
3907
  metaTitle: draft.metaTitle,
3873
3908
  metaDescription: draft.metaDescription,
@@ -3890,6 +3925,30 @@ var ProductRepository = class extends AbstractResourceRepository {
3890
3925
  this.saveNew(context, resource);
3891
3926
  return resource;
3892
3927
  }
3928
+ variantFromDraft(context, variantId, variant) {
3929
+ return {
3930
+ id: variantId,
3931
+ sku: variant?.sku,
3932
+ key: variant?.key,
3933
+ attributes: variant?.attributes ?? [],
3934
+ prices: variant?.prices?.map((p) => this.priceFromDraft(context, p)),
3935
+ assets: [],
3936
+ images: []
3937
+ };
3938
+ }
3939
+ priceFromDraft(context, draft) {
3940
+ return {
3941
+ id: (0, import_uuid6.v4)(),
3942
+ key: draft.key,
3943
+ country: draft.country,
3944
+ value: createTypedMoney(draft.value),
3945
+ channel: draft.channel ? getReferenceFromResourceIdentifier(
3946
+ draft.channel,
3947
+ context.projectKey,
3948
+ this._storage
3949
+ ) : void 0
3950
+ };
3951
+ }
3893
3952
  actions = {
3894
3953
  publish: (context, resource, { scope }) => {
3895
3954
  resource.masterData.current = resource.masterData.staged;
@@ -4134,7 +4193,7 @@ var ProductRepository = class extends AbstractResourceRepository {
4134
4193
  data.variants[variantIndex] = variant;
4135
4194
  }
4136
4195
  };
4137
- const priceToAdd = priceFromDraft(price);
4196
+ const priceToAdd = this.priceFromDraft(context, price);
4138
4197
  const onlyStaged = staged !== void 0 ? staged : true;
4139
4198
  addVariantPrice(resource.masterData.staged, priceToAdd);
4140
4199
  if (!onlyStaged) {
@@ -4291,7 +4350,7 @@ var ProductRepository = class extends AbstractResourceRepository {
4291
4350
  (max, element) => element.id > max ? element.id : max,
4292
4351
  0
4293
4352
  );
4294
- const variant = variantFromDraft(maxId + 1, variantDraft);
4353
+ const variant = this.variantFromDraft(context, maxId + 1, variantDraft);
4295
4354
  dataStaged.variants.push(variant);
4296
4355
  const onlyStaged = staged !== void 0 ? staged : true;
4297
4356
  if (!onlyStaged) {
@@ -4529,21 +4588,6 @@ var getVariant = (productData, variantId, sku) => {
4529
4588
  variantIndex: !isMasterVariant && foundVariant ? productData.variants.indexOf(foundVariant) : -1
4530
4589
  };
4531
4590
  };
4532
- var variantFromDraft = (variantId, variant) => ({
4533
- id: variantId,
4534
- sku: variant?.sku,
4535
- key: variant?.key,
4536
- attributes: variant?.attributes ?? [],
4537
- prices: variant?.prices?.map(priceFromDraft),
4538
- assets: [],
4539
- images: []
4540
- });
4541
- var priceFromDraft = (draft) => ({
4542
- id: (0, import_uuid6.v4)(),
4543
- key: draft.key,
4544
- country: draft.country,
4545
- value: createTypedMoney(draft.value)
4546
- });
4547
4591
 
4548
4592
  // src/repositories/product-discount.ts
4549
4593
  var ProductDiscountRepository = class extends AbstractResourceRepository {
@@ -4815,7 +4859,7 @@ var getVariants = (p) => [
4815
4859
  ];
4816
4860
 
4817
4861
  // src/priceSelector.ts
4818
- var applyPriceSelector = (products, selector) => {
4862
+ var applyPriceSelector = (products, selector, noScopedPrice = false) => {
4819
4863
  validatePriceSelector(selector);
4820
4864
  for (const product of products) {
4821
4865
  const variants = [
@@ -4826,11 +4870,14 @@ var applyPriceSelector = (products, selector) => {
4826
4870
  const scopedPrices = variant.prices?.filter((p) => priceSelectorFilter(p, selector)) ?? [];
4827
4871
  if (scopedPrices.length > 0) {
4828
4872
  const price = scopedPrices[0];
4829
- variant.scopedPriceDiscounted = false;
4830
- variant.scopedPrice = {
4831
- ...price,
4832
- currentValue: price.value
4833
- };
4873
+ variant.price = scopedPrices[0];
4874
+ if (!noScopedPrice) {
4875
+ variant.scopedPriceDiscounted = false;
4876
+ variant.scopedPrice = {
4877
+ ...price,
4878
+ currentValue: price.value
4879
+ };
4880
+ }
4834
4881
  }
4835
4882
  }
4836
4883
  }
@@ -5165,6 +5212,16 @@ var ProductProjectionRepository = class extends AbstractResourceRepository {
5165
5212
  );
5166
5213
  }
5167
5214
  }
5215
+ applyPriceSelector(
5216
+ resources,
5217
+ {
5218
+ country: params.priceCountry,
5219
+ channel: params.priceChannel,
5220
+ customerGroup: params.priceCustomerGroup,
5221
+ currency: params.priceCurrency
5222
+ },
5223
+ true
5224
+ );
5168
5225
  if (params.expand !== void 0) {
5169
5226
  resources = resources.map(
5170
5227
  (resource) => this._storage.expand(context.projectKey, resource, params.expand)
@@ -5199,7 +5256,6 @@ var ProductSelectionRepository = class extends AbstractResourceRepository {
5199
5256
  productCount: 0,
5200
5257
  key: draft.key,
5201
5258
  name: draft.name,
5202
- type: "individual",
5203
5259
  mode: "Individual"
5204
5260
  };
5205
5261
  this.saveNew(context, resource);
@@ -5415,9 +5471,28 @@ var ReviewRepository = class extends AbstractResourceRepository {
5415
5471
  return "review";
5416
5472
  }
5417
5473
  create(context, draft) {
5474
+ if (!draft.target)
5475
+ throw new Error("Missing target");
5418
5476
  const resource = {
5419
5477
  ...getBaseResourceProperties(),
5420
- includedInStatistics: false
5478
+ locale: draft.locale,
5479
+ authorName: draft.authorName,
5480
+ title: draft.title,
5481
+ text: draft.text,
5482
+ rating: draft.rating,
5483
+ uniquenessValue: draft.uniquenessValue,
5484
+ state: draft.state ? getReferenceFromResourceIdentifier(
5485
+ draft.state,
5486
+ context.projectKey,
5487
+ this._storage
5488
+ ) : void 0,
5489
+ target: draft.target ? getReferenceFromResourceIdentifier(draft.target, context.projectKey, this._storage) : void 0,
5490
+ includedInStatistics: false,
5491
+ custom: createCustomFields(
5492
+ draft.custom,
5493
+ context.projectKey,
5494
+ this._storage
5495
+ )
5421
5496
  };
5422
5497
  this.saveNew(context, resource);
5423
5498
  return resource;
@@ -6737,6 +6812,18 @@ var ProductService = class extends AbstractService {
6737
6812
  }
6738
6813
  };
6739
6814
 
6815
+ // src/services/reviews.ts
6816
+ var ReviewService = class extends AbstractService {
6817
+ repository;
6818
+ constructor(parent, repository) {
6819
+ super(parent);
6820
+ this.repository = repository;
6821
+ }
6822
+ getBasePath() {
6823
+ return "reviews";
6824
+ }
6825
+ };
6826
+
6740
6827
  // src/services/shipping-method.ts
6741
6828
  var ShippingMethodService = class extends AbstractService {
6742
6829
  repository;
@@ -6901,6 +6988,7 @@ var createServices = (router, repos) => ({
6901
6988
  router,
6902
6989
  repos["product-selection"]
6903
6990
  ),
6991
+ reviews: new ReviewService(router, repos["review"]),
6904
6992
  "shopping-list": new ShoppingListService(router, repos["shopping-list"]),
6905
6993
  state: new StateService(router, repos["state"]),
6906
6994
  store: new StoreService(router, repos["store"]),
@@ -7090,6 +7178,9 @@ var CommercetoolsMock = class {
7090
7178
  })
7091
7179
  );
7092
7180
  }
7181
+ mswServer() {
7182
+ return this._mswServer;
7183
+ }
7093
7184
  startServer() {
7094
7185
  if (_globalListeners.length > 0) {
7095
7186
  if (this._mswServer !== void 0) {