feat: Refactor enter details price calculation * Refactor getTotalPrice and child functions * Move price calculations from helper file to specific file Approved-by: Linus Flood
2018 lines
46 KiB
TypeScript
2018 lines
46 KiB
TypeScript
import { describe, expect, it } from "vitest"
|
|
|
|
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
|
|
import { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter"
|
|
|
|
import {
|
|
getAdditionalPrice,
|
|
getCorporateChequePrice,
|
|
getRedemptionPrice,
|
|
getRegularPrice,
|
|
getRequestedAdditionalPrice,
|
|
getTotalPrice,
|
|
getVoucherPrice,
|
|
} from "./priceCalculations"
|
|
|
|
type GetAdditionalPriceParams = Parameters<typeof getAdditionalPrice>
|
|
describe("getAdditionalPrice", () => {
|
|
it("should calculate additional price correctly with only additional price", () => {
|
|
const total: GetAdditionalPriceParams[0] = {
|
|
local: {
|
|
additionalPrice: 0,
|
|
additionalPriceCurrency: CurrencyEnum.CC,
|
|
},
|
|
}
|
|
const adults = 1
|
|
const nights = 1
|
|
const breakfast = undefined
|
|
const packages = undefined
|
|
const additionalPrice = 100
|
|
const additionalPriceCurrency = CurrencyEnum.SEK
|
|
|
|
getAdditionalPrice(
|
|
total,
|
|
adults,
|
|
breakfast,
|
|
nights,
|
|
packages,
|
|
additionalPrice,
|
|
additionalPriceCurrency
|
|
)
|
|
|
|
expect(total.local.additionalPrice).toBe(100)
|
|
})
|
|
|
|
it("should set additional price currency correctly when missing in total", () => {
|
|
const total: GetAdditionalPriceParams[0] = {
|
|
local: {
|
|
additionalPrice: 0,
|
|
},
|
|
}
|
|
const adults = 1
|
|
const nights = 1
|
|
const breakfast = undefined
|
|
const packages = undefined
|
|
const additionalPrice = 100
|
|
const additionalPriceCurrency = CurrencyEnum.SEK
|
|
|
|
getAdditionalPrice(
|
|
total,
|
|
adults,
|
|
breakfast,
|
|
nights,
|
|
packages,
|
|
additionalPrice,
|
|
additionalPriceCurrency
|
|
)
|
|
|
|
expect(total.local.additionalPriceCurrency).toBe(CurrencyEnum.SEK)
|
|
})
|
|
|
|
it("should calculate price correctly with breakfast", () => {
|
|
const total: GetAdditionalPriceParams[0] = {
|
|
local: {
|
|
additionalPrice: 0,
|
|
},
|
|
}
|
|
const adults = 2
|
|
const nights = 2
|
|
const breakfast = { localPrice: { price: 50, currency: CurrencyEnum.SEK } }
|
|
const packages: never[] = []
|
|
|
|
getAdditionalPrice(total, adults, breakfast, nights, packages)
|
|
|
|
expect(total.local.additionalPrice).toBe(200)
|
|
})
|
|
|
|
it("should calculate price correctly with packages", () => {
|
|
const total: GetAdditionalPriceParams[0] = {
|
|
local: {
|
|
additionalPrice: 0,
|
|
},
|
|
}
|
|
const adults = 2
|
|
const nights = 2
|
|
const breakfast = undefined
|
|
const packages = [
|
|
{
|
|
localPrice: { totalPrice: 50, currency: CurrencyEnum.SEK },
|
|
},
|
|
{
|
|
localPrice: { totalPrice: 25, currency: CurrencyEnum.SEK },
|
|
},
|
|
]
|
|
|
|
getAdditionalPrice(total, adults, breakfast, nights, packages)
|
|
|
|
expect(total.local.additionalPrice).toBe(75)
|
|
})
|
|
|
|
it("should calculate price correctly with breakfast, packages and additionalPrice", () => {
|
|
const total: GetAdditionalPriceParams[0] = {
|
|
local: {
|
|
additionalPrice: 0,
|
|
},
|
|
}
|
|
const adults = 2
|
|
const nights = 2
|
|
const breakfast = { localPrice: { price: 50, currency: CurrencyEnum.SEK } }
|
|
const packages = [
|
|
{
|
|
localPrice: { totalPrice: 50, currency: CurrencyEnum.SEK },
|
|
},
|
|
{
|
|
localPrice: { totalPrice: 25, currency: CurrencyEnum.SEK },
|
|
},
|
|
]
|
|
const additionalPrice = 33
|
|
const additionalPriceCurrency = CurrencyEnum.SEK
|
|
|
|
getAdditionalPrice(
|
|
total,
|
|
adults,
|
|
breakfast,
|
|
nights,
|
|
packages,
|
|
additionalPrice,
|
|
additionalPriceCurrency
|
|
)
|
|
|
|
expect(total.local.additionalPrice).toBe(308)
|
|
})
|
|
})
|
|
|
|
type GetRequestedAdditionalPriceParams = Parameters<
|
|
typeof getRequestedAdditionalPrice
|
|
>
|
|
describe("getRequestedAdditionalPrice", () => {
|
|
it("should initialize requested object when missing and add cheques to price", () => {
|
|
const total: GetRequestedAdditionalPriceParams[0] = {
|
|
local: {
|
|
price: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
}
|
|
const adults = 1
|
|
const nights = 1
|
|
const breakfast = undefined
|
|
const packages = null
|
|
const cheques = 5
|
|
const additionalPrice = 0
|
|
const additionalPriceCurrency = undefined
|
|
|
|
getRequestedAdditionalPrice(
|
|
total,
|
|
adults,
|
|
breakfast,
|
|
nights,
|
|
packages,
|
|
cheques,
|
|
additionalPrice,
|
|
additionalPriceCurrency
|
|
)
|
|
|
|
expect(total.requested).toEqual({
|
|
currency: CurrencyEnum.CC,
|
|
price: 5,
|
|
additionalPrice: 0,
|
|
})
|
|
})
|
|
|
|
it("should add to existing requested price", () => {
|
|
const total: GetRequestedAdditionalPriceParams[0] = {
|
|
local: {
|
|
price: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
requested: {
|
|
currency: CurrencyEnum.CC,
|
|
price: 10,
|
|
},
|
|
}
|
|
const adults = 1
|
|
const nights = 1
|
|
const breakfast = undefined
|
|
const packages = null
|
|
const cheques = 5
|
|
const additionalPrice = 0
|
|
const additionalPriceCurrency = undefined
|
|
|
|
getRequestedAdditionalPrice(
|
|
total,
|
|
adults,
|
|
breakfast,
|
|
nights,
|
|
packages,
|
|
cheques,
|
|
additionalPrice,
|
|
additionalPriceCurrency
|
|
)
|
|
|
|
expect(total.requested?.price).toBe(15)
|
|
})
|
|
|
|
it("should calculate additional price with only additionalPrice parameter", () => {
|
|
const total: GetRequestedAdditionalPriceParams[0] = {
|
|
local: {
|
|
price: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
}
|
|
const adults = 1
|
|
const nights = 1
|
|
const breakfast = undefined
|
|
const packages = null
|
|
const cheques = 0
|
|
const additionalPrice = 50
|
|
const additionalPriceCurrency = CurrencyEnum.EUR
|
|
|
|
getRequestedAdditionalPrice(
|
|
total,
|
|
adults,
|
|
breakfast,
|
|
nights,
|
|
packages,
|
|
cheques,
|
|
additionalPrice,
|
|
additionalPriceCurrency
|
|
)
|
|
|
|
expect(total.requested).toEqual({
|
|
currency: CurrencyEnum.CC,
|
|
price: 0,
|
|
additionalPrice: 50,
|
|
additionalPriceCurrency: CurrencyEnum.EUR,
|
|
})
|
|
})
|
|
|
|
it("should calculate additional price with breakfast", () => {
|
|
const total: GetRequestedAdditionalPriceParams[0] = {
|
|
local: {
|
|
price: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
}
|
|
const adults = 2
|
|
const nights = 3
|
|
const breakfast = {
|
|
requestedPrice: {
|
|
price: 10,
|
|
currency: CurrencyEnum.EUR,
|
|
},
|
|
}
|
|
const packages = null
|
|
const cheques = 0
|
|
const additionalPrice = 0
|
|
const additionalPriceCurrency = undefined
|
|
|
|
getRequestedAdditionalPrice(
|
|
total,
|
|
adults,
|
|
breakfast,
|
|
nights,
|
|
packages,
|
|
cheques,
|
|
additionalPrice,
|
|
additionalPriceCurrency
|
|
)
|
|
|
|
expect(total.requested?.additionalPrice).toBe(60)
|
|
})
|
|
|
|
it("should calculate additional price with packages", () => {
|
|
const total: GetRequestedAdditionalPriceParams[0] = {
|
|
local: {
|
|
price: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
}
|
|
const adults = 1
|
|
const nights = 1
|
|
const breakfast = undefined
|
|
const packages = [
|
|
{
|
|
code: RoomPackageCodeEnum.PET_ROOM,
|
|
description: "Package 1",
|
|
localPrice: {
|
|
totalPrice: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
price: 100,
|
|
},
|
|
requestedPrice: {
|
|
totalPrice: 25,
|
|
currency: CurrencyEnum.EUR,
|
|
price: 25,
|
|
},
|
|
inventories: [],
|
|
itemCode: "PKG1",
|
|
},
|
|
{
|
|
code: RoomPackageCodeEnum.ALLERGY_ROOM,
|
|
description: "Package 2",
|
|
localPrice: {
|
|
totalPrice: 80,
|
|
currency: CurrencyEnum.SEK,
|
|
price: 80,
|
|
},
|
|
requestedPrice: {
|
|
totalPrice: 15,
|
|
currency: CurrencyEnum.EUR,
|
|
price: 15,
|
|
},
|
|
inventories: [],
|
|
itemCode: "PKG2",
|
|
},
|
|
]
|
|
const cheques = 0
|
|
const additionalPrice = 0
|
|
const additionalPriceCurrency = undefined
|
|
|
|
getRequestedAdditionalPrice(
|
|
total,
|
|
adults,
|
|
breakfast,
|
|
nights,
|
|
packages,
|
|
cheques,
|
|
additionalPrice,
|
|
additionalPriceCurrency
|
|
)
|
|
|
|
expect(total.requested?.additionalPrice).toBe(40)
|
|
})
|
|
|
|
it("should calculate combined price with breakfast, packages, and additionalPrice", () => {
|
|
const total: GetRequestedAdditionalPriceParams[0] = {
|
|
local: {
|
|
price: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
}
|
|
const adults = 2
|
|
const nights = 2
|
|
const breakfast = {
|
|
requestedPrice: {
|
|
price: 10,
|
|
currency: CurrencyEnum.EUR,
|
|
},
|
|
}
|
|
const packages = [
|
|
{
|
|
code: RoomPackageCodeEnum.PET_ROOM,
|
|
description: "Package 1",
|
|
localPrice: {
|
|
totalPrice: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
price: 100,
|
|
},
|
|
requestedPrice: {
|
|
totalPrice: 20,
|
|
currency: CurrencyEnum.EUR,
|
|
price: 20,
|
|
},
|
|
inventories: [],
|
|
itemCode: "PKG1",
|
|
},
|
|
]
|
|
const cheques = 3
|
|
const additionalPrice = 15
|
|
const additionalPriceCurrency = CurrencyEnum.EUR
|
|
|
|
getRequestedAdditionalPrice(
|
|
total,
|
|
adults,
|
|
breakfast,
|
|
nights,
|
|
packages,
|
|
cheques,
|
|
additionalPrice,
|
|
additionalPriceCurrency
|
|
)
|
|
|
|
expect(total.requested).toEqual({
|
|
currency: CurrencyEnum.CC,
|
|
price: 3,
|
|
additionalPrice: 75,
|
|
additionalPriceCurrency: CurrencyEnum.EUR,
|
|
})
|
|
})
|
|
|
|
it("should set currency from additionalPriceCurrency when provided", () => {
|
|
const total: GetRequestedAdditionalPriceParams[0] = {
|
|
local: {
|
|
price: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
}
|
|
const adults = 1
|
|
const nights = 1
|
|
const breakfast = undefined
|
|
const packages = null
|
|
const cheques = 0
|
|
const additionalPrice = 50
|
|
const additionalPriceCurrency = CurrencyEnum.EUR
|
|
|
|
getRequestedAdditionalPrice(
|
|
total,
|
|
adults,
|
|
breakfast,
|
|
nights,
|
|
packages,
|
|
cheques,
|
|
additionalPrice,
|
|
additionalPriceCurrency
|
|
)
|
|
|
|
expect(total.requested?.additionalPriceCurrency).toBe(CurrencyEnum.EUR)
|
|
})
|
|
|
|
it("should set currency from packages when additionalPriceCurrency not provided", () => {
|
|
const total: GetRequestedAdditionalPriceParams[0] = {
|
|
local: {
|
|
price: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
}
|
|
const adults = 1
|
|
const nights = 1
|
|
const breakfast = undefined
|
|
const packages = [
|
|
{
|
|
code: RoomPackageCodeEnum.PET_ROOM,
|
|
description: "Package 1",
|
|
localPrice: {
|
|
totalPrice: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
price: 100,
|
|
},
|
|
requestedPrice: {
|
|
totalPrice: 20,
|
|
currency: CurrencyEnum.EUR,
|
|
price: 20,
|
|
},
|
|
inventories: [],
|
|
itemCode: "PKG1",
|
|
},
|
|
]
|
|
const cheques = 0
|
|
const additionalPrice = 0
|
|
const additionalPriceCurrency = undefined
|
|
|
|
getRequestedAdditionalPrice(
|
|
total,
|
|
adults,
|
|
breakfast,
|
|
nights,
|
|
packages,
|
|
cheques,
|
|
additionalPrice,
|
|
additionalPriceCurrency
|
|
)
|
|
|
|
expect(total.requested?.additionalPriceCurrency).toBe(CurrencyEnum.EUR)
|
|
})
|
|
|
|
it("should set currency from breakfast when no other currency available", () => {
|
|
const total: GetRequestedAdditionalPriceParams[0] = {
|
|
local: {
|
|
price: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
}
|
|
const adults = 1
|
|
const nights = 1
|
|
const breakfast = {
|
|
requestedPrice: {
|
|
price: 10,
|
|
currency: CurrencyEnum.EUR,
|
|
},
|
|
}
|
|
const packages = null
|
|
const cheques = 0
|
|
const additionalPrice = 0
|
|
const additionalPriceCurrency = undefined
|
|
|
|
getRequestedAdditionalPrice(
|
|
total,
|
|
adults,
|
|
breakfast,
|
|
nights,
|
|
packages,
|
|
cheques,
|
|
additionalPrice,
|
|
additionalPriceCurrency
|
|
)
|
|
|
|
expect(total.requested?.additionalPriceCurrency).toBe(CurrencyEnum.EUR)
|
|
})
|
|
|
|
it("should not override existing additionalPriceCurrency", () => {
|
|
const total: GetRequestedAdditionalPriceParams[0] = {
|
|
local: {
|
|
price: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
requested: {
|
|
currency: CurrencyEnum.CC,
|
|
price: 0,
|
|
additionalPriceCurrency: CurrencyEnum.NOK,
|
|
},
|
|
}
|
|
const adults = 1
|
|
const nights = 1
|
|
const breakfast = {
|
|
requestedPrice: {
|
|
price: 10,
|
|
currency: CurrencyEnum.EUR,
|
|
},
|
|
}
|
|
const packages = null
|
|
const cheques = 0
|
|
const additionalPrice = 0
|
|
const additionalPriceCurrency = undefined
|
|
|
|
getRequestedAdditionalPrice(
|
|
total,
|
|
adults,
|
|
breakfast,
|
|
nights,
|
|
packages,
|
|
cheques,
|
|
additionalPrice,
|
|
additionalPriceCurrency
|
|
)
|
|
|
|
expect(total.requested?.additionalPriceCurrency).toBe(CurrencyEnum.NOK)
|
|
})
|
|
|
|
it("should handle breakfast without requestedPrice", () => {
|
|
const total: GetRequestedAdditionalPriceParams[0] = {
|
|
local: {
|
|
price: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
}
|
|
const adults = 2
|
|
const nights = 2
|
|
const breakfast = {
|
|
requestedPrice: {
|
|
price: 0,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
}
|
|
const packages = null
|
|
const cheques = 0
|
|
const additionalPrice = 0
|
|
const additionalPriceCurrency = undefined
|
|
|
|
getRequestedAdditionalPrice(
|
|
total,
|
|
adults,
|
|
breakfast,
|
|
nights,
|
|
packages,
|
|
cheques,
|
|
additionalPrice,
|
|
additionalPriceCurrency
|
|
)
|
|
|
|
expect(total.requested?.additionalPrice).toBe(0)
|
|
})
|
|
|
|
it("should handle false breakfast value", () => {
|
|
const total: GetRequestedAdditionalPriceParams[0] = {
|
|
local: {
|
|
price: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
}
|
|
const adults = 2
|
|
const nights = 2
|
|
const breakfast = false
|
|
const packages = null
|
|
const cheques = 0
|
|
const additionalPrice = 0
|
|
const additionalPriceCurrency = undefined
|
|
|
|
getRequestedAdditionalPrice(
|
|
total,
|
|
adults,
|
|
breakfast,
|
|
nights,
|
|
packages,
|
|
cheques,
|
|
additionalPrice,
|
|
additionalPriceCurrency
|
|
)
|
|
|
|
expect(total.requested?.additionalPrice).toBe(0)
|
|
})
|
|
})
|
|
|
|
type GetCorporateChequePriceParams = Parameters<typeof getCorporateChequePrice>
|
|
describe("getCorporateChequePrice", () => {
|
|
it("returns price 0 when rooms are empty", () => {
|
|
const nights = 1
|
|
const result = getCorporateChequePrice([], nights)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
price: 0,
|
|
currency: CurrencyEnum.CC,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("returns price for single room with corporate cheque", () => {
|
|
const nights = 2
|
|
const rooms: GetCorporateChequePriceParams[0] = [
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
corporateCheque: {
|
|
localPrice: {
|
|
numberOfCheques: 3,
|
|
additionalPricePerStay: 0,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
]
|
|
|
|
const result = getCorporateChequePrice(rooms, nights)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
price: 3,
|
|
currency: CurrencyEnum.CC,
|
|
additionalPrice: 0,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("calculates price with additionalPricePerStay", () => {
|
|
const nights = 2
|
|
const rooms: GetCorporateChequePriceParams[0] = [
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
corporateCheque: {
|
|
localPrice: {
|
|
numberOfCheques: 2,
|
|
additionalPricePerStay: 150,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
]
|
|
|
|
const result = getCorporateChequePrice(rooms, nights)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
price: 2,
|
|
currency: CurrencyEnum.CC,
|
|
additionalPrice: 150,
|
|
additionalPriceCurrency: CurrencyEnum.SEK,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("calculates price with breakfast", () => {
|
|
const nights = 2
|
|
const rooms: GetCorporateChequePriceParams[0] = [
|
|
{
|
|
adults: 2,
|
|
breakfast: {
|
|
localPrice: {
|
|
price: 50,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
corporateCheque: {
|
|
localPrice: {
|
|
numberOfCheques: 3,
|
|
additionalPricePerStay: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
]
|
|
|
|
const result = getCorporateChequePrice(rooms, nights)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
price: 3,
|
|
currency: CurrencyEnum.CC,
|
|
additionalPrice: 300,
|
|
additionalPriceCurrency: CurrencyEnum.SEK,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("calculates price with room features", () => {
|
|
const nights = 2
|
|
const rooms: GetCorporateChequePriceParams[0] = [
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [
|
|
{
|
|
localPrice: {
|
|
totalPrice: 75,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
requestedPrice: {
|
|
totalPrice: 10,
|
|
currency: CurrencyEnum.EUR,
|
|
},
|
|
},
|
|
],
|
|
roomRate: {
|
|
corporateCheque: {
|
|
localPrice: {
|
|
numberOfCheques: 2,
|
|
additionalPricePerStay: 50,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
]
|
|
|
|
const result = getCorporateChequePrice(rooms, nights)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
price: 2,
|
|
currency: CurrencyEnum.CC,
|
|
additionalPrice: 125,
|
|
additionalPriceCurrency: CurrencyEnum.SEK,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("calculates requested price when available", () => {
|
|
const nights = 2
|
|
const rooms: GetCorporateChequePriceParams[0] = [
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
corporateCheque: {
|
|
localPrice: {
|
|
numberOfCheques: 3,
|
|
additionalPricePerStay: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
requestedPrice: {
|
|
numberOfCheques: 2,
|
|
additionalPricePerStay: 15,
|
|
currency: CurrencyEnum.EUR,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
]
|
|
|
|
const result = getCorporateChequePrice(rooms, nights)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
price: 3,
|
|
currency: CurrencyEnum.CC,
|
|
additionalPrice: 100,
|
|
additionalPriceCurrency: CurrencyEnum.SEK,
|
|
},
|
|
requested: {
|
|
price: 2,
|
|
currency: CurrencyEnum.CC,
|
|
additionalPrice: 15,
|
|
additionalPriceCurrency: CurrencyEnum.EUR,
|
|
},
|
|
})
|
|
})
|
|
|
|
it("calculates requested price with breakfast", () => {
|
|
const nights = 2
|
|
const rooms: GetCorporateChequePriceParams[0] = [
|
|
{
|
|
adults: 2,
|
|
breakfast: {
|
|
localPrice: {
|
|
price: 40,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
requestedPrice: {
|
|
price: 5,
|
|
currency: CurrencyEnum.EUR,
|
|
},
|
|
},
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
corporateCheque: {
|
|
localPrice: {
|
|
numberOfCheques: 3,
|
|
additionalPricePerStay: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
requestedPrice: {
|
|
numberOfCheques: 2,
|
|
additionalPricePerStay: 10,
|
|
currency: CurrencyEnum.EUR,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
]
|
|
|
|
const result = getCorporateChequePrice(rooms, nights)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
price: 3,
|
|
currency: CurrencyEnum.CC,
|
|
additionalPrice: 260,
|
|
additionalPriceCurrency: CurrencyEnum.SEK,
|
|
},
|
|
requested: {
|
|
price: 2,
|
|
currency: CurrencyEnum.CC,
|
|
additionalPrice: 30,
|
|
additionalPriceCurrency: CurrencyEnum.EUR,
|
|
},
|
|
})
|
|
})
|
|
|
|
it("calculates price for multiple rooms", () => {
|
|
const nights = 1
|
|
const rooms: GetCorporateChequePriceParams[0] = [
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
corporateCheque: {
|
|
localPrice: {
|
|
numberOfCheques: 2,
|
|
additionalPricePerStay: 50,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
adults: 2,
|
|
breakfast: {
|
|
localPrice: {
|
|
price: 30,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
corporateCheque: {
|
|
localPrice: {
|
|
numberOfCheques: 3,
|
|
additionalPricePerStay: 75,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
requestedPrice: {
|
|
numberOfCheques: 2,
|
|
additionalPricePerStay: 10,
|
|
currency: CurrencyEnum.EUR,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
]
|
|
|
|
const result = getCorporateChequePrice(rooms, nights)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
price: 5,
|
|
currency: CurrencyEnum.CC,
|
|
additionalPrice: 185,
|
|
additionalPriceCurrency: CurrencyEnum.SEK,
|
|
},
|
|
requested: {
|
|
price: 2,
|
|
currency: CurrencyEnum.CC,
|
|
additionalPrice: 10,
|
|
additionalPriceCurrency: CurrencyEnum.EUR,
|
|
},
|
|
})
|
|
})
|
|
|
|
it("calculates combined price with breakfast and room features", () => {
|
|
const nights = 3
|
|
const rooms: GetCorporateChequePriceParams[0] = [
|
|
{
|
|
adults: 2,
|
|
breakfast: {
|
|
localPrice: {
|
|
price: 25,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
requestedPrice: {
|
|
price: 3,
|
|
currency: CurrencyEnum.EUR,
|
|
},
|
|
},
|
|
roomFeatures: [
|
|
{
|
|
localPrice: {
|
|
totalPrice: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
requestedPrice: {
|
|
totalPrice: 12,
|
|
currency: CurrencyEnum.EUR,
|
|
},
|
|
},
|
|
{
|
|
localPrice: {
|
|
totalPrice: 50,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
requestedPrice: {
|
|
totalPrice: 6,
|
|
currency: CurrencyEnum.EUR,
|
|
},
|
|
},
|
|
],
|
|
roomRate: {
|
|
corporateCheque: {
|
|
localPrice: {
|
|
numberOfCheques: 5,
|
|
additionalPricePerStay: 200,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
requestedPrice: {
|
|
numberOfCheques: 4,
|
|
additionalPricePerStay: 25,
|
|
currency: CurrencyEnum.EUR,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
]
|
|
|
|
const result = getCorporateChequePrice(rooms, nights)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
price: 5,
|
|
currency: CurrencyEnum.CC,
|
|
additionalPrice: 500,
|
|
additionalPriceCurrency: CurrencyEnum.SEK,
|
|
},
|
|
requested: {
|
|
price: 4,
|
|
currency: CurrencyEnum.CC,
|
|
additionalPrice: 61,
|
|
additionalPriceCurrency: CurrencyEnum.EUR,
|
|
},
|
|
})
|
|
})
|
|
})
|
|
|
|
describe("getRedemptionPrice", () => {
|
|
it("returns price 0 and default currency when rooms are empty", () => {
|
|
const result = getRedemptionPrice([], 1)
|
|
|
|
expect(result).toEqual({
|
|
local: { price: 0, currency: CurrencyEnum.POINTS },
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("returns price 0 and set currency when rooms are empty", () => {
|
|
const result = getRedemptionPrice([], 1, CurrencyEnum.EUROBONUS)
|
|
|
|
expect(result).toEqual({
|
|
local: { price: 0, currency: CurrencyEnum.EUROBONUS },
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("returns price for single room with redemption price", () => {
|
|
const nights = 1
|
|
const result = getRedemptionPrice(
|
|
[
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
redemption: {
|
|
localPrice: {
|
|
pointsPerStay: 100,
|
|
currency: CurrencyEnum.POINTS,
|
|
additionalPricePerStay: 0,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
nights
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
price: 100,
|
|
currency: CurrencyEnum.POINTS,
|
|
additionalPrice: 0,
|
|
additionalPriceCurrency: CurrencyEnum.POINTS,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("returns price for single room with multiple nights", () => {
|
|
const nights = 3
|
|
const result = getRedemptionPrice(
|
|
[
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
redemption: {
|
|
localPrice: {
|
|
pointsPerStay: 100,
|
|
currency: CurrencyEnum.POINTS,
|
|
additionalPricePerStay: 0,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
nights
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
price: 100,
|
|
currency: CurrencyEnum.POINTS,
|
|
additionalPrice: 0,
|
|
additionalPriceCurrency: CurrencyEnum.POINTS,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("returns price for multiple rooms with multiple nights", () => {
|
|
const nights = 3
|
|
const result = getRedemptionPrice(
|
|
[
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
redemption: {
|
|
localPrice: {
|
|
pointsPerStay: 100,
|
|
currency: CurrencyEnum.POINTS,
|
|
additionalPricePerStay: 0,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
redemption: {
|
|
localPrice: {
|
|
pointsPerStay: 150,
|
|
currency: CurrencyEnum.POINTS,
|
|
additionalPricePerStay: 0,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
nights
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
price: 250,
|
|
currency: CurrencyEnum.POINTS,
|
|
additionalPrice: 0,
|
|
additionalPriceCurrency: CurrencyEnum.POINTS,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("returns price and additionalPrice for single room with room features", () => {
|
|
const nights = 2
|
|
const result = getRedemptionPrice(
|
|
[
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [
|
|
{
|
|
localPrice: { totalPrice: 33 },
|
|
requestedPrice: { totalPrice: 33 },
|
|
},
|
|
],
|
|
roomRate: {
|
|
redemption: {
|
|
localPrice: {
|
|
pointsPerStay: 100,
|
|
currency: CurrencyEnum.POINTS,
|
|
additionalPricePerStay: 0,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
nights
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
price: 100,
|
|
currency: CurrencyEnum.POINTS,
|
|
additionalPrice: 33,
|
|
additionalPriceCurrency: CurrencyEnum.POINTS,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
})
|
|
|
|
describe("getVoucherPrice", () => {
|
|
it("returns price 0 and default currency when rooms are empty", () => {
|
|
const result = getVoucherPrice([], 1)
|
|
|
|
expect(result).toEqual({
|
|
local: { price: 0, currency: CurrencyEnum.Voucher },
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("returns price for single room with voucher price", () => {
|
|
const nights = 1
|
|
const result = getVoucherPrice(
|
|
[
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
voucher: {
|
|
numberOfVouchers: 1,
|
|
},
|
|
},
|
|
},
|
|
],
|
|
nights
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
price: 1,
|
|
currency: CurrencyEnum.Voucher,
|
|
additionalPrice: 0,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("returns price for single room with multiple nights", () => {
|
|
const nights = 3
|
|
const result = getVoucherPrice(
|
|
[
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
voucher: {
|
|
numberOfVouchers: 3,
|
|
},
|
|
},
|
|
},
|
|
],
|
|
nights
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
price: 3,
|
|
currency: CurrencyEnum.Voucher,
|
|
additionalPrice: 0,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("returns price for multiple rooms with multiple nights", () => {
|
|
const nights = 3
|
|
const result = getVoucherPrice(
|
|
[
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
voucher: {
|
|
numberOfVouchers: 3,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
voucher: {
|
|
numberOfVouchers: 2,
|
|
},
|
|
},
|
|
},
|
|
],
|
|
nights
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
price: 5,
|
|
currency: CurrencyEnum.Voucher,
|
|
additionalPrice: 0,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
})
|
|
|
|
describe("getRegularPrice", () => {
|
|
it("returns price 0 for empty rooms", () => {
|
|
const isMember = false
|
|
const nights = 1
|
|
const result = getRegularPrice([], isMember, nights)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
currency: CurrencyEnum.Unknown,
|
|
price: 0,
|
|
regularPrice: 0,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("calculates regular price for non-member", () => {
|
|
const isMember = false
|
|
const nights = 2
|
|
const guest = { join: false }
|
|
const result = getRegularPrice(
|
|
[
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: null,
|
|
guest,
|
|
roomRate: {
|
|
public: {
|
|
localPrice: {
|
|
pricePerNight: 100,
|
|
pricePerStay: 0,
|
|
regularPricePerStay: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
member: {
|
|
localPrice: {
|
|
pricePerNight: 50,
|
|
pricePerStay: 0,
|
|
regularPricePerStay: 50,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
isMember,
|
|
nights
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
currency: CurrencyEnum.SEK,
|
|
price: 0,
|
|
regularPrice: 100,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("calculates regular price for member", () => {
|
|
const isMember = true
|
|
const nights = 2
|
|
const guest = { join: false }
|
|
const result = getRegularPrice(
|
|
[
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
guest,
|
|
roomRate: {
|
|
public: {
|
|
localPrice: {
|
|
pricePerNight: 100,
|
|
pricePerStay: 0,
|
|
regularPricePerStay: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
member: {
|
|
localPrice: {
|
|
pricePerNight: 50,
|
|
pricePerStay: 0,
|
|
regularPricePerStay: 50,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
isMember,
|
|
nights
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
currency: CurrencyEnum.SEK,
|
|
price: 0,
|
|
regularPrice: 100,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("calculates regular price for member without public rate", () => {
|
|
const isMember = true
|
|
const nights = 2
|
|
const guest = { join: false }
|
|
const result = getRegularPrice(
|
|
[
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
guest,
|
|
roomRate: {
|
|
member: {
|
|
localPrice: {
|
|
pricePerNight: 50,
|
|
pricePerStay: 0,
|
|
regularPricePerStay: 50,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
public: null,
|
|
},
|
|
},
|
|
],
|
|
isMember,
|
|
nights
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
currency: CurrencyEnum.SEK,
|
|
price: 0,
|
|
regularPrice: 50,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("calculates regular price for non-member without member rate", () => {
|
|
const isMember = false
|
|
const nights = 2
|
|
const guest = { join: false }
|
|
const result = getRegularPrice(
|
|
[
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
guest,
|
|
roomRate: {
|
|
public: {
|
|
localPrice: {
|
|
pricePerNight: 50,
|
|
pricePerStay: 0,
|
|
regularPricePerStay: 50,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
member: null,
|
|
},
|
|
},
|
|
],
|
|
isMember,
|
|
nights
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
currency: CurrencyEnum.SEK,
|
|
price: 0,
|
|
regularPrice: 50,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("calculates regular price for non-member with breakfast", () => {
|
|
const isMember = false
|
|
const nights = 2
|
|
const guest = { join: false }
|
|
const result = getRegularPrice(
|
|
[
|
|
{
|
|
adults: 1,
|
|
breakfast: { localPrice: { price: 20, currency: CurrencyEnum.SEK } },
|
|
roomFeatures: [],
|
|
guest,
|
|
roomRate: {
|
|
public: {
|
|
localPrice: {
|
|
pricePerNight: 100,
|
|
pricePerStay: 0,
|
|
regularPricePerStay: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
member: {
|
|
localPrice: {
|
|
pricePerNight: 50,
|
|
pricePerStay: 0,
|
|
regularPricePerStay: 50,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
isMember,
|
|
nights
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
currency: CurrencyEnum.SEK,
|
|
price: 40,
|
|
regularPrice: 140,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("calculates regular price for non-member with breakfast and room features", () => {
|
|
const isMember = false
|
|
const nights = 2
|
|
const guest = { join: false }
|
|
const result = getRegularPrice(
|
|
[
|
|
{
|
|
adults: 1,
|
|
breakfast: { localPrice: { price: 20, currency: CurrencyEnum.SEK } },
|
|
roomFeatures: [
|
|
{
|
|
localPrice: { totalPrice: 3, currency: CurrencyEnum.SEK },
|
|
requestedPrice: { totalPrice: 3, currency: CurrencyEnum.SEK },
|
|
},
|
|
{
|
|
localPrice: { totalPrice: 7, currency: CurrencyEnum.SEK },
|
|
requestedPrice: { totalPrice: 7, currency: CurrencyEnum.SEK },
|
|
},
|
|
],
|
|
guest,
|
|
roomRate: {
|
|
public: {
|
|
localPrice: {
|
|
pricePerNight: 100,
|
|
pricePerStay: 0,
|
|
regularPricePerStay: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
member: {
|
|
localPrice: {
|
|
pricePerNight: 50,
|
|
pricePerStay: 0,
|
|
regularPricePerStay: 50,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
isMember,
|
|
nights
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
currency: CurrencyEnum.SEK,
|
|
price: 50,
|
|
regularPrice: 150,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("calculates regular price to 0 when price is same or larger than regular price", () => {
|
|
const isMember = false
|
|
const nights = 2
|
|
const guest = { join: false }
|
|
const result = getRegularPrice(
|
|
[
|
|
{
|
|
adults: 1,
|
|
breakfast: { localPrice: { price: 0, currency: CurrencyEnum.SEK } },
|
|
roomFeatures: [
|
|
{
|
|
localPrice: { totalPrice: 100, currency: CurrencyEnum.SEK },
|
|
requestedPrice: { totalPrice: 3, currency: CurrencyEnum.SEK },
|
|
},
|
|
],
|
|
guest,
|
|
roomRate: {
|
|
public: {
|
|
localPrice: {
|
|
pricePerNight: 0,
|
|
pricePerStay: 0,
|
|
regularPricePerStay: 0,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
member: null,
|
|
},
|
|
},
|
|
],
|
|
isMember,
|
|
nights
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
currency: CurrencyEnum.SEK,
|
|
price: 100,
|
|
regularPrice: 0,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("calculates requested price with breakfast and room features", () => {
|
|
const isMember = false
|
|
const nights = 2
|
|
const guest = { join: false }
|
|
const result = getRegularPrice(
|
|
[
|
|
{
|
|
adults: 1,
|
|
breakfast: {
|
|
localPrice: { price: 30, currency: CurrencyEnum.SEK },
|
|
requestedPrice: { price: 3, currency: CurrencyEnum.EUR },
|
|
},
|
|
roomFeatures: [
|
|
{
|
|
localPrice: { totalPrice: 20, currency: CurrencyEnum.SEK },
|
|
requestedPrice: { totalPrice: 2, currency: CurrencyEnum.EUR },
|
|
},
|
|
],
|
|
guest,
|
|
roomRate: {
|
|
public: {
|
|
localPrice: {
|
|
pricePerNight: 100,
|
|
pricePerStay: 0,
|
|
regularPricePerStay: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
requestedPrice: {
|
|
currency: CurrencyEnum.EUR,
|
|
pricePerStay: 0,
|
|
},
|
|
},
|
|
member: null,
|
|
},
|
|
},
|
|
],
|
|
isMember,
|
|
nights
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
currency: CurrencyEnum.SEK,
|
|
price: 80,
|
|
regularPrice: 180,
|
|
},
|
|
requested: {
|
|
currency: CurrencyEnum.EUR,
|
|
price: 8,
|
|
},
|
|
})
|
|
})
|
|
|
|
it("calculates prices for multi-room", () => {
|
|
const isMember = true
|
|
const nights = 2
|
|
const result = getRegularPrice(
|
|
[
|
|
{
|
|
adults: 1,
|
|
breakfast: { localPrice: { price: 20, currency: CurrencyEnum.SEK } },
|
|
roomFeatures: null,
|
|
guest: { join: false },
|
|
roomRate: {
|
|
public: {
|
|
localPrice: {
|
|
pricePerNight: 100,
|
|
pricePerStay: 0,
|
|
regularPricePerStay: 100,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
member: {
|
|
localPrice: {
|
|
pricePerNight: 50,
|
|
pricePerStay: 0,
|
|
regularPricePerStay: 50,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
adults: 1,
|
|
breakfast: { localPrice: { price: 25, currency: CurrencyEnum.SEK } },
|
|
roomFeatures: null,
|
|
guest: { join: true },
|
|
roomRate: {
|
|
public: {
|
|
localPrice: {
|
|
pricePerNight: 75,
|
|
pricePerStay: 0,
|
|
regularPricePerStay: 75,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
member: {
|
|
localPrice: {
|
|
pricePerNight: 30,
|
|
pricePerStay: 0,
|
|
regularPricePerStay: 30,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
isMember,
|
|
nights
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
currency: CurrencyEnum.SEK,
|
|
price: 90,
|
|
regularPrice: 265,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("returns unknown price for room without public and member rate", () => {
|
|
const isMember = false
|
|
const nights = 1
|
|
const result = getRegularPrice(
|
|
[
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
guest: { join: false },
|
|
roomRate: {
|
|
public: null,
|
|
member: null,
|
|
},
|
|
},
|
|
],
|
|
isMember,
|
|
nights
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
local: {
|
|
currency: CurrencyEnum.Unknown,
|
|
price: 0,
|
|
regularPrice: 0,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
})
|
|
|
|
type TotalPriceRooms = Parameters<typeof getTotalPrice>[0]
|
|
describe("getTotalPrice", () => {
|
|
it("returns corporate cheque price if any room have corporate cheque", () => {
|
|
const nights = 1
|
|
const isMember = false
|
|
const rooms: TotalPriceRooms = [
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
corporateCheque: {
|
|
localPrice: {
|
|
currency: CurrencyEnum.SEK,
|
|
numberOfCheques: 3,
|
|
additionalPricePerStay: 0,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
public: {
|
|
localPrice: {
|
|
pricePerStay: 500,
|
|
pricePerNight: 500,
|
|
regularPricePerStay: 500,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
member: {
|
|
localPrice: {
|
|
pricePerNight: 30,
|
|
pricePerStay: 30,
|
|
regularPricePerStay: 30,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
},
|
|
guest: { join: false },
|
|
},
|
|
]
|
|
|
|
const totalPrice = getTotalPrice(rooms, isMember, nights)
|
|
|
|
expect(totalPrice).toEqual({
|
|
local: {
|
|
price: 3,
|
|
currency: CurrencyEnum.CC,
|
|
additionalPrice: 0,
|
|
additionalPriceCurrency: CurrencyEnum.SEK,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("returns redemption price if any room have redemption price", () => {
|
|
const nights = 1
|
|
const isMember = false
|
|
const rooms: TotalPriceRooms = [
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
redemption: {
|
|
localPrice: {
|
|
pointsPerStay: 100,
|
|
currency: CurrencyEnum.POINTS,
|
|
additionalPricePerStay: 0,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
public: {
|
|
localPrice: {
|
|
pricePerStay: 500,
|
|
pricePerNight: 500,
|
|
regularPricePerStay: 500,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
member: {
|
|
localPrice: {
|
|
pricePerNight: 30,
|
|
pricePerStay: 30,
|
|
regularPricePerStay: 30,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
},
|
|
guest: { join: false },
|
|
},
|
|
]
|
|
|
|
const totalPrice = getTotalPrice(rooms, isMember, nights)
|
|
|
|
expect(totalPrice).toEqual({
|
|
local: {
|
|
price: 100,
|
|
currency: CurrencyEnum.POINTS,
|
|
additionalPrice: 0,
|
|
additionalPriceCurrency: CurrencyEnum.POINTS,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("returns voucher price if any room have voucher price", () => {
|
|
const nights = 1
|
|
const isMember = false
|
|
const rooms: TotalPriceRooms = [
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
voucher: {
|
|
numberOfVouchers: 1,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
public: {
|
|
localPrice: {
|
|
pricePerStay: 500,
|
|
pricePerNight: 500,
|
|
regularPricePerStay: 500,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
member: {
|
|
localPrice: {
|
|
pricePerNight: 30,
|
|
pricePerStay: 30,
|
|
regularPricePerStay: 30,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
},
|
|
},
|
|
guest: { join: false },
|
|
},
|
|
]
|
|
|
|
const totalPrice = getTotalPrice(rooms, isMember, nights)
|
|
|
|
expect(totalPrice).toEqual({
|
|
local: {
|
|
price: 1,
|
|
currency: CurrencyEnum.Voucher,
|
|
additionalPrice: 0,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("returns regular price if no special rates are present", () => {
|
|
const nights = 1
|
|
const isMember = false
|
|
const rooms: TotalPriceRooms = [
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
public: {
|
|
localPrice: {
|
|
pricePerStay: 500,
|
|
currency: CurrencyEnum.SEK,
|
|
regularPricePerStay: 500,
|
|
pricePerNight: 500,
|
|
},
|
|
},
|
|
member: {
|
|
localPrice: {
|
|
pricePerStay: 30,
|
|
currency: CurrencyEnum.SEK,
|
|
regularPricePerStay: 30,
|
|
pricePerNight: 30,
|
|
},
|
|
},
|
|
},
|
|
guest: { join: false },
|
|
},
|
|
]
|
|
|
|
const totalPrice = getTotalPrice(rooms, isMember, nights)
|
|
|
|
expect(totalPrice).toEqual({
|
|
local: {
|
|
price: 500,
|
|
regularPrice: 0,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("returns regular price for room with only public rate", () => {
|
|
const nights = 1
|
|
const isMember = false
|
|
const rooms: TotalPriceRooms = [
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {
|
|
public: {
|
|
localPrice: {
|
|
pricePerStay: 500,
|
|
currency: CurrencyEnum.SEK,
|
|
regularPricePerStay: 500,
|
|
pricePerNight: 500,
|
|
},
|
|
},
|
|
member: null,
|
|
},
|
|
guest: { join: false },
|
|
},
|
|
]
|
|
|
|
const totalPrice = getTotalPrice(rooms, isMember, nights)
|
|
|
|
expect(totalPrice).toEqual({
|
|
local: {
|
|
price: 500,
|
|
regularPrice: 0,
|
|
currency: CurrencyEnum.SEK,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
|
|
it("returns unknown price for unknown room type", () => {
|
|
const nights = 1
|
|
const isMember = false
|
|
const rooms: TotalPriceRooms = [
|
|
{
|
|
adults: 1,
|
|
breakfast: false,
|
|
roomFeatures: [],
|
|
roomRate: {},
|
|
guest: { join: false },
|
|
},
|
|
]
|
|
|
|
const totalPrice = getTotalPrice(rooms, isMember, nights)
|
|
|
|
expect(totalPrice).toEqual({
|
|
local: {
|
|
price: 0,
|
|
currency: CurrencyEnum.Unknown,
|
|
regularPrice: 0,
|
|
},
|
|
requested: undefined,
|
|
})
|
|
})
|
|
})
|