Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/packages/search/src/index.test.ts
T
2026-07-08 16:15:37 +02:00

64 lines
2.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import * as search from "./index.js";
/**
* The barrel is the package's public contract: every name listed in the
* code-review checklist must stay re-exported, and the raw Meilisearch SDK
* must never leak through it. These tests pin both invariants so an
* accidental re-export removal (or a stray `MeiliSearch` export) fails CI.
*/
describe("@hivegrid/search public barrel", () => {
it("re-exports the documented runtime API", () => {
const expected = [
"createSearchClient",
"createSearchIndex",
"IndexSchemaValidationError",
"validateIndexSchema",
"bulkIndex",
"deleteFromIndex",
"health",
"searchInIndex",
"searchWithFallback",
"TenantScopeError",
"ALL_SEARCH_INDEXES",
"BULK_REINDEX_SUPPORTED_INDEXES",
"BULK_REINDEX_SUPPORTED_INDEX_NAMES",
"crmContactsIndex",
"getSearchIndexSchema",
"kbArticlesIndex",
"usersIndex",
"getIndexedEntitiesForPermissions",
"getIndexedEntity",
"indexedEntities",
"listIndexedEntities",
"validateIndexedEntities",
"sanitizeDocument",
"publishSearchBulkReindexEvent",
"publishSearchDeleteEvent",
"publishSearchUpsertEvent",
"searchEventType",
] as const;
for (const name of expected) {
expect(search, `missing export: ${name}`).toHaveProperty(name);
expect(search[name as keyof typeof search]).toBeDefined();
}
});
it("does not leak the raw Meilisearch SDK constructor", () => {
expect(search).not.toHaveProperty("MeiliSearch");
expect(search).not.toHaveProperty("Meilisearch");
});
it("wires the error classes as constructable Error subclasses", () => {
expect(new search.TenantScopeError("nope")).toBeInstanceOf(Error);
expect(new search.IndexSchemaValidationError("nope", "EMPTY_NAME")).toBeInstanceOf(Error);
});
it("keeps the index registry consistent between the barrel and schemas", () => {
expect(search.ALL_SEARCH_INDEXES).toContain(search.kbArticlesIndex);
expect(search.getSearchIndexSchema(search.kbArticlesIndex.name)).toBe(search.kbArticlesIndex);
expect(search.getSearchIndexSchema("does-not-exist")).toBeUndefined();
});
});