70 lines
2.4 KiB
TypeScript
70 lines
2.4 KiB
TypeScript
import { existsSync, readFileSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
ALL_SEARCH_INDEXES,
|
|
BULK_REINDEX_SUPPORTED_INDEXES,
|
|
BULK_REINDEX_SUPPORTED_INDEX_NAMES,
|
|
crmContactsIndex,
|
|
usersIndex,
|
|
projectsIndex,
|
|
getSearchIndexSchema,
|
|
kbArticlesIndex,
|
|
} from "./index.js";
|
|
|
|
describe("search index catalog", () => {
|
|
it("declares tenantId as a filterable attribute on every index", () => {
|
|
for (const schema of ALL_SEARCH_INDEXES) {
|
|
expect(schema.filterableAttributes).toContain("tenantId");
|
|
}
|
|
});
|
|
|
|
it("includes tenantId in the allowed document fields", () => {
|
|
for (const schema of ALL_SEARCH_INDEXES) {
|
|
expect(schema.allowedDocumentFields).toContain("tenantId");
|
|
expect(schema.allowedDocumentFields).toContain(schema.primaryKey);
|
|
}
|
|
});
|
|
|
|
it("exposes every schema via getSearchIndexSchema", () => {
|
|
for (const schema of ALL_SEARCH_INDEXES) {
|
|
expect(getSearchIndexSchema(schema.name)).toBe(schema);
|
|
}
|
|
});
|
|
|
|
it("returns undefined for unknown index names", () => {
|
|
expect(getSearchIndexSchema("does-not-exist")).toBeUndefined();
|
|
});
|
|
|
|
it("limits bulk-reindex support to indexes with registered pagers", () => {
|
|
expect([...BULK_REINDEX_SUPPORTED_INDEX_NAMES]).toEqual([
|
|
kbArticlesIndex.name,
|
|
crmContactsIndex.name,
|
|
usersIndex.name,
|
|
projectsIndex.name,
|
|
]);
|
|
expect(BULK_REINDEX_SUPPORTED_INDEXES.map((schema) => schema.name)).toEqual([
|
|
...BULK_REINDEX_SUPPORTED_INDEX_NAMES,
|
|
]);
|
|
});
|
|
|
|
it("keeps every supported bulk-reindex name in the search catalog", () => {
|
|
for (const name of BULK_REINDEX_SUPPORTED_INDEX_NAMES) {
|
|
expect(getSearchIndexSchema(name)?.name).toBe(name);
|
|
}
|
|
});
|
|
|
|
it("keeps operator docs explicit about the current bulk-reindex scope", () => {
|
|
const featureDocs = readRepoFile("docs/features/search.md");
|
|
expect(featureDocs).toContain("`kb-articles`, `crm-contacts`, `users`, and `projects`");
|
|
expect(featureDocs).toMatch(/Entities still require\s+a dedicated bulk pager/);
|
|
});
|
|
});
|
|
|
|
function readRepoFile(path: string): string {
|
|
const candidates = [resolve(process.cwd(), path), resolve(process.cwd(), "../..", path)];
|
|
const found = candidates.find((candidate) => existsSync(candidate));
|
|
if (!found) throw new Error(`Could not find ${path} from ${process.cwd()}`);
|
|
return readFileSync(found, "utf8");
|
|
}
|