From 994ab439503d535208271ecd5db1cbeeba24ffc5 Mon Sep 17 00:00:00 2001 From: roschaefer Date: Fri, 30 Aug 2019 10:40:53 +0200 Subject: [PATCH] Change the behaviour how notifications get created I think it makes more sense to update an existing notification in place. Ie. if there was already a notification, just mark it as unread so it ends up in the recipient's notification list again. --- .../notificationsMiddleware.spec.js | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/backend/src/middleware/notifications/notificationsMiddleware.spec.js b/backend/src/middleware/notifications/notificationsMiddleware.spec.js index 709ea7ba1..9c0fb61bf 100644 --- a/backend/src/middleware/notifications/notificationsMiddleware.spec.js +++ b/backend/src/middleware/notifications/notificationsMiddleware.spec.js @@ -83,9 +83,11 @@ describe('notifications', () => { from { __typename ... on Post { + id content } ... on Comment { + id content } } @@ -161,6 +163,7 @@ describe('notifications', () => { reason: 'comment_on_post', from: { __typename: 'Comment', + id: 'c47', content: commentContent, }, }, @@ -250,6 +253,7 @@ describe('notifications', () => { reason: 'mentioned_in_post', from: { __typename: 'Post', + id: 'p47', content: expectedContent, }, }, @@ -267,7 +271,7 @@ describe('notifications', () => { ).resolves.toEqual(expected) }) - describe('many times', () => { + describe('updates the post and mentions me again', () => { const updatePostAction = async () => { const updatedContent = ` One more mention to @@ -296,7 +300,7 @@ describe('notifications', () => { authenticatedUser = await notifiedUser.toJson() } - it('creates exactly one more notification', async () => { + it('creates no duplicate notification for the same resource', async () => { await createPostAction() await updatePostAction() const expectedContent = @@ -309,14 +313,7 @@ describe('notifications', () => { reason: 'mentioned_in_post', from: { __typename: 'Post', - content: expectedContent, - }, - }, - { - read: false, - reason: 'mentioned_in_post', - from: { - __typename: 'Post', + id: 'p47', content: expectedContent, }, }, @@ -334,6 +331,13 @@ describe('notifications', () => { }) }) + describe('if the notification was marked as read earlier', () => { + describe('but the next mentioning happens after the notification was marked as read', () => { + it.todo('sets the `read` attribute to false again') + it.todo('updates the `createdAt` attribute') + }) + }) + describe('but the author of the post blocked me', () => { beforeEach(async () => { await postAuthor.relateTo(notifiedUser, 'blocked') @@ -386,6 +390,7 @@ describe('notifications', () => { reason: 'mentioned_in_comment', from: { __typename: 'Comment', + id: 'c47', content: commentContent, }, },