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:
@@ -2,7 +2,11 @@ import { describe, expect, it } from "vitest"
|
||||
|
||||
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
|
||||
|
||||
import { getAdditionalPrice, getRedemptionPrice } from "./helpers"
|
||||
import {
|
||||
getAdditionalPrice,
|
||||
getRedemptionPrice,
|
||||
getVoucherPrice,
|
||||
} from "./helpers"
|
||||
|
||||
type GetAdditionalPriceParams = Parameters<typeof getAdditionalPrice>
|
||||
describe("getAdditionalPrice", () => {
|
||||
@@ -307,3 +311,150 @@ describe("getRedemptionPrice", () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
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,
|
||||
})
|
||||
})
|
||||
|
||||
it("does not return price for room without voucher", () => {
|
||||
const nights = 3
|
||||
const result = getVoucherPrice(
|
||||
[
|
||||
{
|
||||
adults: 1,
|
||||
breakfast: false,
|
||||
roomFeatures: [],
|
||||
roomRate: {
|
||||
redemption: {
|
||||
localPrice: {
|
||||
pointsPerStay: 150,
|
||||
currency: CurrencyEnum.POINTS,
|
||||
additionalPricePerStay: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
adults: 1,
|
||||
breakfast: false,
|
||||
roomFeatures: [],
|
||||
roomRate: {
|
||||
voucher: {
|
||||
numberOfVouchers: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
nights
|
||||
)
|
||||
|
||||
expect(result).toEqual({
|
||||
local: {
|
||||
price: 2,
|
||||
currency: CurrencyEnum.Voucher,
|
||||
additionalPrice: 0,
|
||||
},
|
||||
requested: undefined,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user