From 7fe6fb110b795095095d3d9d5517e45e700a998a Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Tue, 18 Feb 2020 22:21:49 +0100 Subject: [PATCH] Remove unnecessary negation of negation, refactor - tests to use `toMatchObject`, which checks that only one notification is indeed created --- .../src/middleware/notifications/notificationsMiddleware.js | 2 +- .../notifications/notificationsMiddleware.spec.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/middleware/notifications/notificationsMiddleware.js b/backend/src/middleware/notifications/notificationsMiddleware.js index 26c27bb10..64eca97c8 100644 --- a/backend/src/middleware/notifications/notificationsMiddleware.js +++ b/backend/src/middleware/notifications/notificationsMiddleware.js @@ -112,7 +112,7 @@ const notifyUsersOfMention = async (label, id, idsOfUsers, reason, context) => { } const notifyUsersOfComment = async (label, commentId, postAuthorId, reason, context) => { - if (!(context.user.id !== postAuthorId)) return [] + if (context.user.id === postAuthorId) return [] await validateNotifyUsers(label, reason) const session = context.driver.session() const writeTxResultPromise = await session.writeTransaction(async transaction => { diff --git a/backend/src/middleware/notifications/notificationsMiddleware.spec.js b/backend/src/middleware/notifications/notificationsMiddleware.spec.js index 16e33bdfb..af4ed9693 100644 --- a/backend/src/middleware/notifications/notificationsMiddleware.spec.js +++ b/backend/src/middleware/notifications/notificationsMiddleware.spec.js @@ -528,7 +528,7 @@ describe('notifications', () => { }) it('sends only one notification with reason commented_on_post, no notification with reason mentioned_in_comment', async () => { await createCommentOnPostAction() - const expected = expect.objectContaining({ + const expected = { data: { notifications: [ { @@ -543,7 +543,7 @@ describe('notifications', () => { }, ], }, - }) + } await expect( query({ @@ -552,7 +552,7 @@ describe('notifications', () => { read: false, }, }), - ).resolves.toEqual(expected) + ).resolves.toMatchObject(expected, { errors: undefined }) }) })