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
74 lines
1.8 KiB
TypeScript
74 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest"
|
|
|
|
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
|
|
import { dt } from "@scandic-hotels/common/dt"
|
|
|
|
import { filterOverlappingDates } from "./index"
|
|
|
|
import type { specialAlertsSchema } from "@scandic-hotels/trpc/routers/hotels/schemas/hotel/specialAlerts"
|
|
import type { z } from "zod"
|
|
|
|
type Alert = z.infer<typeof specialAlertsSchema>[number]
|
|
|
|
function makeAlert(start: string, end: string): Alert {
|
|
return {
|
|
id: "test-id",
|
|
name: "Test Alert",
|
|
heading: "Test Heading",
|
|
text: "Some text",
|
|
type: AlertTypeEnum.Alarm,
|
|
displayInBookingFlow: true,
|
|
startDate: start,
|
|
endDate: end,
|
|
}
|
|
}
|
|
|
|
describe("filterOverlappingDates", () => {
|
|
const alert = makeAlert("2025-09-01", "2025-09-10")
|
|
|
|
it("shows alert if booking starts inside alert", () => {
|
|
const result = filterOverlappingDates(
|
|
[alert],
|
|
dt("2025-09-05"),
|
|
dt("2025-09-12")
|
|
)
|
|
expect(result).toHaveLength(1)
|
|
})
|
|
|
|
it("shows alert if booking ends inside alert", () => {
|
|
const result = filterOverlappingDates(
|
|
[alert],
|
|
dt("2025-08-28"),
|
|
dt("2025-09-05")
|
|
)
|
|
expect(result).toHaveLength(1)
|
|
})
|
|
|
|
it("shows alert if booking fully contains alert", () => {
|
|
const result = filterOverlappingDates(
|
|
[alert],
|
|
dt("2025-08-28"),
|
|
dt("2025-09-15")
|
|
)
|
|
expect(result).toHaveLength(1)
|
|
})
|
|
|
|
it("shows alert if alert fully contains booking", () => {
|
|
const result = filterOverlappingDates(
|
|
[alert],
|
|
dt("2025-09-03"),
|
|
dt("2025-09-05")
|
|
)
|
|
expect(result).toHaveLength(1)
|
|
})
|
|
|
|
it("does not show alert if no overlap", () => {
|
|
const result = filterOverlappingDates(
|
|
[alert],
|
|
dt("2025-08-01"),
|
|
dt("2025-08-05")
|
|
)
|
|
expect(result).toHaveLength(0)
|
|
})
|
|
})
|