import { describe, expect, it } from "vitest"; import { createSearchClient } from "./client.js"; import { createSearchIndex } from "./index-helper.js"; import type { SearchIndexSchema } from "./schemas/index.js"; import { createInMemoryMeili } from "./testing.js"; /** * A schema that carries stopWords + synonyms but deliberately omits * rankingRules — exercises both the truthy (stopWords/synonyms) and the * falsy (rankingRules) merge branches plus the synonyms copy helper. */ const schemaWithSynonyms: SearchIndexSchema = { name: "syn-index", primaryKey: "id", searchableAttributes: ["title"], filterableAttributes: ["tenantId"], sortableAttributes: ["createdAt"], stopWords: ["the", "a"], synonyms: { car: ["auto", "vehicle"], laptop: ["notebook"] }, allowedDocumentFields: ["id", "tenantId", "title", "createdAt"], }; describe("createSearchIndex — schema settings merge", () => { it("forwards schema-level stopWords and synonyms, omitting absent rankingRules", async () => { const { factory, state } = createInMemoryMeili(); const client = createSearchClient({ url: "http://memory", meiliFactory: factory }); await createSearchIndex({ client, schema: schemaWithSynonyms }); const settings = state.indexes.get("syn-index")?.settings; expect(settings).toMatchObject({ searchableAttributes: ["title"], stopWords: ["the", "a"], synonyms: { car: ["auto", "vehicle"], laptop: ["notebook"] }, }); expect(settings).not.toHaveProperty("rankingRules"); }); it("lets each overridable field win over the schema value", async () => { const { factory, state } = createInMemoryMeili(); const client = createSearchClient({ url: "http://memory", meiliFactory: factory }); await createSearchIndex({ client, schema: schemaWithSynonyms, settingsOverride: { searchableAttributes: ["body"], filterableAttributes: ["tenantId", "status"], sortableAttributes: ["updatedAt"], rankingRules: ["words", "sort"], stopWords: ["und"], synonyms: { x: ["y"] }, }, }); expect(state.indexes.get("syn-index")?.settings).toMatchObject({ searchableAttributes: ["body"], filterableAttributes: ["tenantId", "status"], sortableAttributes: ["updatedAt"], rankingRules: ["words", "sort"], stopWords: ["und"], synonyms: { x: ["y"] }, }); }); });