mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Fix middleware/spec
This commit is contained in:
parent
5d63dda6ee
commit
f5545e3976
@ -371,7 +371,7 @@ describe('notifications', () => {
|
|||||||
expect(readAfter).toEqual(false)
|
expect(readAfter).toEqual(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('updates the `createdAt` attribute', async () => {
|
it('does not update the `createdAt` attribute', async () => {
|
||||||
await createPostAction()
|
await createPostAction()
|
||||||
await markAsReadAction()
|
await markAsReadAction()
|
||||||
const {
|
const {
|
||||||
|
|||||||
@ -86,19 +86,20 @@ const validateReview = async (resolve, root, args, context, info) => {
|
|||||||
const [existingReportedResource] = reportQueryRes.records.map(record => {
|
const [existingReportedResource] = reportQueryRes.records.map(record => {
|
||||||
return {
|
return {
|
||||||
label: record.get('label'),
|
label: record.get('label'),
|
||||||
author: record.get('author').properties,
|
author: record.get('author'),
|
||||||
filed: record.get('filed'),
|
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)
|
if (!existingReportedResource.filed)
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Before starting the review process, please report the ${existingReportedResource.label}!`,
|
`Before starting the review process, please report the ${existingReportedResource.label}!`,
|
||||||
)
|
)
|
||||||
const authorId =
|
const authorId =
|
||||||
existingReportedResource.label !== 'User' && existingReportedResource.author
|
existingReportedResource.label !== 'User' && existingReportedResource.author
|
||||||
? existingReportedResource.author.id
|
? existingReportedResource.author.properties.id
|
||||||
: null
|
: null
|
||||||
if (authorId && authorId === user.id)
|
if (authorId && authorId === user.id)
|
||||||
throw new Error(`You cannot review your own ${existingReportedResource.label}!`)
|
throw new Error(`You cannot review your own ${existingReportedResource.label}!`)
|
||||||
|
|||||||
@ -122,7 +122,7 @@ describe('validateReview', () => {
|
|||||||
mutate({ mutation: reviewMutation, variables: disableVariables }),
|
mutate({ mutation: reviewMutation, variables: disableVariables }),
|
||||||
).resolves.toMatchObject({
|
).resolves.toMatchObject({
|
||||||
data: { review: null },
|
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!' }],
|
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!' }],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user