diff --git a/backend/src/middleware/index.js b/backend/src/middleware/index.js index 39bb0e775..4f725ef72 100644 --- a/backend/src/middleware/index.js +++ b/backend/src/middleware/index.js @@ -20,9 +20,9 @@ export default schema => { validUrlMiddleware, sluggifyMiddleware, excerptMiddleware, + notificationsMiddleware, xssMiddleware, fixImageUrlsMiddleware, - notificationsMiddleware, softDeleteMiddleware, userMiddleware, includedFieldsMiddleware, diff --git a/backend/src/middleware/notifications/index.js b/backend/src/middleware/notifications/index.js index 0efd140d2..89d86bed3 100644 --- a/backend/src/middleware/notifications/index.js +++ b/backend/src/middleware/notifications/index.js @@ -1,20 +1,20 @@ import extractIds from './extractMentions' const notify = async (resolve, root, args, context, resolveInfo) => { + const ids = extractIds(args.content) // before mention class gets removed const post = await resolve(root, args, context, resolveInfo) const session = context.driver.session() const { content, id: postId } = post - const slugs = extractIds(content) const createdAt = (new Date()).toISOString() const cypher = ` - match(u:User) where u.slug in $slugs + match(u:User) where u.id in $ids 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) ` - await session.run(cypher, { slugs, createdAt, postId }) + await session.run(cypher, { ids, createdAt, postId }) session.close() return post diff --git a/backend/src/middleware/notifications/spec.js b/backend/src/middleware/notifications/spec.js index 656f10636..c7dd99613 100644 --- a/backend/src/middleware/notifications/spec.js +++ b/backend/src/middleware/notifications/spec.js @@ -54,26 +54,31 @@ describe('currentUser { notifications }', () => { }) describe('who mentions me in a post', () => { + let post + const title = 'Mentioning Al Capone' + const content = 'Hey @al-capone how do you do?' + beforeEach(async () => { - const content = 'Hey @al-capone how do you do?' - const title = 'Mentioning Al Capone' const createPostMutation = ` mutation($title: String!, $content: String!) { CreatePost(title: $title, content: $content) { + id title content } } ` authorClient = new GraphQLClient(host, { headers: authorHeaders }) - await authorClient.request(createPostMutation, { title, content }) + const { CreatePost } = await authorClient.request(createPostMutation, { title, content }) + post = CreatePost }) it('sends you a notification', async () => { + const newContent = 'Hey @al-capone how do you do?' const expected = { currentUser: { notifications: [ - { read: false, post: { content: 'Hey @al-capone how do you do?' } } + { read: false, post: { content: newContent } } ] } }