Skip to content

Commit 47b2ea5

Browse files
Remove discounted field mapping from priceFromDraft as it should be calculated
Co-authored-by: mvantellingen <245297+mvantellingen@users.noreply.github.com>
1 parent 818ffa8 commit 47b2ea5

File tree

3 files changed

+5
-76
lines changed

3 files changed

+5
-76
lines changed

.changeset/plain-gifts-cross.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@labdigital/commercetools-mock": patch
3+
---
4+
5+
Remove discounted field mapping from priceFromDraft as it should be calculated

src/repositories/product/helpers.test.ts

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import type {
22
CustomerGroupResourceIdentifier,
3-
DiscountedPriceDraft,
43
PriceDraft,
54
PriceTierDraft,
6-
ProductDiscountReference,
75
} from "@commercetools/platform-sdk";
86
import { describe, expect, test } from "vitest";
97
import { getBaseResourceProperties } from "~src/helpers";
@@ -174,70 +172,6 @@ describe("priceFromDraft", () => {
174172
});
175173
});
176174

177-
test("should handle discounted field when provided", () => {
178-
// First create a product discount in storage
179-
const productDiscount = {
180-
...getBaseResourceProperties(),
181-
id: "product-discount-id",
182-
name: { en: "Test Discount" },
183-
description: { en: "Test Discount Description" },
184-
value: {
185-
type: "relative" as const,
186-
permyriad: 2000, // 20% discount
187-
},
188-
predicate: "1=1",
189-
sortOrder: "0.1",
190-
isActive: true,
191-
references: [],
192-
};
193-
storage.add("test-project", "product-discount", productDiscount);
194-
195-
const discountedDraft: DiscountedPriceDraft = {
196-
value: {
197-
currencyCode: "EUR",
198-
centAmount: 800,
199-
},
200-
discount: {
201-
typeId: "product-discount",
202-
id: "product-discount-id",
203-
},
204-
};
205-
206-
const draft: PriceDraft = {
207-
value: {
208-
currencyCode: "EUR",
209-
centAmount: 1000,
210-
},
211-
country: "NL",
212-
discounted: discountedDraft,
213-
};
214-
215-
const result = priceFromDraft(context, storage, draft);
216-
217-
expect(result).toMatchObject({
218-
id: expect.any(String),
219-
country: "NL",
220-
value: {
221-
type: "centPrecision",
222-
currencyCode: "EUR",
223-
centAmount: 1000,
224-
fractionDigits: 2,
225-
},
226-
discounted: {
227-
value: {
228-
type: "centPrecision",
229-
currencyCode: "EUR",
230-
centAmount: 800,
231-
fractionDigits: 2,
232-
},
233-
discount: {
234-
typeId: "product-discount",
235-
id: "product-discount-id",
236-
},
237-
},
238-
});
239-
});
240-
241175
test("should handle custom field when provided", () => {
242176
// First create a type in storage for custom fields
243177
const customType = {

src/repositories/product/helpers.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,6 @@ export const priceFromDraft = (
128128
: undefined,
129129
validFrom: draft.validFrom,
130130
validUntil: draft.validUntil,
131-
discounted: draft.discounted
132-
? {
133-
value: createTypedMoney(draft.discounted.value),
134-
discount: getReferenceFromResourceIdentifier<ProductDiscountReference>(
135-
draft.discounted.discount,
136-
context.projectKey,
137-
storage,
138-
),
139-
}
140-
: undefined,
141131
tiers: draft.tiers?.map(
142132
(tier: PriceTierDraft): PriceTier => ({
143133
minimumQuantity: tier.minimumQuantity,

0 commit comments

Comments
 (0)