Files
web/packages/booking-flow/lib/contexts/SelectRate/isRateSelected.test.ts
Anton Gunnarsson 5a86cbaafe Merged in chore/update-eslint-configs (pull request #2812)
chore: Extend eslint configs from @typescript-eslint/recommended

* Change to typescript recommended in scandic-web

* Remove comment

* Change to recommended ts config in partner-sas

* Change to recommended ts lint config in booking-flow


Approved-by: Linus Flood
2025-09-17 07:55:11 +00:00

119 lines
3.2 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
import { describe, expect, it } from "vitest"
import { RateEnum } from "@scandic-hotels/common/constants/rate"
import { isRateSelected } from "./isRateSelected"
describe("isRateSelected", () => {
it("should return false when selectedRateCode is undefined", () => {
const result = isRateSelected({
selectedRateCode: undefined,
selectedRoomTypeCode: "ROOM1",
rate: { public: { rateCode: "RATE1" } },
roomTypeCode: "ROOM1",
} as any)
expect(result).toBe(false)
})
it("should return false when selectedRoomTypeCode is null", () => {
const result = isRateSelected({
selectedRateCode: "RATE1",
selectedRoomTypeCode: null,
rate: { public: { rateCode: "RATE1" } },
roomTypeCode: "ROOM1",
} as any)
expect(result).toBe(false)
})
it("should return false when rateCode is undefined", () => {
const result = isRateSelected({
selectedRateCode: "RATE1",
selectedRoomTypeCode: "ROOM1",
rate: { public: { rateCode: undefined } },
roomTypeCode: "ROOM1",
} as any)
expect(result).toBe(false)
})
it("should return false when roomTypeCode is null", () => {
const result = isRateSelected({
selectedRateCode: "RATE1",
selectedRoomTypeCode: "ROOM1",
rate: { public: { rateCode: "RATE1" } },
roomTypeCode: null,
} as any)
expect(result).toBe(false)
})
it("should return false when rate codes don't match", () => {
const result = isRateSelected({
selectedRateCode: "RATE1",
selectedRoomTypeCode: "ROOM1",
rate: { public: { rateCode: "RATE2" } },
roomTypeCode: "ROOM1",
} as any)
expect(result).toBe(false)
})
it("should return false when room type codes don't match", () => {
const result = isRateSelected({
selectedRateCode: "RATE1",
selectedRoomTypeCode: "ROOM1",
rate: { public: { rateCode: "RATE1" } },
roomTypeCode: "ROOM2",
} as any)
expect(result).toBe(false)
})
it("should return true when both rate code and room type code match", () => {
const result = isRateSelected({
selectedRateCode: "RATE1",
selectedRoomTypeCode: "ROOM1",
rate: { public: { rateCode: "RATE1" } },
roomTypeCode: "ROOM1",
} as any)
expect(result).toBe(true)
})
it("should handle case insensitivity in rate codes", () => {
const result = isRateSelected({
selectedRateCode: "RATE1",
selectedRoomTypeCode: "ROOM1",
rate: { public: { rateCode: "rate1" } },
roomTypeCode: "ROOM1",
} as any)
expect(result).toBe(true)
})
it("should handle case insensitivity in room type codes", () => {
const result = isRateSelected({
selectedRateCode: "RATE1",
selectedRoomTypeCode: "ROOM1",
rate: { public: { rateCode: "RATE1" } },
roomTypeCode: "room1",
} as any)
expect(result).toBe(true)
})
it("should work with RateEnum values", () => {
const result = isRateSelected({
selectedRateCode: RateEnum.save,
selectedRoomTypeCode: "ROOM1",
rate: { public: { rateCode: RateEnum.save } },
roomTypeCode: "ROOM1",
} as any)
expect(result).toBe(true)
})
})