Merged in chore/SW-3321-move-selectratecontext-to- (pull request #2729)
chore(SW-3321): Moved Select rate context to booking-flow package * chore(SW-3321): Moved Select rate context to booking-flow package * chore(SW-3321): Optimised code Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
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()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user