Add tests for suspended user notification prevention

Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-03 03:00:02 +00:00
parent 68193aca7a
commit f317ebf047
2 changed files with 60 additions and 0 deletions
@@ -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();
});
});
@@ -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();
});
});