@labdigital/commercetools-mock 2.3.0 → 2.4.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
@@ -2760,6 +2760,22 @@ var CategoryRepository = class extends AbstractResourceRepository {
2760
2760
  changeSlug: (context, resource, { slug }) => {
2761
2761
  resource.slug = slug;
2762
2762
  },
2763
+ changeName: (context, resource, { name }) => {
2764
+ resource.name = name;
2765
+ },
2766
+ changeParent: (context, resource, { parent }) => {
2767
+ const category = this._storage.getByResourceIdentifier(
2768
+ context.projectKey,
2769
+ parent
2770
+ );
2771
+ if (!category) {
2772
+ throw new Error("No category found for reference");
2773
+ }
2774
+ resource.parent = {
2775
+ typeId: "category",
2776
+ id: category.id
2777
+ };
2778
+ },
2763
2779
  setKey: (context, resource, { key }) => {
2764
2780
  resource.key = key;
2765
2781
  },
@@ -3924,6 +3940,47 @@ var ProductRepository = class extends AbstractResourceRepository {
3924
3940
  checkForStagedChanges(resource);
3925
3941
  return resource;
3926
3942
  },
3943
+ setAttributeInAllVariants: (context, resource, { name, value, staged }) => {
3944
+ const setAttrInAllVariants = (data) => {
3945
+ if (!data.masterVariant.attributes) {
3946
+ data.masterVariant.attributes = [];
3947
+ }
3948
+ const existingAttr = data.masterVariant.attributes?.find(
3949
+ (attr) => attr.name === name
3950
+ );
3951
+ if (existingAttr) {
3952
+ existingAttr.value = value;
3953
+ } else {
3954
+ data.masterVariant.attributes.push({
3955
+ name,
3956
+ value
3957
+ });
3958
+ }
3959
+ data.variants.forEach((variant) => {
3960
+ if (!variant.attributes) {
3961
+ variant.attributes = [];
3962
+ }
3963
+ const existingAttr2 = variant.attributes.find(
3964
+ (attr) => attr.name === name
3965
+ );
3966
+ if (existingAttr2) {
3967
+ existingAttr2.value = value;
3968
+ } else {
3969
+ variant.attributes.push({
3970
+ name,
3971
+ value
3972
+ });
3973
+ }
3974
+ });
3975
+ };
3976
+ const onlyStaged = staged !== void 0 ? staged : true;
3977
+ setAttrInAllVariants(resource.masterData.staged);
3978
+ if (!onlyStaged) {
3979
+ setAttrInAllVariants(resource.masterData.current);
3980
+ }
3981
+ checkForStagedChanges(resource);
3982
+ return resource;
3983
+ },
3927
3984
  setDescription: (context, resource, { description, staged }) => {
3928
3985
  const onlyStaged = staged !== void 0 ? staged : true;
3929
3986
  resource.masterData.staged.description = description;