Merged in chore/add-tests-for-getCorporateChequePrice (pull request #3114)
chore: Add tests for getCorporateChequePrice * Add tests for getRequestedAdditionalPrice * simplify types * Add tests for getCorporateChequePrice Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -8,12 +8,7 @@ import { calculateRegularPrice } from "../../utils/calculateRegularPrice"
|
||||
import { sumPackages, sumPackagesRequestedPrice } from "../../utils/SelectRate"
|
||||
import { detailsStorageName } from "."
|
||||
|
||||
import type { BreakfastPackage } from "@scandic-hotels/trpc/routers/hotels/schemas/packages"
|
||||
import type { Packages } from "@scandic-hotels/trpc/types/packages"
|
||||
import type {
|
||||
CorporateChequeProduct,
|
||||
Product,
|
||||
} from "@scandic-hotels/trpc/types/roomAvailability"
|
||||
import type { Product } from "@scandic-hotels/trpc/types/roomAvailability"
|
||||
import type { User } from "@scandic-hotels/trpc/types/user"
|
||||
|
||||
import type { Price } from "../../types/price"
|
||||
@@ -315,12 +310,20 @@ export function getAdditionalPrice(
|
||||
}
|
||||
}
|
||||
|
||||
function getRequestedAdditionalPrice(
|
||||
export function getRequestedAdditionalPrice(
|
||||
total: Price,
|
||||
adults: number,
|
||||
breakfast: BreakfastPackage | false | undefined,
|
||||
breakfast:
|
||||
| {
|
||||
requestedPrice?: { price: number; currency?: CurrencyEnum }
|
||||
}
|
||||
| false
|
||||
| undefined,
|
||||
nights: number,
|
||||
packages: Packages | null,
|
||||
packages:
|
||||
| { requestedPrice: { totalPrice: number; currency?: CurrencyEnum } }[]
|
||||
| null
|
||||
| undefined,
|
||||
cheques: number,
|
||||
additionalPrice = 0,
|
||||
additionalPriceCurrency: CurrencyEnum | null | undefined
|
||||
@@ -362,14 +365,30 @@ type TRoom = Pick<
|
||||
"adults" | "breakfast" | "guest" | "roomFeatures" | "roomRate"
|
||||
>
|
||||
|
||||
interface TRoomCorporateCheque extends TRoom {
|
||||
roomRate: CorporateChequeProduct
|
||||
type CorporateCheckRoom = PriceCalculationRoom & {
|
||||
roomRate: {
|
||||
corporateCheque: {
|
||||
localPrice: {
|
||||
numberOfCheques: number
|
||||
additionalPricePerStay: number
|
||||
currency?: CurrencyEnum
|
||||
}
|
||||
requestedPrice?: {
|
||||
numberOfCheques: number
|
||||
additionalPricePerStay: number
|
||||
currency?: CurrencyEnum
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getCorporateChequePrice(rooms: TRoom[], nights: number) {
|
||||
export function getCorporateChequePrice(
|
||||
rooms: PriceCalculationRoom[],
|
||||
nights: number
|
||||
) {
|
||||
return rooms
|
||||
.filter(
|
||||
(room): room is TRoomCorporateCheque => "corporateCheque" in room.roomRate
|
||||
(room): room is CorporateCheckRoom => "corporateCheque" in room.roomRate
|
||||
)
|
||||
.reduce<Price>(
|
||||
(total, room) => {
|
||||
|
||||
Reference in New Issue
Block a user