diff --git a/backend/src/middleware/notifications/notificationsMiddleware.spec.js b/backend/src/middleware/notifications/notificationsMiddleware.spec.js index 502ddaa8e..2122d009b 100644 --- a/backend/src/middleware/notifications/notificationsMiddleware.spec.js +++ b/backend/src/middleware/notifications/notificationsMiddleware.spec.js @@ -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 { diff --git a/backend/src/middleware/validation/validationMiddleware.js b/backend/src/middleware/validation/validationMiddleware.js index bbde03df6..b8c539a0f 100644 --- a/backend/src/middleware/validation/validationMiddleware.js +++ b/backend/src/middleware/validation/validationMiddleware.js @@ -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}!`) diff --git a/backend/src/middleware/validation/validationMiddleware.spec.js b/backend/src/middleware/validation/validationMiddleware.spec.js index 9448d50cf..87fc2a329 100644 --- a/backend/src/middleware/validation/validationMiddleware.spec.js +++ b/backend/src/middleware/validation/validationMiddleware.spec.js @@ -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!' }], + }) + }) + }) })