mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +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) {
|
||||
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 postQueryRes = await session.run(
|
||||
|
||||
@ -23,7 +23,7 @@ afterEach(async () => {
|
||||
|
||||
describe('CreateComment', () => {
|
||||
const createCommentMutation = gql`
|
||||
mutation($postId: ID, $content: String!) {
|
||||
mutation($postId: ID!, $content: String!) {
|
||||
CreateComment(postId: $postId, content: $content) {
|
||||
id
|
||||
content
|
||||
@ -37,13 +37,6 @@ describe('CreateComment', () => {
|
||||
}
|
||||
}
|
||||
`
|
||||
const commentQueryForPostId = gql`
|
||||
query($content: String) {
|
||||
Comment(content: $content) {
|
||||
postId
|
||||
}
|
||||
}
|
||||
`
|
||||
describe('unauthenticated', () => {
|
||||
it('throws authorization error', async () => {
|
||||
createCommentVariables = {
|
||||
@ -191,23 +184,6 @@ describe('CreateComment', () => {
|
||||
client.request(createCommentMutation, createCommentVariablesWithNonExistentPost),
|
||||
).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 {
|
||||
id: ID!
|
||||
activityId: String
|
||||
postId: ID
|
||||
author: User @relation(name: "WROTE", direction: "IN")
|
||||
content: String!
|
||||
contentExcerpt: String
|
||||
@ -11,4 +10,25 @@ type Comment {
|
||||
deleted: Boolean
|
||||
disabled: Boolean
|
||||
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 {
|
||||
mutation: `
|
||||
mutation($id: ID!, $postId: ID, $content: String!) {
|
||||
mutation($id: ID!, $postId: ID!, $content: String!) {
|
||||
CreateComment(id: $id, postId: $postId, content: $content) {
|
||||
id
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ import gql from 'graphql-tag'
|
||||
export default () => {
|
||||
return {
|
||||
CreateComment: gql`
|
||||
mutation($postId: ID, $content: String!) {
|
||||
mutation($postId: ID!, $content: String!) {
|
||||
CreateComment(postId: $postId, content: $content) {
|
||||
id
|
||||
contentExcerpt
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user