From 063ff17d8bc96a41fa38cb6bcc675bc722bdcbf6 Mon Sep 17 00:00:00 2001 From: Kapil Jain Date: Wed, 30 Oct 2019 20:39:50 -0400 Subject: [PATCH] add software tests for two notifications bug --- .../notificationsMiddleware.spec.js | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/backend/src/middleware/notifications/notificationsMiddleware.spec.js b/backend/src/middleware/notifications/notificationsMiddleware.spec.js index 88f91d688..9d397cbe0 100644 --- a/backend/src/middleware/notifications/notificationsMiddleware.spec.js +++ b/backend/src/middleware/notifications/notificationsMiddleware.spec.js @@ -105,6 +105,7 @@ describe('notifications', () => { let title let postContent let postAuthor + const createPostAction = async () => { authenticatedUser = await postAuthor.toJson() await mutate({ @@ -239,6 +240,7 @@ describe('notifications', () => { describe('mentions me in a post', () => { beforeEach(async () => { title = 'Mentioning Al Capone' + postContent = 'Hey @al-capone how do you do?' }) @@ -439,7 +441,15 @@ describe('notifications', () => { }) }) - it('sends a notification', async () => { + it('sends only one notification with reason mentioned_in_comment', async () => { + postAuthor = await instance.create('User', { + id: 'postAuthor', + name: 'Mr Author', + slug: 'mr-author', + email: 'post-author@example.org', + password: '1234', + }) + await createCommentOnPostAction() const expected = expect.objectContaining({ data: { @@ -467,6 +477,53 @@ describe('notifications', () => { }), ).resolves.toEqual(expected) }) + + beforeEach(async () => { + title = 'Post where Im the author and I get mentioned in a comment' + postContent = 'Content of post where I get mentioned in a comment.' + postAuthor = notifiedUser + const createPostAction = async () => { + authenticatedUser = await postAuthor.toJson() + await mutate({ + mutation: createPostMutation, + variables: { + id: 'p49', + title, + postContent, + categoryIds, + }, + }) + authenticatedUser = await notifiedUser.toJson() + } + }) + it('sends only one notification with reason commented_on_post, no notification with reason mentioned_in_comment', async () => { + await createCommentOnPostAction() + const expected = expect.objectContaining({ + data: { + notifications: [ + { + read: false, + createdAt: expect.any(String), + reason: 'commented_on_post', + from: { + __typename: 'Comment', + id: 'c47', + content: commentContent, + }, + }, + ], + }, + }) + const { query } = createTestClient(server) + await expect( + query({ + query: notificationQuery, + variables: { + read: false, + }, + }), + ).resolves.toEqual(expected) + }) }) describe('but the author of the post blocked me', () => {