mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Explicitly define all comment mutations in schema
Remove `postId` as part of the to-be-saved comment type.
This commit is contained in:
parent
cbc8fc8d83
commit
0bc1444336
@ -18,9 +18,6 @@ export default {
|
|||||||
if (!params.content || content.length < COMMENT_MIN_LENGTH) {
|
if (!params.content || content.length < COMMENT_MIN_LENGTH) {
|
||||||
throw new UserInputError(`Comment must be at least ${COMMENT_MIN_LENGTH} character long!`)
|
throw new UserInputError(`Comment must be at least ${COMMENT_MIN_LENGTH} character long!`)
|
||||||
}
|
}
|
||||||
if (!postId.trim()) {
|
|
||||||
throw new UserInputError(NO_POST_ERR_MESSAGE)
|
|
||||||
}
|
|
||||||
|
|
||||||
const session = context.driver.session()
|
const session = context.driver.session()
|
||||||
const postQueryRes = await session.run(
|
const postQueryRes = await session.run(
|
||||||
|
|||||||
@ -23,7 +23,7 @@ afterEach(async () => {
|
|||||||
|
|
||||||
describe('CreateComment', () => {
|
describe('CreateComment', () => {
|
||||||
const createCommentMutation = gql`
|
const createCommentMutation = gql`
|
||||||
mutation($postId: ID, $content: String!) {
|
mutation($postId: ID!, $content: String!) {
|
||||||
CreateComment(postId: $postId, content: $content) {
|
CreateComment(postId: $postId, content: $content) {
|
||||||
id
|
id
|
||||||
content
|
content
|
||||||
@ -37,13 +37,6 @@ describe('CreateComment', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
const commentQueryForPostId = gql`
|
|
||||||
query($content: String) {
|
|
||||||
Comment(content: $content) {
|
|
||||||
postId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`
|
|
||||||
describe('unauthenticated', () => {
|
describe('unauthenticated', () => {
|
||||||
it('throws authorization error', async () => {
|
it('throws authorization error', async () => {
|
||||||
createCommentVariables = {
|
createCommentVariables = {
|
||||||
@ -191,23 +184,6 @@ describe('CreateComment', () => {
|
|||||||
client.request(createCommentMutation, createCommentVariablesWithNonExistentPost),
|
client.request(createCommentMutation, createCommentVariablesWithNonExistentPost),
|
||||||
).rejects.toThrow('Comment cannot be created without a post!')
|
).rejects.toThrow('Comment cannot be created without a post!')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not create the comment with the postId as an attribute', async () => {
|
|
||||||
const commentQueryVariablesByContent = {
|
|
||||||
content: "I'm authorised to comment",
|
|
||||||
}
|
|
||||||
|
|
||||||
await client.request(createCommentMutation, createCommentVariables)
|
|
||||||
const { Comment } = await client.request(
|
|
||||||
commentQueryForPostId,
|
|
||||||
commentQueryVariablesByContent,
|
|
||||||
)
|
|
||||||
expect(Comment).toEqual([
|
|
||||||
{
|
|
||||||
postId: null,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
type Comment {
|
type Comment {
|
||||||
id: ID!
|
id: ID!
|
||||||
activityId: String
|
activityId: String
|
||||||
postId: ID
|
|
||||||
author: User @relation(name: "WROTE", direction: "IN")
|
author: User @relation(name: "WROTE", direction: "IN")
|
||||||
content: String!
|
content: String!
|
||||||
contentExcerpt: String
|
contentExcerpt: String
|
||||||
@ -11,4 +10,25 @@ type Comment {
|
|||||||
deleted: Boolean
|
deleted: Boolean
|
||||||
disabled: Boolean
|
disabled: Boolean
|
||||||
disabledBy: User @relation(name: "DISABLED", direction: "IN")
|
disabledBy: User @relation(name: "DISABLED", direction: "IN")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Mutation {
|
||||||
|
CreateComment(
|
||||||
|
id: ID
|
||||||
|
postId: ID!
|
||||||
|
content: String!
|
||||||
|
contentExcerpt: String
|
||||||
|
deleted: Boolean
|
||||||
|
disabled: Boolean
|
||||||
|
): Comment
|
||||||
|
UpdateComment(
|
||||||
|
id: ID!
|
||||||
|
content: String
|
||||||
|
contentExcerpt: String
|
||||||
|
deleted: Boolean
|
||||||
|
disabled: Boolean
|
||||||
|
): Comment
|
||||||
|
DeleteComment(
|
||||||
|
id: ID!
|
||||||
|
): Comment
|
||||||
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ export default function(params) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
mutation: `
|
mutation: `
|
||||||
mutation($id: ID!, $postId: ID, $content: String!) {
|
mutation($id: ID!, $postId: ID!, $content: String!) {
|
||||||
CreateComment(id: $id, postId: $postId, content: $content) {
|
CreateComment(id: $id, postId: $postId, content: $content) {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import gql from 'graphql-tag'
|
|||||||
export default () => {
|
export default () => {
|
||||||
return {
|
return {
|
||||||
CreateComment: gql`
|
CreateComment: gql`
|
||||||
mutation($postId: ID, $content: String!) {
|
mutation($postId: ID!, $content: String!) {
|
||||||
CreateComment(postId: $postId, content: $content) {
|
CreateComment(postId: $postId, content: $content) {
|
||||||
id
|
id
|
||||||
contentExcerpt
|
contentExcerpt
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user