Files
web/apps/scandic-web/contexts/SelectRate/includeRoomInfo.test.ts
Joakim Jäderberg 68cd061c6d Merged in feature/select-rate-vertical-data-flow (pull request #2535)
Feature/select rate vertical data flow

* add fix from SW-2666

* use translations for room packages

* move types to it's own file

* Merge branch 'master' of bitbucket.org:scandic-swap/web into feature/select-rate-vertical-data-flow

* merge

* feature/select-rate: double rate for campaing rates

* revert NODE_ENV check in Cookiebot script

* revert testing values

* fix(SW-3171): fix all filter selected in price details

* fix(SW-3166): multiroom anchoring when changing filter

* fix(SW-3172): check hotelType, show correct breakfast message

* Merge branch 'feature/select-rate-vertical-data-flow' of bitbucket.org:scandic-swap/web into feature/select-rate-vertical-data-flow

* fix: show special needs icons for subsequent roomTypes SW-3167

* fix: Display strike through text when logged in SW-3168

* fix: Reinstate the scrollToView behaviour when selecting a rate SW-3169

* merge

* .

* PR fixes

* fix: don't return notFound()

* .

* always include defaults for room packages

* merge

* merge

* merge

* Remove floating h1 for new select-rate


Approved-by: Anton Gunnarsson
2025-08-13 12:45:40 +00:00

107 lines
3.0 KiB
TypeScript

import { describe, expect, it } from "vitest"
import { includeRoomInfo } from "./includeRoomInfo"
import type { RoomCategory } from "@scandic-hotels/trpc/types/hotel"
import type { RoomConfiguration } from "@scandic-hotels/trpc/types/roomAvailability"
type DeepPartial<T> = T extends object
? {
[P in keyof T]?: DeepPartial<T[P]>
}
: T
const mockRoomCategories: DeepPartial<RoomCategory>[] = [
{
id: "cat1",
name: "Standard",
roomTypes: [{ code: "STD" }, { code: "STD2" }],
},
{
id: "cat2",
name: "Deluxe",
roomTypes: [{ code: "DLX" }],
},
]
describe("includeRoomInfo", () => {
it("returns roomConfiguration with roomInfo when roomTypeCode matches", () => {
const roomConfigurations: DeepPartial<RoomConfiguration>[] = [
{ roomTypeCode: "STD" },
{ roomTypeCode: "DLX" },
]
const result = includeRoomInfo({
roomConfigurations: roomConfigurations as RoomConfiguration[],
roomCategories: mockRoomCategories as RoomCategory[],
selectedPackages: [],
})
expect(result[0]).toMatchObject({
roomTypeCode: "STD",
roomInfo: mockRoomCategories[0],
})
expect(result[1]).toMatchObject({
roomTypeCode: "DLX",
roomInfo: mockRoomCategories[1],
})
})
it("returns null when no matching roomTypeCode is found", () => {
const roomConfigurations: DeepPartial<RoomConfiguration>[] = [
{ roomTypeCode: "NOT_FOUND" },
]
const result = includeRoomInfo({
roomConfigurations: roomConfigurations as RoomConfiguration[],
roomCategories: mockRoomCategories as RoomCategory[],
selectedPackages: [],
})
expect(result).toEqual([null])
})
it("handles empty roomConfigurations", () => {
const result = includeRoomInfo({
roomConfigurations: [],
roomCategories: mockRoomCategories as RoomCategory[],
selectedPackages: [],
})
expect(result).toEqual([])
})
it("handles empty roomCategories", () => {
const roomConfigurations: DeepPartial<RoomConfiguration>[] = [
{ roomTypeCode: "STD" },
]
const result = includeRoomInfo({
roomConfigurations: roomConfigurations as RoomConfiguration[],
roomCategories: [],
selectedPackages: [],
})
expect(result).toEqual([null])
})
it("returns correct mapping for multiple configurations with mixed matches", () => {
const roomConfigurations: DeepPartial<RoomConfiguration>[] = [
{ roomTypeCode: "STD" },
{ roomTypeCode: "DLX" },
{ roomTypeCode: "UNKNOWN" },
]
const result = includeRoomInfo({
roomConfigurations: roomConfigurations as RoomConfiguration[],
roomCategories: mockRoomCategories as RoomCategory[],
selectedPackages: [],
})
expect(result[0]).toMatchObject({
roomTypeCode: "STD",
roomInfo: mockRoomCategories[0],
})
expect(result[1]).toMatchObject({
roomTypeCode: "DLX",
roomInfo: mockRoomCategories[1],
})
expect(result[2]).toBeNull()
})
})