Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
+75
@@ -0,0 +1,75 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
ALL_SEARCH_INDEXES,
|
||||
BULK_REINDEX_SUPPORTED_INDEXES,
|
||||
BULK_REINDEX_SUPPORTED_INDEX_NAMES,
|
||||
crmContactsIndex,
|
||||
kbArticlesIndex,
|
||||
rowsIndex,
|
||||
usersIndex,
|
||||
} from "@toolctrl/search";
|
||||
import { enqueueReindexEvents, selectIndexes, selectTenants } from "./reindex.js";
|
||||
|
||||
describe("selectIndexes", () => {
|
||||
it("returns every supported bulk-reindex entry when input is undefined or 'all'", () => {
|
||||
expect(selectIndexes(undefined)).toEqual(BULK_REINDEX_SUPPORTED_INDEXES);
|
||||
expect(selectIndexes("all")).toEqual(BULK_REINDEX_SUPPORTED_INDEXES);
|
||||
expect(selectIndexes("all").map((schema) => schema.name)).toEqual([...BULK_REINDEX_SUPPORTED_INDEX_NAMES]);
|
||||
});
|
||||
|
||||
it("returns the matching schema when a known name is passed", () => {
|
||||
expect(selectIndexes("kb-articles")).toEqual([kbArticlesIndex]);
|
||||
expect(selectIndexes("crm-contacts")).toEqual([crmContactsIndex]);
|
||||
expect(selectIndexes("rows")).toEqual([rowsIndex]);
|
||||
expect(selectIndexes("users")).toEqual([usersIndex]);
|
||||
});
|
||||
|
||||
it("rejects cataloged indexes that do not have a bulk-reindex pager", () => {
|
||||
const unsupportedCatalogNames = ALL_SEARCH_INDEXES.map((schema) => schema.name).filter(
|
||||
(name) => !(BULK_REINDEX_SUPPORTED_INDEX_NAMES as readonly string[]).includes(name)
|
||||
);
|
||||
|
||||
expect(unsupportedCatalogNames).toEqual(["entities"]);
|
||||
for (const name of unsupportedCatalogNames) {
|
||||
expect(() => selectIndexes(name)).toThrow(/Unsupported search reindex target/);
|
||||
}
|
||||
});
|
||||
|
||||
it("throws on unknown index names", () => {
|
||||
expect(() => selectIndexes("does-not-exist")).toThrow(/Unsupported search reindex target/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("selectTenants", () => {
|
||||
it("returns the full list when input is undefined or 'all'", () => {
|
||||
expect(selectTenants(undefined, ["a", "b"])).toEqual(["a", "b"]);
|
||||
expect(selectTenants("all", ["a", "b"])).toEqual(["a", "b"]);
|
||||
});
|
||||
|
||||
it("returns the single tenant when a concrete id is passed", () => {
|
||||
expect(selectTenants("tenant-x", ["a", "b"])).toEqual(["tenant-x"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("enqueueReindexEvents", () => {
|
||||
it("publishes one event per index x tenant", async () => {
|
||||
const publish = vi.fn().mockResolvedValue(undefined);
|
||||
const results = await enqueueReindexEvents({
|
||||
indexes: [kbArticlesIndex],
|
||||
tenantIds: ["t1", "t2"],
|
||||
publish,
|
||||
});
|
||||
expect(results).toHaveLength(2);
|
||||
expect(publish).toHaveBeenCalledTimes(2);
|
||||
expect(publish.mock.calls.map((c) => c[0].tenantId)).toEqual(["t1", "t2"]);
|
||||
expect(publish.mock.calls[0][0].type).toMatch(/^search\.index\..+\.bulkreindex$/);
|
||||
expect(publish.mock.calls[0][0].payload).toMatchObject({ action: "bulk-reindex", indexName: kbArticlesIndex.name });
|
||||
});
|
||||
|
||||
it("returns empty list when no tenants provided", async () => {
|
||||
const publish = vi.fn().mockResolvedValue(undefined);
|
||||
const results = await enqueueReindexEvents({ indexes: BULK_REINDEX_SUPPORTED_INDEXES, tenantIds: [], publish });
|
||||
expect(results).toHaveLength(0);
|
||||
expect(publish).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user