Merged in chore/regular-price-tests (pull request #3075)
chore: Add tests for regular price calculations * Add tests for calculateRegularPrice * Add tests for getRegularPrice * Add multiroom test Approved-by: Joakim Jäderberg Approved-by: Linus Flood
This commit is contained in:
@@ -12,7 +12,6 @@ import type { BreakfastPackage } from "@scandic-hotels/trpc/routers/hotels/schem
|
||||
import type { Packages } from "@scandic-hotels/trpc/types/packages"
|
||||
import type {
|
||||
CorporateChequeProduct,
|
||||
PriceProduct,
|
||||
Product,
|
||||
} from "@scandic-hotels/trpc/types/roomAvailability"
|
||||
import type { User } from "@scandic-hotels/trpc/types/user"
|
||||
@@ -456,12 +455,16 @@ export function getVoucherPrice(rooms: PriceCalculationRoom[], nights: number) {
|
||||
type PriceCalculationRoom = {
|
||||
adults: number
|
||||
breakfast:
|
||||
| { localPrice: { price: number; currency?: CurrencyEnum } }
|
||||
| {
|
||||
localPrice: { price: number; currency?: CurrencyEnum }
|
||||
requestedPrice?: { price: number; currency?: CurrencyEnum }
|
||||
}
|
||||
| false
|
||||
| undefined
|
||||
roomFeatures:
|
||||
| {
|
||||
localPrice: { totalPrice: number; currency?: CurrencyEnum }
|
||||
requestedPrice: { totalPrice: number; currency?: CurrencyEnum }
|
||||
}[]
|
||||
| null
|
||||
| undefined
|
||||
@@ -518,14 +521,45 @@ export function getRedemptionPrice(
|
||||
)
|
||||
}
|
||||
|
||||
interface TRoomPriceProduct extends TRoom {
|
||||
roomRate: PriceProduct
|
||||
type RegularPriceCalculationRoom = PriceCalculationRoom & {
|
||||
guest: {
|
||||
join: boolean
|
||||
membershipNo?: string | null
|
||||
}
|
||||
}
|
||||
type RegularRoomLocalPrice = {
|
||||
price: number
|
||||
currency: CurrencyEnum
|
||||
pricePerStay: number
|
||||
pricePerNight: number
|
||||
regularPricePerStay: number
|
||||
}
|
||||
type RegularRoomRequestedPrice = {
|
||||
price: number
|
||||
currency: CurrencyEnum
|
||||
pricePerStay: number
|
||||
}
|
||||
type GetRegularPriceRoom = RegularPriceCalculationRoom & {
|
||||
roomRate: {
|
||||
member: {
|
||||
localPrice: RegularRoomLocalPrice
|
||||
requestedPrice: RegularRoomRequestedPrice
|
||||
}
|
||||
public: {
|
||||
localPrice: RegularRoomLocalPrice
|
||||
requestedPrice: RegularRoomRequestedPrice
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getRegularPrice(rooms: TRoom[], isMember: boolean, nights: number) {
|
||||
export function getRegularPrice(
|
||||
rooms: RegularPriceCalculationRoom[],
|
||||
isMember: boolean,
|
||||
nights: number
|
||||
) {
|
||||
const totalPrice = rooms
|
||||
.filter(
|
||||
(room): room is TRoomPriceProduct =>
|
||||
(room): room is GetRegularPriceRoom =>
|
||||
"member" in room.roomRate || "public" in room.roomRate
|
||||
)
|
||||
.reduce<Price>(
|
||||
|
||||
Reference in New Issue
Block a user