diff --git a/packages/booking-flow/lib/stores/enter-details/helpers.test.ts b/packages/booking-flow/lib/stores/enter-details/helpers.test.ts index 33b7e6c1b..99e40ed98 100644 --- a/packages/booking-flow/lib/stores/enter-details/helpers.test.ts +++ b/packages/booking-flow/lib/stores/enter-details/helpers.test.ts @@ -9,6 +9,7 @@ import { getRedemptionPrice, getRegularPrice, getRequestedAdditionalPrice, + getTotalPrice, getVoucherPrice, } from "./helpers" @@ -1208,43 +1209,43 @@ describe("getRedemptionPrice", () => { 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, + 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 - ) + ], + nights + ) - expect(result).toEqual({ - local: { - price: 100, - currency: CurrencyEnum.POINTS, - additionalPrice: 33, - additionalPriceCurrency: CurrencyEnum.POINTS, - }, - requested: undefined, + expect(result).toEqual({ + local: { + price: 100, + currency: CurrencyEnum.POINTS, + additionalPrice: 33, + additionalPriceCurrency: CurrencyEnum.POINTS, + }, + requested: undefined, + }) }) }) @@ -1849,3 +1850,285 @@ describe("getRegularPrice", () => { }) }) }) + +type TotalPriceRooms = Parameters[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, + }, + rateCode: {} as never, + rateType: {} as never, + }, + bookingCode: {} as never, + rateDefinition: {} as never, + rate: {} as never, + rateDefinitionMember: {} as never, + }, + guest: {} as never, + }, + { + adults: 1, + breakfast: false, + roomFeatures: [], + roomRate: { + public: { + localPrice: { + pricePerStay: 500, + currency: CurrencyEnum.SEK, + omnibusPricePerNight: {} as never, + pricePerNight: {} as never, + regularPricePerNight: {} as never, + regularPricePerStay: {} as never, + }, + rateCode: {} as never, + rateType: {} as never, + }, + member: { + localPrice: { + pricePerNight: 30, + regularPricePerStay: 30, + currency: CurrencyEnum.SEK, + omnibusPricePerNight: {} as never, + pricePerStay: {} as never, + regularPricePerNight: {} as never, + }, + rateCode: {} as never, + rateType: {} as never, + }, + bookingCode: {} as never, + rateDefinition: {} as never, + rate: {} as never, + rateDefinitionMember: {} as never, + }, + guest: {} as never, + }, + ] + + 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, + pointsPerNight: 100, + currency: CurrencyEnum.POINTS, + additionalPricePerStay: 0, + }, + hasEnoughPoints: {} as never, + rateCode: {} as never, + rateType: {} as never, + }, + bookingCode: {} as never, + rateDefinition: {} as never, + rate: {} as never, + rateDefinitionMember: {} as never, + }, + guest: {} as never, + }, + { + adults: 1, + breakfast: false, + roomFeatures: [], + roomRate: { + public: { + localPrice: { + pricePerStay: 500, + currency: CurrencyEnum.SEK, + omnibusPricePerNight: {} as never, + pricePerNight: {} as never, + regularPricePerNight: {} as never, + regularPricePerStay: {} as never, + }, + rateCode: {} as never, + rateType: {} as never, + }, + member: { + localPrice: { + pricePerNight: 30, + regularPricePerStay: 30, + currency: CurrencyEnum.SEK, + omnibusPricePerNight: {} as never, + pricePerStay: {} as never, + regularPricePerNight: {} as never, + }, + rateCode: {} as never, + rateType: {} as never, + }, + bookingCode: {} as never, + rateDefinition: {} as never, + rate: {} as never, + rateDefinitionMember: {} as never, + }, + guest: {} as never, + }, + ] + + 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, + rateCode: {} as never, + rateType: {} as never, + }, + bookingCode: {} as never, + rateDefinition: {} as never, + rate: {} as never, + rateDefinitionMember: {} as never, + }, + guest: {} as never, + }, + { + adults: 1, + breakfast: false, + roomFeatures: [], + roomRate: { + public: { + localPrice: { + pricePerStay: 500, + currency: CurrencyEnum.SEK, + omnibusPricePerNight: {} as never, + pricePerNight: {} as never, + regularPricePerNight: {} as never, + regularPricePerStay: {} as never, + }, + rateCode: {} as never, + rateType: {} as never, + }, + member: { + localPrice: { + pricePerNight: 30, + regularPricePerStay: 30, + currency: CurrencyEnum.SEK, + omnibusPricePerNight: {} as never, + pricePerStay: {} as never, + regularPricePerNight: {} as never, + }, + rateCode: {} as never, + rateType: {} as never, + }, + bookingCode: {} as never, + rateDefinition: {} as never, + rate: {} as never, + rateDefinitionMember: {} as never, + }, + guest: {} as never, + }, + ] + + 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, + omnibusPricePerNight: {} as never, + pricePerNight: {} as never, + regularPricePerNight: {} as never, + }, + rateCode: {} as never, + rateType: {} as never, + }, + member: { + localPrice: { + pricePerStay: 30, + currency: CurrencyEnum.SEK, + regularPricePerStay: 30, + omnibusPricePerNight: {} as never, + pricePerNight: {} as never, + regularPricePerNight: {} as never, + }, + rateCode: {} as never, + rateType: {} as never, + }, + bookingCode: {} as never, + rateDefinition: {} as never, + rate: {} as never, + rateDefinitionMember: {} as never, + }, + guest: { join: false } as never, + }, + ] + + const totalPrice = getTotalPrice(rooms, isMember, nights) + + expect(totalPrice).toEqual({ + local: { + price: 500, + regularPrice: 0, + currency: CurrencyEnum.SEK, + }, + requested: undefined, + }) + }) +}) diff --git a/packages/booking-flow/lib/stores/enter-details/helpers.ts b/packages/booking-flow/lib/stores/enter-details/helpers.ts index 980fd54d6..b2c331058 100644 --- a/packages/booking-flow/lib/stores/enter-details/helpers.ts +++ b/packages/booking-flow/lib/stores/enter-details/helpers.ts @@ -360,11 +360,6 @@ export function getRequestedAdditionalPrice( } } -type TRoom = Pick< - RoomState["room"], - "adults" | "breakfast" | "guest" | "roomFeatures" | "roomRate" -> - type CorporateCheckRoom = PriceCalculationRoom & { roomRate: { corporateCheque: { @@ -669,6 +664,11 @@ export function getRegularPrice( return totalPrice } +type TRoom = Pick< + RoomState["room"], + "adults" | "breakfast" | "guest" | "roomFeatures" | "roomRate" +> + export function getTotalPrice( rooms: TRoom[], isMember: boolean,