diff --git a/backend/src/graphql/posts.js b/backend/src/graphql/posts.js index 2669d6f24..5fd5790ee 100644 --- a/backend/src/graphql/posts.js +++ b/backend/src/graphql/posts.js @@ -11,6 +11,7 @@ export const createPostMutation = () => { $content: String! $categoryIds: [ID] $groupId: ID + $postType: PostType ) { CreatePost( id: $id @@ -19,11 +20,18 @@ export const createPostMutation = () => { content: $content categoryIds: $categoryIds groupId: $groupId + postType: $postType ) { id slug title content + disabled + deleted + postType + author { + name + } } } ` diff --git a/backend/src/schema/resolvers/posts.spec.js b/backend/src/schema/resolvers/posts.spec.js index b9b369cef..a4d28a92a 100644 --- a/backend/src/schema/resolvers/posts.spec.js +++ b/backend/src/schema/resolvers/posts.spec.js @@ -3,6 +3,7 @@ import Factory, { cleanDatabase } from '../../db/factories' import gql from 'graphql-tag' import { getNeode, getDriver } from '../../db/neo4j' import createServer from '../../server' +import { createPostMutation } from '../../graphql/posts' const driver = getDriver() const neode = getNeode() @@ -15,30 +16,6 @@ let user const categoryIds = ['cat9', 'cat4', 'cat15'] let variables -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 - title - content - slug - disabled - deleted - language - author { - name - } - postType - } - } -` - beforeAll(async () => { await cleanDatabase() @@ -282,7 +259,7 @@ describe('CreatePost', () => { describe('unauthenticated', () => { it('throws authorization error', async () => { - const { errors } = await mutate({ mutation: createPostMutation, variables }) + const { errors } = await mutate({ mutation: createPostMutation(), variables }) expect(errors[0]).toHaveProperty('message', 'Not Authorized!') }) }) @@ -297,7 +274,7 @@ describe('CreatePost', () => { data: { CreatePost: { title: 'I am a title', content: 'Some content' } }, errors: undefined, } - await expect(mutate({ mutation: createPostMutation, variables })).resolves.toMatchObject( + await expect(mutate({ mutation: createPostMutation(), variables })).resolves.toMatchObject( expected, ) }) @@ -314,23 +291,54 @@ describe('CreatePost', () => { }, errors: undefined, } - await expect(mutate({ mutation: createPostMutation, variables })).resolves.toMatchObject( + await expect(mutate({ mutation: createPostMutation(), variables })).resolves.toMatchObject( expected, ) }) it('`disabled` and `deleted` default to `false`', async () => { const expected = { data: { CreatePost: { disabled: false, deleted: false } } } - await expect(mutate({ mutation: createPostMutation, variables })).resolves.toMatchObject( + await expect(mutate({ mutation: createPostMutation(), variables })).resolves.toMatchObject( expected, ) }) it('has label "Article" as default', async () => { - await expect(mutate({ mutation: createPostMutation, variables })).resolves.toMatchObject({ + await expect(mutate({ mutation: createPostMutation(), variables })).resolves.toMatchObject({ data: { CreatePost: { postType: ['Article'] } }, }) }) + + describe('with post type "Event"', () => { + it('has label "Event" set', async () => { + await expect( + mutate({ + mutation: createPostMutation(), + variables: { ...variables, postType: 'Event' }, + }), + ).resolves.toMatchObject({ + data: { CreatePost: { postType: ['Event'] } }, + }) + }) + }) + + describe('with invalid post type', () => { + it('throws an error', async () => { + await expect( + mutate({ + mutation: createPostMutation(), + variables: { ...variables, postType: 'not-valid' }, + }), + ).resolves.toMatchObject({ + errors: [ + { + message: + 'Variable "$postType" got invalid value "not-valid"; Expected type PostType.', + }, + ], + }) + }) + }) }) })