diff --git a/backend/src/middleware/validation/validationMiddleware.js b/backend/src/middleware/validation/validationMiddleware.js index 086b657ff..20933a777 100644 --- a/backend/src/middleware/validation/validationMiddleware.js +++ b/backend/src/middleware/validation/validationMiddleware.js @@ -2,8 +2,6 @@ import { UserInputError } from 'apollo-server' const COMMENT_MIN_LENGTH = 1 const NO_POST_ERR_MESSAGE = 'Comment cannot be created without a post!' -const NO_CATEGORIES_ERR_MESSAGE = - 'You cannot save a post without at least one category or more than three' const USERNAME_MIN_LENGTH = 3 const validateCreateComment = async (resolve, root, args, context, info) => { const content = args.content.replace(/<(?:.|\n)*?>/gm, '').trim() @@ -46,20 +44,6 @@ const validateUpdateComment = async (resolve, root, args, context, info) => { return resolve(root, args, context, info) } -const validatePost = async (resolve, root, args, context, info) => { - const { categoryIds } = args - if (!Array.isArray(categoryIds) || !categoryIds.length || categoryIds.length > 3) { - throw new UserInputError(NO_CATEGORIES_ERR_MESSAGE) - } - return resolve(root, args, context, info) -} - -const validateUpdatePost = async (resolve, root, args, context, info) => { - const { categoryIds } = args - if (typeof categoryIds === 'undefined') return resolve(root, args, context, info) - return validatePost(resolve, root, args, context, info) -} - const validateReport = async (resolve, root, args, context, info) => { const { resourceId } = args const { user } = context diff --git a/backend/src/middleware/validation/validationMiddleware.spec.js b/backend/src/middleware/validation/validationMiddleware.spec.js index efb85bd10..c3d518256 100644 --- a/backend/src/middleware/validation/validationMiddleware.spec.js +++ b/backend/src/middleware/validation/validationMiddleware.spec.js @@ -30,27 +30,7 @@ const updateCommentMutation = gql` } } ` -const createPostMutation = gql` - mutation($id: ID, $title: String!, $content: String!, $language: String, $categoryIds: [ID]) { - CreatePost( - id: $id - title: $title - content: $content - language: $language - categoryIds: $categoryIds - ) { - id - } - } -` -const updatePostMutation = gql` - mutation($id: ID!, $title: String!, $content: String!, $categoryIds: [ID]) { - UpdatePost(id: $id, title: $title, content: $content, categoryIds: $categoryIds) { - id - } - } -` const reportMutation = gql` mutation($resourceId: ID!, $reasonCategory: ReasonCategory!, $reasonDescription: String!) { fileReport( @@ -227,104 +207,6 @@ describe('validateCreateComment', () => { }) }) }) - - describe('validatePost', () => { - let createPostVariables - beforeEach(async () => { - createPostVariables = { - title: 'I am a title', - content: 'Some content', - } - authenticatedUser = await commentingUser.toJson() - }) - - describe('categories', () => { - describe('null', () => { - it.skip('throws UserInputError', async () => { - createPostVariables = { ...createPostVariables, categoryIds: null } - await expect( - mutate({ mutation: createPostMutation, variables: createPostVariables }), - ).resolves.toMatchObject({ - data: { CreatePost: null }, - errors: [ - { - message: 'You cannot save a post without at least one category or more than three', - }, - ], - }) - }) - }) - - describe('empty', () => { - it.skip('throws UserInputError', async () => { - createPostVariables = { ...createPostVariables, categoryIds: [] } - await expect( - mutate({ mutation: createPostMutation, variables: createPostVariables }), - ).resolves.toMatchObject({ - data: { CreatePost: null }, - errors: [ - { - message: 'You cannot save a post without at least one category or more than three', - }, - ], - }) - }) - }) - - describe('more than 3 categoryIds', () => { - it.skip('throws UserInputError', async () => { - createPostVariables = { - ...createPostVariables, - categoryIds: ['cat9', 'cat27', 'cat15', 'cat4'], - } - await expect( - mutate({ mutation: createPostMutation, variables: createPostVariables }), - ).resolves.toMatchObject({ - data: { CreatePost: null }, - errors: [ - { - message: 'You cannot save a post without at least one category or more than three', - }, - ], - }) - }) - }) - }) - }) - - describe('validateUpdatePost', () => { - describe('post created without categories somehow', () => { - let owner, updatePostVariables - beforeEach(async () => { - const postSomehowCreated = await neode.create('Post', { - id: 'how-was-this-created', - }) - owner = await neode.create('User', { - id: 'author-of-post-without-category', - slug: 'hacker', - }) - await postSomehowCreated.relateTo(owner, 'author') - authenticatedUser = await owner.toJson() - updatePostVariables = { - id: 'how-was-this-created', - title: 'I am a title', - content: 'Some content', - categoryIds: [], - } - }) - - it.skip('requires at least one category for successful update', async () => { - await expect( - mutate({ mutation: updatePostMutation, variables: updatePostVariables }), - ).resolves.toMatchObject({ - data: { UpdatePost: null }, - errors: [ - { message: 'You cannot save a post without at least one category or more than three' }, - ], - }) - }) - }) - }) }) describe('validateReport', () => {