From f317ebf0479b026c32d4fc89a4bd414472ca7ce4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 3 Dec 2025 03:00:02 +0000 Subject: [PATCH] Add tests for suspended user notification prevention Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> --- ...DocumentPublishedNotificationsTask.test.ts | 23 ++++++++++++ .../RevisionCreatedNotificationsTask.test.ts | 37 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/server/queues/tasks/DocumentPublishedNotificationsTask.test.ts b/server/queues/tasks/DocumentPublishedNotificationsTask.test.ts index 406aa7f313..4db114fc05 100644 --- a/server/queues/tasks/DocumentPublishedNotificationsTask.test.ts +++ b/server/queues/tasks/DocumentPublishedNotificationsTask.test.ts @@ -119,4 +119,27 @@ describe("documents.publish", () => { }); expect(spy).not.toHaveBeenCalled(); }); + + test("should not send a notification to suspended users", async () => { + const spy = jest.spyOn(Notification, "create"); + const user = await buildUser(); + const document = await buildDocument({ + teamId: user.teamId, + }); + // Suspend the user + user.suspendedAt = new Date(); + user.setNotificationEventType(NotificationEventType.PublishDocument); + await user.save(); + + const processor = new DocumentPublishedNotificationsTask(); + await processor.perform({ + name: "documents.publish", + documentId: document.id, + collectionId: document.collectionId!, + teamId: document.teamId, + actorId: document.createdById, + ip, + }); + expect(spy).not.toHaveBeenCalled(); + }); }); diff --git a/server/queues/tasks/RevisionCreatedNotificationsTask.test.ts b/server/queues/tasks/RevisionCreatedNotificationsTask.test.ts index f943ee1425..23b08baed6 100644 --- a/server/queues/tasks/RevisionCreatedNotificationsTask.test.ts +++ b/server/queues/tasks/RevisionCreatedNotificationsTask.test.ts @@ -514,4 +514,41 @@ describe("revisions.create", () => { }); expect(spy).not.toHaveBeenCalled(); }); + + test("should not send a notification to suspended users", async () => { + const spy = jest.spyOn(Notification, "create"); + const user = await buildUser(); + let document = await buildDocument({ + teamId: user.teamId, + userId: user.id, + }); + await Revision.createFromDocument(createContext({ user }), document); + + document = updateDocumentText(document, "Updated body content"); + const collaborator = await buildUser({ + teamId: document.teamId, + suspendedAt: new Date(), + }); + const revision = await Revision.createFromDocument( + createContext({ user: collaborator }), + document + ); + document.collaboratorIds = [user.id, collaborator.id]; + await document.save(); + + // Suspend the user who should receive the notification + user.suspendedAt = new Date(); + await user.save(); + + const task = new RevisionCreatedNotificationsTask(); + await task.perform({ + name: "revisions.create", + documentId: document.id, + teamId: document.teamId, + actorId: collaborator.id, + modelId: revision.id, + ip, + }); + expect(spy).not.toHaveBeenCalled(); + }); });