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
+72
@@ -0,0 +1,72 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { createSearchClient } from "@toolctrl/search";
|
||||
import { createInMemoryMeili } from "@toolctrl/search/testing";
|
||||
import { bootstrapSearchIndexer } from "./search-indexer-bootstrap.js";
|
||||
import { SEARCH_INDEX_OUTBOX_QUEUE } from "./search-indexer.js";
|
||||
|
||||
function fakeWorker() {
|
||||
const close = vi.fn(async () => undefined);
|
||||
const handle = { name: "fake-worker", close };
|
||||
const createWorkerImpl = vi.fn(() => handle);
|
||||
return { handle, createWorkerImpl };
|
||||
}
|
||||
|
||||
describe("bootstrapSearchIndexer", () => {
|
||||
it("returns disabled when MEILI_URL is unset", () => {
|
||||
const { createWorkerImpl } = fakeWorker();
|
||||
const result = bootstrapSearchIndexer({ WORKER_QUEUE_GROUP: "general" }, { createWorkerImpl });
|
||||
expect(result.status).toBe("disabled");
|
||||
if (result.status === "disabled") expect(result.reason).toMatch(/MEILI_URL/);
|
||||
expect(createWorkerImpl).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns disabled when SEARCH_INDEXER_ENABLED is 'false'", () => {
|
||||
const { createWorkerImpl } = fakeWorker();
|
||||
const result = bootstrapSearchIndexer(
|
||||
{ WORKER_QUEUE_GROUP: "general", MEILI_URL: "http://x", SEARCH_INDEXER_ENABLED: "false" },
|
||||
{ createWorkerImpl }
|
||||
);
|
||||
expect(result.status).toBe("disabled");
|
||||
});
|
||||
|
||||
it("returns disabled in non-general groups", () => {
|
||||
const { createWorkerImpl } = fakeWorker();
|
||||
const result = bootstrapSearchIndexer({ WORKER_QUEUE_GROUP: "mail", MEILI_URL: "http://x" }, { createWorkerImpl });
|
||||
expect(result.status).toBe("disabled");
|
||||
expect(createWorkerImpl).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("subscribes the worker to the outbox.search-index queue when enabled", () => {
|
||||
const { createWorkerImpl, handle } = fakeWorker();
|
||||
const meili = createInMemoryMeili();
|
||||
const searchClient = createSearchClient({ url: "http://memory", meiliFactory: meili.factory });
|
||||
const result = bootstrapSearchIndexer(
|
||||
{ WORKER_QUEUE_GROUP: "general", MEILI_URL: "http://memory" },
|
||||
{ createWorkerImpl, searchClient }
|
||||
);
|
||||
expect(result.status).toBe("started");
|
||||
expect(createWorkerImpl).toHaveBeenCalledWith(
|
||||
SEARCH_INDEX_OUTBOX_QUEUE,
|
||||
expect.any(Function),
|
||||
expect.objectContaining({ concurrency: 5 })
|
||||
);
|
||||
if (result.status === "started") {
|
||||
expect(result.handle).toBe(handle);
|
||||
}
|
||||
});
|
||||
|
||||
it("honours SEARCH_INDEXER_CONCURRENCY override", () => {
|
||||
const { createWorkerImpl } = fakeWorker();
|
||||
const meili = createInMemoryMeili();
|
||||
const searchClient = createSearchClient({ url: "http://memory", meiliFactory: meili.factory });
|
||||
bootstrapSearchIndexer(
|
||||
{ WORKER_QUEUE_GROUP: "general", MEILI_URL: "http://memory", SEARCH_INDEXER_CONCURRENCY: "12" },
|
||||
{ createWorkerImpl, searchClient }
|
||||
);
|
||||
expect(createWorkerImpl).toHaveBeenCalledWith(
|
||||
SEARCH_INDEX_OUTBOX_QUEUE,
|
||||
expect.any(Function),
|
||||
expect.objectContaining({ concurrency: 12 })
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user