Add test cases for review workflow

This commit is contained in:
mattwr18 2019-11-29 19:45:52 +01:00
parent f5545e3976
commit bbd80fbc23
2 changed files with 49 additions and 38 deletions

View File

@ -18,12 +18,13 @@ export default {
const session = driver.session()
try {
const cypher = `
MATCH (resource {id: $params.resourceId})<-[:BELONGS_TO]-(report:Report {closed: false})
MATCH (moderator:User {id: $moderatorId})
MATCH (resource {id: $params.resourceId})<-[:BELONGS_TO]-(report:Report {closed: false})
WHERE resource:User OR resource:Post OR resource:Comment
MERGE (report)<-[review:REVIEWED { disable: $params.disable, closed: $params.closed }]-(moderator)
MERGE (report)<-[review:REVIEWED]-(moderator)
ON CREATE SET review.createdAt = $dateTime, review.updatedAt = review.createdAt
ON MATCH SET review.updatedAt = $dateTime
SET review.disable = $params.disable, review.closed = $params.closed
SET report.updatedAt = $dateTime, report.closed = review.closed
SET resource.disabled = review.disable

View File

@ -159,6 +159,41 @@ describe('moderate resources', () => {
errors: undefined,
})
})
it('creates only one review for multiple reviews by the same moderator on same resource', async () => {
await Promise.all([
mutate({
mutation: reviewMutation,
variables: { ...disableVariables, resourceId: 'should-i-be-disabled' },
}),
mutate({
mutation: reviewMutation,
variables: { ...enableVariables, resourceId: 'should-i-be-disabled' },
}),
])
const cypher =
'MATCH (:Report)<-[review:REVIEWED]-(moderator:User {id: "moderator-id"}) RETURN review'
const reviews = await neode.cypher(cypher)
expect(reviews.records).toHaveLength(1)
})
it('updates the updatedAt attribute', async () => {
const [firstReview, secondReview] = await Promise.all([
mutate({
mutation: reviewMutation,
variables: { ...disableVariables, resourceId: 'should-i-be-disabled' },
}),
mutate({
mutation: reviewMutation,
variables: { ...enableVariables, resourceId: 'should-i-be-disabled' },
}),
])
expect(firstReview.data.review.updatedAt).toBeTruthy()
expect(Date.parse(firstReview.data.review.updatedAt)).toEqual(expect.any(Number))
expect(secondReview.data.review.updatedAt).toBeTruthy()
expect(Date.parse(secondReview.data.review.updatedAt)).toEqual(expect.any(Number))
expect(firstReview.data.review.updatedAt).not.toEqual(secondReview.data.review.updatedAt)
})
})
})
@ -192,24 +227,6 @@ describe('moderate resources', () => {
authenticatedUser = await moderator.toJson()
})
describe('review of a resource that is not a (Comment|Post|User) ', () => {
beforeEach(async () => {
disableVariables = {
...disableVariables,
resourceId: 'tag-id',
}
await factory.create('Tag', { id: 'tag-id' })
})
it('returns null', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: disableVariables }),
).resolves.toMatchObject({
data: { review: null },
})
})
})
describe('moderate a comment', () => {
beforeEach(async () => {
const trollingComment = await factory.create('Comment', {
@ -254,6 +271,7 @@ describe('moderate resources', () => {
},
},
},
errors: undefined,
})
})
@ -264,6 +282,7 @@ describe('moderate resources', () => {
data: {
review: { resource: { __typename: 'Comment', id: 'comment-id', disabled: true } },
},
errors: undefined,
})
})
@ -281,6 +300,7 @@ describe('moderate resources', () => {
report: { id: expect.any(String), closed: true },
},
},
errors: undefined,
})
})
})
@ -314,6 +334,7 @@ describe('moderate resources', () => {
resource: { __typename: 'Post', id: 'post-id' },
},
},
errors: undefined,
})
})
@ -332,6 +353,7 @@ describe('moderate resources', () => {
},
},
},
errors: undefined,
})
})
@ -340,6 +362,7 @@ describe('moderate resources', () => {
mutate({ mutation: reviewMutation, variables: disableVariables }),
).resolves.toMatchObject({
data: { review: { resource: { __typename: 'Post', id: 'post-id', disabled: true } } },
errors: undefined,
})
})
@ -357,6 +380,7 @@ describe('moderate resources', () => {
report: { id: expect.any(String), closed: true },
},
},
errors: undefined,
})
})
})
@ -386,6 +410,7 @@ describe('moderate resources', () => {
mutate({ mutation: reviewMutation, variables: disableVariables }),
).resolves.toMatchObject({
data: { review: { resource: { __typename: 'User', id: 'user-id' } } },
errors: undefined,
})
})
@ -404,6 +429,7 @@ describe('moderate resources', () => {
},
},
},
errors: undefined,
})
})
@ -412,6 +438,7 @@ describe('moderate resources', () => {
mutate({ mutation: reviewMutation, variables: disableVariables }),
).resolves.toMatchObject({
data: { review: { resource: { __typename: 'User', id: 'user-id', disabled: true } } },
errors: undefined,
})
})
@ -429,6 +456,7 @@ describe('moderate resources', () => {
report: { id: expect.any(String), closed: true },
},
},
errors: undefined,
})
})
})
@ -474,24 +502,6 @@ describe('moderate resources', () => {
authenticatedUser = await moderator.toJson()
})
describe('moderate a resource that is not a (Comment|Post|User) ', () => {
beforeEach(async () => {
await Promise.all([factory.create('Tag', { id: 'tag-id' })])
})
it('returns null', async () => {
enableVariables = {
...enableVariables,
resourceId: 'tag-id',
}
await expect(
mutate({ mutation: reviewMutation, variables: enableVariables }),
).resolves.toMatchObject({
data: { review: null },
})
})
})
describe('moderate a comment', () => {
beforeEach(async () => {
const trollingComment = await factory.create('Comment', {