@labdigital/commercetools-mock 2.3.0 → 2.5.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;
@@ -6956,6 +7013,24 @@ var CommercetoolsMock = class {
6956
7013
  headers: mapHeaderType(res.headers)
6957
7014
  });
6958
7015
  }),
7016
+ import_msw.http.head(`${this.options.apiHost}/*`, async ({ request }) => {
7017
+ const body = await request.text();
7018
+ const url = new URL(request.url);
7019
+ const headers = copyHeaders(request.headers);
7020
+ const res = await (0, import_light_my_request.default)(server).get(url.pathname + "?" + url.searchParams.toString()).body(body).headers(headers).end();
7021
+ if (res.statusCode === 200) {
7022
+ const parsedBody = JSON.parse(res.body);
7023
+ const resultCount = "count" in parsedBody ? parsedBody.count : Object.keys(parsedBody).length;
7024
+ return new import_msw.HttpResponse(null, {
7025
+ status: resultCount > 0 ? 200 : 404,
7026
+ headers: mapHeaderType(res.headers)
7027
+ });
7028
+ }
7029
+ return new import_msw.HttpResponse(null, {
7030
+ status: res.statusCode,
7031
+ headers: mapHeaderType(res.headers)
7032
+ });
7033
+ }),
6959
7034
  import_msw.http.get(`${this.options.apiHost}/*`, async ({ request }) => {
6960
7035
  const body = await request.text();
6961
7036
  const url = new URL(request.url);