Merged in chore/price-calculation-tests (pull request #3072)
chore: Add more price calculation tests * Add tests and refactor types for getVoucherPrice * Add tests for sumPackagesRequestedPrice * Add tests for calculateVat Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -14,7 +14,6 @@ import type {
|
||||
CorporateChequeProduct,
|
||||
PriceProduct,
|
||||
Product,
|
||||
VoucherProduct,
|
||||
} from "@scandic-hotels/trpc/types/roomAvailability"
|
||||
import type { User } from "@scandic-hotels/trpc/types/user"
|
||||
|
||||
@@ -417,13 +416,17 @@ function getCorporateChequePrice(rooms: TRoom[], nights: number) {
|
||||
)
|
||||
}
|
||||
|
||||
interface TRoomVoucher extends TRoom {
|
||||
roomRate: VoucherProduct
|
||||
type VoucherRoom = PriceCalculationRoom & {
|
||||
roomRate: {
|
||||
voucher: {
|
||||
numberOfVouchers: number
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getVoucherPrice(rooms: TRoom[], nights: number) {
|
||||
export function getVoucherPrice(rooms: PriceCalculationRoom[], nights: number) {
|
||||
return rooms
|
||||
.filter((room): room is TRoomVoucher => "voucher" in room.roomRate)
|
||||
.filter((room): room is VoucherRoom => "voucher" in room.roomRate)
|
||||
.reduce<Price>(
|
||||
(total, room) => {
|
||||
const voucher = room.roomRate.voucher
|
||||
@@ -450,7 +453,7 @@ function getVoucherPrice(rooms: TRoom[], nights: number) {
|
||||
)
|
||||
}
|
||||
|
||||
type GetRedemptionPriceRoom = {
|
||||
type PriceCalculationRoom = {
|
||||
adults: number
|
||||
breakfast:
|
||||
| { localPrice: { price: number; currency?: CurrencyEnum } }
|
||||
@@ -465,7 +468,7 @@ type GetRedemptionPriceRoom = {
|
||||
// We don't care about roomRate unless it's RedemptionProduct
|
||||
roomRate: object
|
||||
}
|
||||
type RedemptionRoom = GetRedemptionPriceRoom & {
|
||||
type RedemptionRoom = PriceCalculationRoom & {
|
||||
roomRate: {
|
||||
redemption: {
|
||||
localPrice: {
|
||||
@@ -478,7 +481,7 @@ type RedemptionRoom = GetRedemptionPriceRoom & {
|
||||
}
|
||||
|
||||
export function getRedemptionPrice(
|
||||
rooms: GetRedemptionPriceRoom[],
|
||||
rooms: PriceCalculationRoom[],
|
||||
nights: number,
|
||||
pointsCurrency?: CurrencyEnum
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user