/* eslint-disable @typescript-eslint/no-explicit-any */ import { createIntl, createIntlCache } from "react-intl" import { beforeAll, describe, expect, it, vi } from "vitest" import { calculateTotalPrice } from "./helpers" const cache = createIntlCache() const createTestIntl = (locale: string = "en-US") => createIntl({ locale, messages: {}, onError: () => {} }, cache) describe("calculateTotalPrice", () => { const baseRoom: Parameters[0][0] = { totalPrice: 0, isCancelled: false, cheques: 0, roomPointType: null, totalPoints: 0, roomPoints: 0, vouchers: 0, } vi.mock("@scandic-hotels/common/utils/numberFormatting", () => ({ formatPrice: (_intl: any, price: number, currency: string) => `${price} ${currency}`, })) beforeAll(() => { vi.clearAllMocks() }) it("should return correct price for conflicting rooms (cash)", () => { const rooms = [ { totalPrice: 1000, isCancelled: false }, { totalPrice: 500, isCancelled: false }, ] as any const result = calculateTotalPrice( rooms, "SEK" as any, createTestIntl(), false ) expect(result).toBe("1500 SEK") }) it("should ignore cancelled rooms if not all are cancelled", () => { vi.mock("@scandic-hotels/common/utils/numberFormatting", () => ({ formatPrice: (_intl: any, price: number, currency: string) => `${price} ${currency}`, })) const rooms = [ { totalPrice: 1000, isCancelled: false }, { totalPrice: 500, isCancelled: true }, ] as any const result = calculateTotalPrice( rooms, "SEK" as any, createTestIntl(), false ) expect(result).toBe("1000 SEK") }) it("should format string for Vouchers", () => { const result = calculateTotalPrice( [{ ...baseRoom, vouchers: 2, totalPrice: -1, isCancelled: false }], "SEK" as any, createTestIntl(), false ) expect(result).toContain("2 Vouchers") }) it("should handle mixed Cash and Points", () => { const result = calculateTotalPrice( [ { ...baseRoom, totalPrice: 100, isCancelled: false, totalPoints: 0, }, { ...baseRoom, totalPrice: 0, totalPoints: 20000, roomPointType: "Scandic", isCancelled: false, }, ], "SEK" as any, createTestIntl(), false ) expect(result).toMatch(/20000 Points \+ 100 SEK/) }) it("should sum up Cheques correctly", () => { const rooms = [{ cheques: 2, isCancelled: false }] as any // CurrencyEnum.CC is usually imported, assuming it resolves or we check specific output const result = calculateTotalPrice( rooms, "SEK" as any, createTestIntl(), false ) expect(result).toContain("2 CC") }) it("should combine Vouchers and Cash", () => { const result = calculateTotalPrice( [ { ...baseRoom, vouchers: 1, totalPrice: -1, isCancelled: false, }, { ...baseRoom, totalPrice: 500, isCancelled: false, }, ], "SEK" as any, createTestIntl(), false ) expect(result).toMatch(/1 Voucher \+ 500 SEK/) }) it("should combine Eurobonus points and Cash", () => { const result = calculateTotalPrice( [ { ...baseRoom, roomPoints: 1, roomPointType: "EuroBonus", }, { ...baseRoom, totalPrice: 500, }, ], "SEK" as any, createTestIntl(), false ) expect(result).toMatch(/1 EB Point \+ 500 SEK/) }) it("should combine Eurobonus points, Scandic Friends points and Cash", () => { const result = calculateTotalPrice( [ { ...baseRoom, roomPoints: 1, roomPointType: "EuroBonus", totalPoints: 500, }, { ...baseRoom, totalPrice: 500, }, ], "SEK" as any, createTestIntl(), false ) expect(result).toMatch(/1 EB Point \+ 500 Points \+ 500 SEK/) }) })