@labdigital/commercetools-mock 1.0.0 → 1.1.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.
@@ -48024,6 +48024,122 @@ ${this.pendingMocks().join("\n")}`
48024
48024
  }
48025
48025
  checkForStagedChanges(resource);
48026
48026
  return resource;
48027
+ },
48028
+ addPrice: (context, resource, { variantId, sku, price, staged }) => {
48029
+ const addVariantPrice = (data) => {
48030
+ const { variant, isMasterVariant, variantIndex } = getVariant(
48031
+ data,
48032
+ variantId,
48033
+ sku
48034
+ );
48035
+ if (!variant) {
48036
+ throw new Error(
48037
+ `Variant with id ${variantId} or sku ${sku} not found on product ${resource.id}`
48038
+ );
48039
+ }
48040
+ if (variant.prices === void 0) {
48041
+ variant.prices = [priceFromDraft(price)];
48042
+ } else {
48043
+ variant.prices.push(priceFromDraft(price));
48044
+ }
48045
+ if (isMasterVariant) {
48046
+ data.masterVariant = variant;
48047
+ } else {
48048
+ data.variants[variantIndex] = variant;
48049
+ }
48050
+ };
48051
+ const onlyStaged = staged !== void 0 ? staged : true;
48052
+ addVariantPrice(resource.masterData.staged);
48053
+ if (!onlyStaged) {
48054
+ addVariantPrice(resource.masterData.current);
48055
+ }
48056
+ checkForStagedChanges(resource);
48057
+ return resource;
48058
+ },
48059
+ changePrice: (context, resource, { priceId, price, staged }) => {
48060
+ const changeVariantPrice = (data) => {
48061
+ var _a;
48062
+ const allVariants = [data.masterVariant, ...data.variants ?? []];
48063
+ const priceVariant = allVariants.find(
48064
+ (variant2) => {
48065
+ var _a2;
48066
+ return (_a2 = variant2.prices) == null ? void 0 : _a2.some((x) => x.id === priceId);
48067
+ }
48068
+ );
48069
+ if (!priceVariant) {
48070
+ throw new Error(
48071
+ `Price with id ${priceId} not found on product ${resource.id}`
48072
+ );
48073
+ }
48074
+ const { variant, isMasterVariant, variantIndex } = getVariant(
48075
+ data,
48076
+ priceVariant.id,
48077
+ priceVariant.sku
48078
+ );
48079
+ if (!variant) {
48080
+ throw new Error(
48081
+ `Variant with id ${priceVariant.id} or sku ${priceVariant.sku} not found on product ${resource.id}`
48082
+ );
48083
+ }
48084
+ variant.prices = (_a = variant.prices) == null ? void 0 : _a.map((x) => {
48085
+ if (x.id === priceId) {
48086
+ return { ...x, ...price };
48087
+ }
48088
+ return x;
48089
+ });
48090
+ if (isMasterVariant) {
48091
+ data.masterVariant = variant;
48092
+ } else {
48093
+ data.variants[variantIndex] = variant;
48094
+ }
48095
+ };
48096
+ const onlyStaged = staged !== void 0 ? staged : true;
48097
+ changeVariantPrice(resource.masterData.staged);
48098
+ if (!onlyStaged) {
48099
+ changeVariantPrice(resource.masterData.current);
48100
+ }
48101
+ checkForStagedChanges(resource);
48102
+ return resource;
48103
+ },
48104
+ removePrice: (context, resource, { priceId, staged }) => {
48105
+ const removeVariantPrice = (data) => {
48106
+ var _a;
48107
+ const allVariants = [data.masterVariant, ...data.variants ?? []];
48108
+ const priceVariant = allVariants.find(
48109
+ (variant2) => {
48110
+ var _a2;
48111
+ return (_a2 = variant2.prices) == null ? void 0 : _a2.some((x) => x.id === priceId);
48112
+ }
48113
+ );
48114
+ if (!priceVariant) {
48115
+ throw new Error(
48116
+ `Price with id ${priceId} not found on product ${resource.id}`
48117
+ );
48118
+ }
48119
+ const { variant, isMasterVariant, variantIndex } = getVariant(
48120
+ data,
48121
+ priceVariant.id,
48122
+ priceVariant.sku
48123
+ );
48124
+ if (!variant) {
48125
+ throw new Error(
48126
+ `Variant with id ${priceVariant.id} or sku ${priceVariant.sku} not found on product ${resource.id}`
48127
+ );
48128
+ }
48129
+ variant.prices = (_a = variant.prices) == null ? void 0 : _a.filter((x) => x.id !== priceId);
48130
+ if (isMasterVariant) {
48131
+ data.masterVariant = variant;
48132
+ } else {
48133
+ data.variants[variantIndex] = variant;
48134
+ }
48135
+ };
48136
+ const onlyStaged = staged !== void 0 ? staged : true;
48137
+ removeVariantPrice(resource.masterData.staged);
48138
+ if (!onlyStaged) {
48139
+ removeVariantPrice(resource.masterData.current);
48140
+ }
48141
+ checkForStagedChanges(resource);
48142
+ return resource;
48027
48143
  }
48028
48144
  };
48029
48145
  }
@@ -48117,6 +48233,7 @@ ${this.pendingMocks().join("\n")}`
48117
48233
  };
48118
48234
  var priceFromDraft = (draft) => ({
48119
48235
  id: v4(),
48236
+ country: draft.country,
48120
48237
  value: {
48121
48238
  currencyCode: draft.value.currencyCode,
48122
48239
  centAmount: draft.value.centAmount,