From e92500dd85af262cf6970cabba5e0f1fa8e25cd2 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 28 Apr 2025 21:38:42 -0400 Subject: [PATCH] tsc --- .../processors/WebhookProcessor.test.ts | 28 ++++++++++++++----- server/commands/documentMover.ts | 2 +- .../commands/documentPermanentDeleter.test.ts | 12 +++++--- .../DocumentSubscriptionProcessor.ts | 4 +-- .../tasks/DetachDraftsFromCollectionTask.ts | 2 +- .../DocumentAddGroupNotificationsTask.ts | 5 ++-- server/queues/tasks/DocumentImportTask.ts | 2 +- server/routes/api/cron/cron.ts | 3 ++ server/routes/api/documents/documents.ts | 1 + server/services/cron.ts | 1 + 10 files changed, 42 insertions(+), 18 deletions(-) diff --git a/plugins/webhooks/server/processors/WebhookProcessor.test.ts b/plugins/webhooks/server/processors/WebhookProcessor.test.ts index 63d37d7f95..f8b6028375 100644 --- a/plugins/webhooks/server/processors/WebhookProcessor.test.ts +++ b/plugins/webhooks/server/processors/WebhookProcessor.test.ts @@ -29,8 +29,12 @@ describe("WebhookProcessor", () => { await processor.perform(event); - expect(DeliverWebhookTask.schedule).toHaveBeenCalled(); - expect(DeliverWebhookTask.schedule).toHaveBeenCalledWith({ + expect( + jest.mocked(DeliverWebhookTask.prototype.schedule) + ).toHaveBeenCalled(); + expect( + jest.mocked(DeliverWebhookTask.prototype.schedule) + ).toHaveBeenCalledWith({ event, subscriptionId: subscription.id, }); @@ -53,7 +57,9 @@ describe("WebhookProcessor", () => { await processor.perform(event); - expect(DeliverWebhookTask.schedule).toHaveBeenCalledTimes(0); + expect( + jest.mocked(DeliverWebhookTask.prototype.schedule) + ).toHaveBeenCalledTimes(0); }); it("it schedules a delivery for the event for each subscription", async () => { @@ -79,13 +85,21 @@ describe("WebhookProcessor", () => { await processor.perform(event); - expect(DeliverWebhookTask.schedule).toHaveBeenCalled(); - expect(DeliverWebhookTask.schedule).toHaveBeenCalledTimes(2); - expect(DeliverWebhookTask.schedule).toHaveBeenCalledWith({ + expect( + jest.mocked(DeliverWebhookTask.prototype.schedule) + ).toHaveBeenCalled(); + expect( + jest.mocked(DeliverWebhookTask.prototype.schedule) + ).toHaveBeenCalledTimes(2); + expect( + jest.mocked(DeliverWebhookTask.prototype.schedule) + ).toHaveBeenCalledWith({ event, subscriptionId: subscription.id, }); - expect(DeliverWebhookTask.schedule).toHaveBeenCalledWith({ + expect( + jest.mocked(DeliverWebhookTask.prototype.schedule) + ).toHaveBeenCalledWith({ event, subscriptionId: subscriptionTwo.id, }); diff --git a/server/commands/documentMover.ts b/server/commands/documentMover.ts index 01ab23aad5..cf1b150783 100644 --- a/server/commands/documentMover.ts +++ b/server/commands/documentMover.ts @@ -24,7 +24,7 @@ type Props = { /** Position of moved document within document structure */ index?: number; /** The IP address of the user moving the document */ - ip: string; + ip: string | null; /** The database transaction to run within */ transaction?: Transaction; }; diff --git a/server/commands/documentPermanentDeleter.test.ts b/server/commands/documentPermanentDeleter.test.ts index e397f69804..ab0ad273db 100644 --- a/server/commands/documentPermanentDeleter.test.ts +++ b/server/commands/documentPermanentDeleter.test.ts @@ -4,9 +4,11 @@ import DeleteAttachmentTask from "@server/queues/tasks/DeleteAttachmentTask"; import { buildAttachment, buildDocument } from "@server/test/factories"; import documentPermanentDeleter from "./documentPermanentDeleter"; -jest.mock("@server/queues/tasks/DeleteAttachmentTask", () => ({ - schedule: jest.fn(), -})); +jest.mock("@server/queues/tasks/DeleteAttachmentTask"); + +beforeEach(() => { + jest.resetAllMocks(); +}); describe("documentPermanentDeleter", () => { it("should destroy documents", async () => { @@ -60,7 +62,9 @@ describe("documentPermanentDeleter", () => { await document.save(); const countDeletedDoc = await documentPermanentDeleter([document]); expect(countDeletedDoc).toEqual(1); - expect(DeleteAttachmentTask.schedule).toHaveBeenCalledTimes(2); + expect( + jest.mocked(DeleteAttachmentTask.prototype.schedule) + ).toHaveBeenCalledTimes(2); expect( await Document.unscoped().count({ where: { diff --git a/server/queues/processors/DocumentSubscriptionProcessor.ts b/server/queues/processors/DocumentSubscriptionProcessor.ts index ac8e485eef..4b138d98de 100644 --- a/server/queues/processors/DocumentSubscriptionProcessor.ts +++ b/server/queues/processors/DocumentSubscriptionProcessor.ts @@ -61,7 +61,7 @@ export default class DocumentSubscriptionProcessor extends BaseProcessor { ...event, name: "collections.remove_user", userId: groupUser.userId, - }) + } as CollectionUserEvent) ) ); } @@ -83,7 +83,7 @@ export default class DocumentSubscriptionProcessor extends BaseProcessor { ...event, name: "documents.remove_user", userId: groupUser.userId, - }) + } as DocumentUserEvent) ) ); } diff --git a/server/queues/tasks/DetachDraftsFromCollectionTask.ts b/server/queues/tasks/DetachDraftsFromCollectionTask.ts index 8920098671..b6b720ebfb 100644 --- a/server/queues/tasks/DetachDraftsFromCollectionTask.ts +++ b/server/queues/tasks/DetachDraftsFromCollectionTask.ts @@ -7,7 +7,7 @@ import BaseTask from "./BaseTask"; type Props = { collectionId: string; actorId: string; - ip: string; + ip: string | null; }; export default class DetachDraftsFromCollectionTask extends BaseTask { diff --git a/server/queues/tasks/DocumentAddGroupNotificationsTask.ts b/server/queues/tasks/DocumentAddGroupNotificationsTask.ts index e2aa256d79..8a7c3746cc 100644 --- a/server/queues/tasks/DocumentAddGroupNotificationsTask.ts +++ b/server/queues/tasks/DocumentAddGroupNotificationsTask.ts @@ -1,6 +1,6 @@ import { Op } from "sequelize"; import { GroupUser } from "@server/models"; -import { DocumentGroupEvent } from "@server/types"; +import { DocumentGroupEvent, DocumentUserEvent } from "@server/types"; import BaseTask, { TaskPriority } from "./BaseTask"; import DocumentAddUserNotificationsTask from "./DocumentAddUserNotificationsTask"; @@ -21,9 +21,10 @@ export default class DocumentAddGroupNotificationsTask extends BaseTask { await new DocumentAddUserNotificationsTask().schedule({ ...event, + name: "documents.add_user", modelId: event.data.membershipId, userId: groupUser.userId, - }); + } as DocumentUserEvent); }) ); } diff --git a/server/queues/tasks/DocumentImportTask.ts b/server/queues/tasks/DocumentImportTask.ts index 630c02b8a0..82fc2e64c5 100644 --- a/server/queues/tasks/DocumentImportTask.ts +++ b/server/queues/tasks/DocumentImportTask.ts @@ -12,7 +12,7 @@ type Props = { sourceMetadata: Pick, "fileName" | "mimeType">; publish?: boolean; collectionId?: string; - parentDocumentId?: string; + parentDocumentId?: string | null; ip: string; key: string; }; diff --git a/server/routes/api/cron/cron.ts b/server/routes/api/cron/cron.ts index 834d31235c..c2e072be3c 100644 --- a/server/routes/api/cron/cron.ts +++ b/server/routes/api/cron/cron.ts @@ -29,6 +29,7 @@ const cronHandler = async (ctx: APIContext) => { for (const name in tasks) { const TaskClass = tasks[name]; if (TaskClass.cron === period) { + // @ts-expect-error We won't instantiate an abstract class await new TaskClass().schedule({ limit }); // Backwards compatibility for installations that have not set up @@ -38,12 +39,14 @@ const cronHandler = async (ctx: APIContext) => { !receivedPeriods.has(TaskSchedule.Minute) && (period === TaskSchedule.Hour || period === TaskSchedule.Day) ) { + // @ts-expect-error We won't instantiate an abstract class await new TaskClass().schedule({ limit }); } else if ( TaskClass.cron === TaskSchedule.Hour && !receivedPeriods.has(TaskSchedule.Hour) && period === TaskSchedule.Day ) { + // @ts-expect-error We won't instantiate an abstract class await new TaskClass().schedule({ limit }); } } diff --git a/server/routes/api/documents/documents.ts b/server/routes/api/documents/documents.ts index aa93e5918c..084e766e0e 100644 --- a/server/routes/api/documents/documents.ts +++ b/server/routes/api/documents/documents.ts @@ -1549,6 +1549,7 @@ router.post( collectionId, parentDocumentId, publish, + ip: ctx.request.ip, }); const response: DocumentImportTaskResponse = await job.finished(); if ("error" in response) { diff --git a/server/services/cron.ts b/server/services/cron.ts index 26ed88d2f1..7f43f229e8 100644 --- a/server/services/cron.ts +++ b/server/services/cron.ts @@ -7,6 +7,7 @@ export default function init() { for (const name in tasks) { const TaskClass = tasks[name]; if (TaskClass.cron === schedule) { + // @ts-expect-error We won't instantiate an abstract class await new TaskClass().schedule({ limit: 10000 }); } }