Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit f0cf390

Browse files
committed
fix: free -> paid skips tax percentage changes
1 parent 4a7aa3b commit f0cf390

2 files changed

Lines changed: 57 additions & 2 deletions

File tree

apps/ui/modules/__tests__/reservationUnit.test.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,16 @@ function constructPricing({
10141014
}
10151015

10161016
describe("getReservationUnitPrice", () => {
1017+
beforeAll(() => {
1018+
jest.useFakeTimers({
1019+
doNotFake: ["performance"],
1020+
now: new Date(2024, 0, 1, 10, 0, 0),
1021+
});
1022+
});
1023+
afterAll(() => {
1024+
jest.useRealTimers();
1025+
});
1026+
10171027
function connstructInput({
10181028
date,
10191029
}: {
@@ -1061,7 +1071,51 @@ describe("getReservationUnitPrice", () => {
10611071
expect(getReservationUnitPrice(input2)).toEqual("10,00 - 20,00 € / tunti");
10621072
});
10631073

1064-
test.todo("Tax change should work");
1074+
test("future change in tax uses active price", () => {
1075+
const date = addDays(new Date(), 15);
1076+
const input = {
1077+
pricingDate: date,
1078+
reservationUnit: {
1079+
pricings: [
1080+
constructPricing({
1081+
begins: addDays(new Date(), -10),
1082+
highestPrice: 20,
1083+
taxPercentage: 24,
1084+
status: Status.Active,
1085+
}),
1086+
constructPricing({
1087+
begins: addDays(new Date(), 10),
1088+
highestPrice: 25,
1089+
taxPercentage: 25.5,
1090+
status: Status.Future,
1091+
}),
1092+
],
1093+
},
1094+
};
1095+
expect(getReservationUnitPrice(input)).toBe("20,00 € / tunti");
1096+
});
1097+
test("future change in tax for free uses future price", () => {
1098+
const date = addDays(new Date(), 15);
1099+
const input = {
1100+
pricingDate: date,
1101+
reservationUnit: {
1102+
pricings: [
1103+
constructPricing({
1104+
begins: addDays(new Date(), -10),
1105+
status: Status.Active,
1106+
pricingType: PricingType.Free,
1107+
}),
1108+
constructPricing({
1109+
begins: addDays(new Date(), 10),
1110+
highestPrice: 25,
1111+
taxPercentage: 25.5,
1112+
status: Status.Future,
1113+
}),
1114+
],
1115+
},
1116+
};
1117+
expect(getReservationUnitPrice(input)).toBe("25,00 € / tunti");
1118+
});
10651119
});
10661120

10671121
describe("isReservationUnitPaidInFuture", () => {

apps/ui/modules/reservationUnit.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ export function getReservationUnitPrice(
335335
if (
336336
futurePricing &&
337337
activePricing &&
338-
futurePricing.taxPercentage.value !== activePricing.taxPercentage.value
338+
futurePricing.taxPercentage.value !== activePricing.taxPercentage.value &&
339+
isReservationUnitPaid([activePricing])
339340
) {
340341
pricing = activePricing;
341342
}

0 commit comments

Comments
 (0)