@labdigital/commercetools-mock 0.10.1 → 0.12.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.
@@ -45950,13 +45950,13 @@ ${this.pendingMocks().join("\n")}`
45950
45950
  if (!project) {
45951
45951
  return response.status(404).send({});
45952
45952
  }
45953
- this.repository.processUpdateActions(
45953
+ const updatedResource = this.repository.processUpdateActions(
45954
45954
  getRepositoryContext(request),
45955
45955
  project,
45956
45956
  updateRequest.version,
45957
45957
  updateRequest.actions
45958
45958
  );
45959
- return response.status(200).send({});
45959
+ return response.status(200).send(updatedResource);
45960
45960
  }
45961
45961
  };
45962
45962
 
@@ -47579,6 +47579,123 @@ ${this.pendingMocks().join("\n")}`
47579
47579
  setKey: (context, resource, { key }) => {
47580
47580
  resource.key = key;
47581
47581
  return resource;
47582
+ },
47583
+ addExternalImage: (context, resource, { variantId, sku, image, staged }) => {
47584
+ const addImg = (data) => {
47585
+ const { variant, isMasterVariant, variantIndex } = getVariant(
47586
+ data,
47587
+ variantId,
47588
+ sku
47589
+ );
47590
+ if (!variant) {
47591
+ throw new Error(
47592
+ `Variant with id ${variantId} or sku ${sku} not found on product ${resource.id}`
47593
+ );
47594
+ }
47595
+ if (!variant.images) {
47596
+ variant.images = [];
47597
+ } else {
47598
+ const existingImage = variant.images.find((x) => x.url === image.url);
47599
+ if (existingImage) {
47600
+ throw new Error(
47601
+ `Cannot add image '${image.url}' because product '${resource.id}' already has that image.`
47602
+ );
47603
+ }
47604
+ }
47605
+ variant.images.push(image);
47606
+ if (isMasterVariant) {
47607
+ data.masterVariant = variant;
47608
+ } else {
47609
+ data.variants[variantIndex] = variant;
47610
+ }
47611
+ };
47612
+ const onlyStaged = staged !== void 0 ? staged : true;
47613
+ addImg(resource.masterData.staged);
47614
+ if (!onlyStaged) {
47615
+ addImg(resource.masterData.current);
47616
+ }
47617
+ checkForStagedChanges(resource);
47618
+ return resource;
47619
+ },
47620
+ removeImage: (context, resource, { variantId, sku, imageUrl, staged }) => {
47621
+ const removeImg = (data) => {
47622
+ const { variant, isMasterVariant, variantIndex } = getVariant(
47623
+ data,
47624
+ variantId,
47625
+ sku
47626
+ );
47627
+ if (!variant) {
47628
+ throw new Error(
47629
+ `Variant with id ${variantId} or sku ${sku} not found on product ${resource.id}`
47630
+ );
47631
+ }
47632
+ const variantImages = variant.images ?? [];
47633
+ const existingImage = variantImages.find((x) => x.url === imageUrl);
47634
+ if (!existingImage) {
47635
+ throw new Error(
47636
+ `Cannot remove image '${imageUrl}' because product '${resource.id}' does not have that image.`
47637
+ );
47638
+ }
47639
+ variant.images = variantImages.filter((image) => image.url !== imageUrl);
47640
+ if (isMasterVariant) {
47641
+ data.masterVariant = variant;
47642
+ } else {
47643
+ data.variants[variantIndex] = variant;
47644
+ }
47645
+ };
47646
+ const onlyStaged = staged !== void 0 ? staged : true;
47647
+ removeImg(resource.masterData.staged);
47648
+ if (!onlyStaged) {
47649
+ removeImg(resource.masterData.current);
47650
+ }
47651
+ checkForStagedChanges(resource);
47652
+ return resource;
47653
+ },
47654
+ moveImageToPosition: (context, resource, {
47655
+ variantId,
47656
+ sku,
47657
+ imageUrl,
47658
+ position,
47659
+ staged
47660
+ }) => {
47661
+ const moveImg = (data) => {
47662
+ const { variant, isMasterVariant, variantIndex } = getVariant(
47663
+ data,
47664
+ variantId,
47665
+ sku
47666
+ );
47667
+ if (!variant) {
47668
+ throw new Error(
47669
+ `Variant with id ${variantId} or sku ${sku} not found on product ${resource.id}`
47670
+ );
47671
+ }
47672
+ const variantImages = variant.images ?? [];
47673
+ const existingImage = variantImages.find((x) => x.url === imageUrl);
47674
+ if (!existingImage) {
47675
+ throw new Error(
47676
+ `Cannot move image '${imageUrl}' because product '${resource.id}' does not have that image.`
47677
+ );
47678
+ }
47679
+ if (position >= variantImages.length) {
47680
+ throw new Error(
47681
+ `Invalid position given. Position in images where the image should be moved. Must be between 0 and the total number of images minus 1.`
47682
+ );
47683
+ }
47684
+ variant.images = variantImages.filter((image) => image.url !== imageUrl);
47685
+ variant.images.splice(position, 0, existingImage);
47686
+ if (isMasterVariant) {
47687
+ data.masterVariant = variant;
47688
+ } else {
47689
+ data.variants[variantIndex] = variant;
47690
+ }
47691
+ };
47692
+ const onlyStaged = staged !== void 0 ? staged : true;
47693
+ moveImg(resource.masterData.staged);
47694
+ if (!onlyStaged) {
47695
+ moveImg(resource.masterData.current);
47696
+ }
47697
+ checkForStagedChanges(resource);
47698
+ return resource;
47582
47699
  }
47583
47700
  };
47584
47701
  }
@@ -48428,6 +48545,7 @@ ${this.pendingMocks().join("\n")}`
48428
48545
  },
48429
48546
  changeMessagesConfiguration: (context, resource, { messagesConfiguration }) => {
48430
48547
  resource.messages.enabled = messagesConfiguration.enabled;
48548
+ resource.messages.deleteDaysAfterCreation = messagesConfiguration.deleteDaysAfterCreation;
48431
48549
  },
48432
48550
  changeProductSearchIndexingEnabled: (context, resource, { enabled }) => {
48433
48551
  var _a;
@@ -48747,6 +48865,9 @@ ${this.pendingMocks().join("\n")}`
48747
48865
  changeKey: (context, resource, { key }) => {
48748
48866
  resource.key = key;
48749
48867
  },
48868
+ changeInitial: (context, resource, { initial }) => {
48869
+ resource.initial = initial;
48870
+ },
48750
48871
  setDescription: (context, resource, { description }) => {
48751
48872
  resource.description = description;
48752
48873
  },