Merged in chore/add-tests-to-getAdditionalPrice (pull request #3065)

chore: Refactor types and add tests to parts of price calcuations

* Add tests to sumPackages

* Refactor types and add tests to getAdditionalPrice

* Don't always generate coverage

* Add tests and refactor types of getRedemptionPrice


Approved-by: Joakim Jäderberg
This commit is contained in:
Anton Gunnarsson
2025-11-04 12:09:04 +00:00
parent fa10abbe78
commit dc42a22513
6 changed files with 566 additions and 15 deletions

View File

@@ -1,9 +1,10 @@
import { describe, expect, it } from "vitest"
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
import { dt } from "@scandic-hotels/common/dt"
import { filterOverlappingDates } from "./index"
import { filterOverlappingDates, sumPackages } from "./index"
import type { specialAlertsSchema } from "@scandic-hotels/trpc/routers/hotels/schemas/hotel/specialAlerts"
import type { z } from "zod"
@@ -71,3 +72,29 @@ describe("filterOverlappingDates", () => {
expect(result).toHaveLength(0)
})
})
describe("sumPackages", () => {
it("returns 0 price for null packages", () => {
const result = sumPackages(null)
expect(result).toEqual({ currency: undefined, price: 0 })
})
it("returns 0 price for undefined packages", () => {
const result = sumPackages(undefined)
expect(result).toEqual({ currency: undefined, price: 0 })
})
it("returns 0 price for empty packages", () => {
const result = sumPackages([])
expect(result).toEqual({ currency: undefined, price: 0 })
})
it("sums prices of packages", () => {
const result = sumPackages([
{ localPrice: { totalPrice: 100, currency: CurrencyEnum.SEK } },
{ localPrice: { totalPrice: 200, currency: CurrencyEnum.SEK } },
{ localPrice: { totalPrice: 50, currency: CurrencyEnum.SEK } },
])
expect(result).toEqual({ currency: CurrencyEnum.SEK, price: 350 })
})
})

View File

@@ -8,7 +8,8 @@ import { ChildBedMapEnum } from "@scandic-hotels/trpc/enums/childBedMapEnum"
import { ChildBedTypeEnum } from "@scandic-hotels/trpc/enums/childBedTypeEnum"
import { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter"
import type { Package, Packages } from "@scandic-hotels/trpc/types/packages"
import type { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
import type { Packages } from "@scandic-hotels/trpc/types/packages"
import type { JSX } from "react"
import type { RoomPackageCodes } from "../../types/components/selectRate/roomFilter"
@@ -39,7 +40,10 @@ export const invertedBedTypeMap: Record<ChildBedTypeEnum, string> = {
}
export function sumPackages(
packages: Pick<Package, "localPrice">[] | undefined | null
packages:
| { localPrice: { totalPrice: number; currency?: CurrencyEnum } }[]
| null
| undefined
) {
if (!packages || !packages.length) {
return {