Merged in chore/add-tests-to-getTotalPrice (pull request #3178)
chore: Add tests to getTotalPrice * Add tests to getTotalPrice Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
getRedemptionPrice,
|
getRedemptionPrice,
|
||||||
getRegularPrice,
|
getRegularPrice,
|
||||||
getRequestedAdditionalPrice,
|
getRequestedAdditionalPrice,
|
||||||
|
getTotalPrice,
|
||||||
getVoucherPrice,
|
getVoucherPrice,
|
||||||
} from "./helpers"
|
} from "./helpers"
|
||||||
|
|
||||||
@@ -1208,43 +1209,43 @@ describe("getRedemptionPrice", () => {
|
|||||||
requested: undefined,
|
requested: undefined,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
it("returns price and additionalPrice for single room with room features", () => {
|
it("returns price and additionalPrice for single room with room features", () => {
|
||||||
const nights = 2
|
const nights = 2
|
||||||
const result = getRedemptionPrice(
|
const result = getRedemptionPrice(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
adults: 1,
|
adults: 1,
|
||||||
breakfast: false,
|
breakfast: false,
|
||||||
roomFeatures: [
|
roomFeatures: [
|
||||||
{
|
{
|
||||||
localPrice: { totalPrice: 33 },
|
localPrice: { totalPrice: 33 },
|
||||||
requestedPrice: { totalPrice: 33 },
|
requestedPrice: { totalPrice: 33 },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
roomRate: {
|
roomRate: {
|
||||||
redemption: {
|
redemption: {
|
||||||
localPrice: {
|
localPrice: {
|
||||||
pointsPerStay: 100,
|
pointsPerStay: 100,
|
||||||
currency: CurrencyEnum.POINTS,
|
currency: CurrencyEnum.POINTS,
|
||||||
additionalPricePerStay: 0,
|
additionalPricePerStay: 0,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
],
|
||||||
],
|
nights
|
||||||
nights
|
)
|
||||||
)
|
|
||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
local: {
|
local: {
|
||||||
price: 100,
|
price: 100,
|
||||||
currency: CurrencyEnum.POINTS,
|
currency: CurrencyEnum.POINTS,
|
||||||
additionalPrice: 33,
|
additionalPrice: 33,
|
||||||
additionalPriceCurrency: CurrencyEnum.POINTS,
|
additionalPriceCurrency: CurrencyEnum.POINTS,
|
||||||
},
|
},
|
||||||
requested: undefined,
|
requested: undefined,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -1849,3 +1850,285 @@ describe("getRegularPrice", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
@@ -360,11 +360,6 @@ export function getRequestedAdditionalPrice(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type TRoom = Pick<
|
|
||||||
RoomState["room"],
|
|
||||||
"adults" | "breakfast" | "guest" | "roomFeatures" | "roomRate"
|
|
||||||
>
|
|
||||||
|
|
||||||
type CorporateCheckRoom = PriceCalculationRoom & {
|
type CorporateCheckRoom = PriceCalculationRoom & {
|
||||||
roomRate: {
|
roomRate: {
|
||||||
corporateCheque: {
|
corporateCheque: {
|
||||||
@@ -669,6 +664,11 @@ export function getRegularPrice(
|
|||||||
return totalPrice
|
return totalPrice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TRoom = Pick<
|
||||||
|
RoomState["room"],
|
||||||
|
"adults" | "breakfast" | "guest" | "roomFeatures" | "roomRate"
|
||||||
|
>
|
||||||
|
|
||||||
export function getTotalPrice(
|
export function getTotalPrice(
|
||||||
rooms: TRoom[],
|
rooms: TRoom[],
|
||||||
isMember: boolean,
|
isMember: boolean,
|
||||||
|
|||||||
Reference in New Issue
Block a user