Fix middleware/spec

This commit is contained in:
mattwr18 2019-11-29 19:45:34 +01:00
parent 5d63dda6ee
commit f5545e3976
3 changed files with 25 additions and 5 deletions

View File

@ -371,7 +371,7 @@ describe('notifications', () => {
expect(readAfter).toEqual(false)
})
it('updates the `createdAt` attribute', async () => {
it('does not update the `createdAt` attribute', async () => {
await createPostAction()
await markAsReadAction()
const {

View File

@ -86,19 +86,20 @@ const validateReview = async (resolve, root, args, context, info) => {
const [existingReportedResource] = reportQueryRes.records.map(record => {
return {
label: record.get('label'),
author: record.get('author').properties,
author: record.get('author'),
filed: record.get('filed'),
}
})
if (!existingReportedResource) throw new Error(`Resource not found!`)
if (!existingReportedResource)
throw new Error(`Resource not found or is not a Post|Comment|User!`)
if (!existingReportedResource.filed)
throw new Error(
`Before starting the review process, please report the ${existingReportedResource.label}!`,
)
const authorId =
existingReportedResource.label !== 'User' && existingReportedResource.author
? existingReportedResource.author.id
? existingReportedResource.author.properties.id
: null
if (authorId && authorId === user.id)
throw new Error(`You cannot review your own ${existingReportedResource.label}!`)

View File

@ -122,7 +122,7 @@ describe('validateReview', () => {
mutate({ mutation: reviewMutation, variables: disableVariables }),
).resolves.toMatchObject({
data: { review: null },
errors: [{ message: 'Resource not found!' }],
errors: [{ message: 'Resource not found or is not a Post|Comment|User!' }],
})
})
@ -153,4 +153,23 @@ describe('validateReview', () => {
errors: [{ message: 'You cannot review your own Post!' }],
})
})
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 () => {
disableVariables = {
...disableVariables,
resourceId: 'tag-id',
}
await expect(
mutate({ mutation: reviewMutation, variables: disableVariables }),
).resolves.toMatchObject({
data: { review: null },
errors: [{ message: 'Resource not found or is not a Post|Comment|User!' }],
})
})
})
})