Implement delete of comments when post is deleted

This commit is contained in:
roschaefer 2019-09-02 11:11:11 +02:00
parent 1b5d91bfd2
commit 660e3434aa
2 changed files with 42 additions and 1 deletions

View File

@ -146,10 +146,12 @@ export default {
const transactionRes = await session.run(
`
MATCH (post:Post {id: $postId})
OPTIONAL MATCH (post)<-[:COMMENTS]-(comment:Comment)
SET post.deleted = TRUE
SET post.image = 'DELETED'
SET post.content = 'DELETED'
SET post.contentExcerpt = 'DELETED'
SET comment.deleted = TRUE
RETURN post
`,
{ postId: args.id },

View File

@ -417,6 +417,11 @@ describe('DeletePost', () => {
content
contentExcerpt
image
comments {
deleted
content
contentExcerpt
}
}
}
`
@ -466,6 +471,7 @@ describe('DeletePost', () => {
content: 'DELETED',
contentExcerpt: 'DELETED',
image: 'DELETED',
comments: [],
},
},
}
@ -474,7 +480,40 @@ describe('DeletePost', () => {
)
})
it.todo('marks all comments as deleted')
describe('if there are comments on the post', () => {
beforeEach(async () => {
await factory.create('Comment', {
postId: 'p4711',
content: 'to be deleted comment content',
contentExcerpt: 'to be deleted comment content',
})
})
it('marks the comments as deleted', async () => {
const expected = {
data: {
DeletePost: {
id: 'p4711',
deleted: true,
content: 'DELETED',
contentExcerpt: 'DELETED',
image: 'DELETED',
comments: [
{
deleted: true,
// Should we black out the comment content in the database, too?
content: 'to be deleted comment content',
contentExcerpt: 'to be deleted comment content',
},
],
},
},
}
await expect(mutate({ mutation: deletePostMutation, variables })).resolves.toMatchObject(
expected,
)
})
})
})
})