import { describe, expect, it } from "@jest/globals"

import { getSearchTokens } from "./getSearchTokens"

import type { DeepPartial } from "@/types/DeepPartial"
import type { Location } from "@/types/trpc/routers/hotel/locations"

describe("getSearchTokens", () => {
  it("should return lowercased tokens for a hotel location", () => {
    const location: DeepPartial<Location> = {
      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<Location> = {
      keyWords: ["Ångström", "Café"],
      name: "München",
      country: "Frånce",
      type: "cities",
    }

    const result = getSearchTokens(location as Location)
    expect(result).toEqual([
      "ångström",
      "café",
      "münchen",
      "frånce",
      "angstrom",
      "cafe",
      "munchen",
      "france",
    ])
  })

  it("should filter out empty or falsey tokens", () => {
    const location: DeepPartial<Location> = {
      keyWords: ["", "Valid"],
      name: "",
      type: "hotels",
      relationships: { city: { name: "" } },
    }

    const result = getSearchTokens(location as Location)
    expect(result).toEqual(["valid"])
  })
})
