import { describe, expect, it } from "vitest" import { getSearchTokens } from "./getSearchTokens" import type { Location } from "@scandic-hotels/trpc/types/locations" import type { DeepPartial } from "../../../types/deepPartial" describe("getSearchTokens", () => { it("should return lowercased tokens for a hotel location", () => { const location: DeepPartial = { keyWords: ["Beach", "Luxury"], name: "Grand Hotel", type: "hotels", relationships: { city: { name: "Stockholm" } }, } const result = getSearchTokens(location as Location) expect(result).toEqual(["beach", "luxury", "grand hotel", "stockholm"]) }) it("should generate additional tokens for diacritics replacement on a non-hotel location", () => { const location: DeepPartial = { keyWords: ["Ångström", "Café"], name: "München", country: "Frånce", type: "cities", } const result = getSearchTokens(location as Location) expect(result).toEqual([ "angstrom", "cafe", "munchen", "france", "ångström", "café", "münchen", "frånce", ]) }) it("should filter out empty or falsey tokens", () => { const location: DeepPartial = { keyWords: ["", "Valid"], name: "", type: "hotels", relationships: { city: { name: "" } }, } const result = getSearchTokens(location as Location) expect(result).toEqual(["valid"]) }) })