Update to allow single character comments or greater

This commit is contained in:
Matt Rider 2019-04-29 12:19:27 -03:00
parent 30d0ff3cc7
commit 1b84ccbdfa
3 changed files with 7 additions and 7 deletions

View File

@ -1,7 +1,7 @@
import { neo4jgraphql } from 'neo4j-graphql-js'
import { UserInputError } from 'apollo-server'
const COMMENT_MIN_LENGTH = 3
const COMMENT_MIN_LENGTH = 1
export default {
Query: {
CommentByPost: async (object, params, context, resolveInfo) => {
@ -28,7 +28,7 @@ export default {
const content = params.content.replace(/<(?:.|\n)*?>/gm, '').trim()
if (!params.content || content.length < COMMENT_MIN_LENGTH) {
throw new UserInputError(`Comment must be at least ${COMMENT_MIN_LENGTH} characters long!`)
throw new UserInputError(`Comment must be at least ${COMMENT_MIN_LENGTH} character long!`)
}
const { postId } = params
delete params.postId

View File

@ -65,17 +65,17 @@ describe('CreateComment', () => {
}
await expect(client.request(mutation, variables))
.rejects.toThrow('Comment must be at least 3 characters long!')
.rejects.toThrow('Comment must be at least 1 character long!')
})
it('throws an error if a comment is less than 3 characters', async () => {
it('throws an error if a comment does not contain a single character', async () => {
variables = {
postId: 'p1',
content: '<p>ab</p>'
content: '<p> </p>'
}
await expect(client.request(mutation, variables))
.rejects.toThrow('Comment must be at least 3 characters long!')
.rejects.toThrow('Comment must be at least 1 character long!')
})
})
})

View File

@ -64,7 +64,7 @@ export default {
methods: {
updateEditorContent(value) {
const content = value.replace(/<(?:.|\n)*?>/gm, '').trim()
if (content.length < 3) {
if (content.length < 1) {
this.disabled = true
} else {
this.disabled = false