mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
091346dfe8
* wip * Remove obsolete snapshots * simplify * chore(test): Convert mocks to TypeScript and tighten fetch mock types Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * Remove unneccessary patches * Migrate to msw instead of custom fetch mock * Address PR review comments - Split chained vi.useFakeTimers().setSystemTime() into separate calls. - Switch test setup to dynamic imports so EventEmitter.defaultMaxListeners assignment runs before module init (static imports were hoisted above it). - Drop redundant NODE_ENV guard in monkeyPatchSequelizeErrorsForJest; its sole caller already gates on env.isTest. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
85 lines
2.4 KiB
TypeScript
85 lines
2.4 KiB
TypeScript
import { SearchableModel } from "@shared/types";
|
|
import {
|
|
buildDocument,
|
|
buildCollection,
|
|
buildUser,
|
|
} from "@server/test/factories";
|
|
import SearchProviderManager from "@server/utils/SearchProviderManager";
|
|
import SearchIndexProcessor from "./SearchIndexProcessor";
|
|
|
|
type PerformArg = Parameters<SearchIndexProcessor["perform"]>[0];
|
|
|
|
const processor = new SearchIndexProcessor();
|
|
|
|
describe("SearchIndexProcessor", () => {
|
|
it("should have the expected applicable events", () => {
|
|
expect(SearchIndexProcessor.applicableEvents).toContain(
|
|
"documents.publish"
|
|
);
|
|
expect(SearchIndexProcessor.applicableEvents).toContain(
|
|
"documents.update.delayed"
|
|
);
|
|
expect(SearchIndexProcessor.applicableEvents).toContain(
|
|
"documents.permanent_delete"
|
|
);
|
|
expect(SearchIndexProcessor.applicableEvents).toContain(
|
|
"collections.create"
|
|
);
|
|
expect(SearchIndexProcessor.applicableEvents).toContain("comments.create");
|
|
expect(SearchIndexProcessor.applicableEvents).toContain("comments.delete");
|
|
});
|
|
|
|
it("should call provider.index for documents.publish", async () => {
|
|
const user = await buildUser();
|
|
const collection = await buildCollection({
|
|
teamId: user.teamId,
|
|
userId: user.id,
|
|
});
|
|
const document = await buildDocument({
|
|
teamId: user.teamId,
|
|
collectionId: collection.id,
|
|
userId: user.id,
|
|
});
|
|
|
|
const provider = SearchProviderManager.getProvider();
|
|
const indexSpy = vi.spyOn(provider, "index");
|
|
|
|
await processor.perform({
|
|
name: "documents.publish",
|
|
documentId: document.id,
|
|
collectionId: collection.id,
|
|
teamId: user.teamId,
|
|
actorId: user.id,
|
|
} as PerformArg);
|
|
|
|
expect(indexSpy).toHaveBeenCalledWith(
|
|
SearchableModel.Document,
|
|
expect.objectContaining({ id: document.id })
|
|
);
|
|
|
|
indexSpy.mockRestore();
|
|
});
|
|
|
|
it("should call provider.remove for documents.permanent_delete", async () => {
|
|
const user = await buildUser();
|
|
const provider = SearchProviderManager.getProvider();
|
|
const removeSpy = vi.spyOn(provider, "remove");
|
|
|
|
await processor.perform({
|
|
name: "documents.permanent_delete",
|
|
documentId: "deleted-doc-id",
|
|
collectionId: "some-collection-id",
|
|
teamId: user.teamId,
|
|
actorId: user.id,
|
|
} as PerformArg);
|
|
|
|
expect(removeSpy).toHaveBeenCalledWith(
|
|
SearchableModel.Document,
|
|
"deleted-doc-id",
|
|
user.teamId
|
|
);
|
|
|
|
removeSpy.mockRestore();
|
|
});
|
|
});
|