diff --git a/backend/src/middleware/handleHtmlContent/handleContentData.js b/backend/src/middleware/handleHtmlContent/handleContentData.js index 6519ddae7..287ba34e6 100644 --- a/backend/src/middleware/handleHtmlContent/handleContentData.js +++ b/backend/src/middleware/handleHtmlContent/handleContentData.js @@ -5,11 +5,12 @@ const notify = async (postId, idsOfMentionedUsers, context) => { const session = context.driver.session() const createdAt = new Date().toISOString() const cypher = ` - match(u:User) where u.id in $idsOfMentionedUsers - match(p:Post) where p.id = $postId - create(n:Notification{id: apoc.create.uuid(), read: false, createdAt: $createdAt}) - merge (n)-[:NOTIFIED]->(u) - merge (p)-[:NOTIFIED]->(n) + MATCH(p:Post {id: $postId})<-[:WROTE]-(author:User) + MATCH(u:User) + WHERE u.id in $idsOfMentionedUsers + AND NOT (u)<-[:BLOCKED]-(author) + CREATE(n:Notification{id: apoc.create.uuid(), read: false, createdAt: $createdAt}) + MERGE (p)-[:NOTIFIED]->(n)-[:NOTIFIED]->(u) ` await session.run(cypher, { idsOfMentionedUsers, diff --git a/backend/src/middleware/handleHtmlContent/handleContentData.spec.js b/backend/src/middleware/handleHtmlContent/handleContentData.spec.js index 1effeb5d6..40d8a2481 100644 --- a/backend/src/middleware/handleHtmlContent/handleContentData.spec.js +++ b/backend/src/middleware/handleHtmlContent/handleContentData.spec.js @@ -77,7 +77,7 @@ describe('notifications', () => { const content = 'Hey @al-capone how do you do?' - beforeEach(async () => { + const createPostAction = async () => { const createPostMutation = gql` mutation($id: ID, $title: String!, $content: String!) { CreatePost(id: $id, title: $title, content: $content) { @@ -93,9 +93,10 @@ describe('notifications', () => { variables: { id: 'p47', title, content }, }) authenticatedUser = await user.toJson() - }) + } it('sends you a notification', async () => { + await createPostAction() const expectedContent = 'Hey @al-capone how do you do?' const expected = expect.objectContaining({ @@ -110,7 +111,7 @@ describe('notifications', () => { }) describe('who mentions me many times', () => { - beforeEach(async () => { + const updatePostAction = async () => { const updatedContent = ` One more mention to @@ -143,9 +144,11 @@ describe('notifications', () => { }, }) authenticatedUser = await user.toJson() - }) + } it('creates exactly one more notification', async () => { + await createPostAction() + await updatePostAction() const expectedContent = '
One more mention to

@al-capone

and again:

@al-capone

and again

@al-capone

' const expected = expect.objectContaining({ @@ -163,6 +166,23 @@ describe('notifications', () => { ).resolves.toEqual(expected) }) }) + + describe('but the author of the post blocked me', () => { + beforeEach(async () => { + await author.relateTo(user, 'blocked') + }) + + it('sends no notification', async () => { + await createPostAction() + const expected = expect.objectContaining({ + data: { currentUser: { notifications: [] } }, + }) + const { query } = createTestClient(server) + await expect( + query({ query: notificationQuery, variables: { read: false } }), + ).resolves.toEqual(expected) + }) + }) }) }) })