Update backend tests

- Every test that created or updated a post needed to be updated to add categoryIds
This commit is contained in:
Matt Rider 2019-08-20 15:54:51 +02:00
parent c614e4de47
commit 29f39c4f45
12 changed files with 284 additions and 158 deletions

View File

@ -1,8 +1,10 @@
import { GraphQLClient } from 'graphql-request'
import { host, login } from '../../jest/helpers'
import Factory from '../../seed/factories'
import { neode } from '../../bootstrap/neo4j'
const factory = Factory()
const instance = neode()
const currentUserParams = {
id: 'u1',
@ -21,6 +23,7 @@ const randomAuthorParams = {
name: 'Someone else',
password: 'else',
}
const categoryIds = ['cat9']
beforeEach(async () => {
await Promise.all([
@ -28,14 +31,19 @@ beforeEach(async () => {
factory.create('User', followedAuthorParams),
factory.create('User', randomAuthorParams),
])
await instance.create('Category', {
id: 'cat9',
name: 'Democracy & Politics',
icon: 'university',
})
const [asYourself, asFollowedUser, asSomeoneElse] = await Promise.all([
Factory().authenticateAs(currentUserParams),
Factory().authenticateAs(followedAuthorParams),
Factory().authenticateAs(randomAuthorParams),
])
await asYourself.follow({ id: 'u2', type: 'User' })
await asFollowedUser.create('Post', { title: 'This is the post of a followed user' })
await asSomeoneElse.create('Post', { title: 'This is some random post' })
await asFollowedUser.create('Post', { title: 'This is the post of a followed user', categoryIds })
await asSomeoneElse.create('Post', { title: 'This is some random post', categoryIds })
})
afterEach(async () => {

View File

@ -4,14 +4,32 @@ import { createTestClient } from 'apollo-server-testing'
import { neode, getDriver } from '../../bootstrap/neo4j'
import createServer from '../../server'
const factory = Factory()
const driver = getDriver()
const instance = neode()
let server
let query
let mutate
let user
let authenticatedUser
const factory = Factory()
const driver = getDriver()
const instance = neode()
const categoryIds = ['cat9']
const createPostMutation = gql`
mutation($id: ID, $title: String!, $content: String!, $categoryIds: [ID]!) {
CreatePost(id: $id, title: $title, content: $content, categoryIds: $categoryIds) {
id
title
content
}
}
`
const updatePostMutation = gql`
mutation($id: ID!, $title: String!, $content: String!, $categoryIds: [ID]!) {
UpdatePost(id: $id, content: $content, title: $title, categoryIds: $categoryIds) {
title
content
}
}
`
beforeAll(() => {
const createServerResult = createServer({
@ -37,6 +55,11 @@ beforeEach(async () => {
email: 'test@example.org',
password: '1234',
})
await instance.create('Category', {
id: 'cat9',
name: 'Democracy & Politics',
icon: 'university',
})
})
afterEach(async () => {
@ -78,19 +101,10 @@ describe('notifications', () => {
'Hey <a class="mention" data-mention-id="you" href="/profile/you/al-capone">@al-capone</a> how do you do?'
const createPostAction = async () => {
const createPostMutation = gql`
mutation($id: ID, $title: String!, $content: String!) {
CreatePost(id: $id, title: $title, content: $content) {
id
title
content
}
}
`
authenticatedUser = await author.toJson()
await mutate({
mutation: createPostMutation,
variables: { id: 'p47', title, content },
variables: { id: 'p47', title, content, categoryIds },
})
authenticatedUser = await user.toJson()
}
@ -126,14 +140,6 @@ describe('notifications', () => {
@al-capone
</a>
`
const updatePostMutation = gql`
mutation($id: ID!, $title: String!, $content: String!) {
UpdatePost(id: $id, content: $content, title: $title) {
title
content
}
}
`
authenticatedUser = await author.toJson()
await mutate({
mutation: updatePostMutation,
@ -141,6 +147,7 @@ describe('notifications', () => {
id: 'p47',
title,
content: updatedContent,
categoryIds,
},
})
authenticatedUser = await user.toJson()
@ -189,9 +196,9 @@ describe('notifications', () => {
})
describe('Hashtags', () => {
const postId = 'p135'
const postTitle = 'Two Hashtags'
const postContent =
const id = 'p135'
const title = 'Two Hashtags'
const content =
'<p>Hey Dude, <a class="hashtag" href="/search/hashtag/Democracy">#Democracy</a> should work equal for everybody!? That seems to be the only way to have equal <a class="hashtag" href="/search/hashtag/Liberty">#Liberty</a> for everyone.</p>'
const postWithHastagsQuery = gql`
query($id: ID) {
@ -203,17 +210,8 @@ describe('Hashtags', () => {
}
`
const postWithHastagsVariables = {
id: postId,
id,
}
const createPostMutation = gql`
mutation($postId: ID, $postTitle: String!, $postContent: String!) {
CreatePost(id: $postId, title: $postTitle, content: $postContent) {
id
title
content
}
}
`
describe('authenticated', () => {
beforeEach(async () => {
@ -225,9 +223,10 @@ describe('Hashtags', () => {
await mutate({
mutation: createPostMutation,
variables: {
postId,
postTitle,
postContent,
id,
title,
content,
categoryIds,
},
})
})
@ -251,25 +250,17 @@ describe('Hashtags', () => {
describe('afterwards update the Post by removing a Hashtag, leaving a Hashtag and add a Hashtag', () => {
// The already existing Hashtag has no class at this point.
const updatedPostContent =
const content =
'<p>Hey Dude, <a class="hashtag" href="/search/hashtag/Elections">#Elections</a> should work equal for everybody!? That seems to be the only way to have equal <a href="/search/hashtag/Liberty">#Liberty</a> for everyone.</p>'
const updatePostMutation = gql`
mutation($postId: ID!, $postTitle: String!, $updatedPostContent: String!) {
UpdatePost(id: $postId, title: $postTitle, content: $updatedPostContent) {
id
title
content
}
}
`
it('only one previous Hashtag and the new Hashtag exists', async () => {
await mutate({
mutation: updatePostMutation,
variables: {
postId,
postTitle,
updatedPostContent,
id,
title,
content,
categoryIds,
},
})

View File

@ -1,13 +1,25 @@
import { GraphQLClient } from 'graphql-request'
import Factory from '../seed/factories'
import { host, login } from '../jest/helpers'
import { host, login, gql } from '../jest/helpers'
import { neode } from '../bootstrap/neo4j'
let authenticatedClient
let headers
const factory = Factory()
const instance = neode()
const categoryIds = ['cat9']
const createPostMutation = gql`
mutation($title: String!, $content: String!, $categoryIds: [ID]!, $slug: String) {
CreatePost(title: $title, content: $content, categoryIds: $categoryIds, slug: $slug) {
slug
}
}
`
let createPostVariables = {
title: 'I am a brand new post',
content: 'Some content',
categoryIds,
}
beforeEach(async () => {
const adminParams = { role: 'admin', email: 'admin@example.org', password: '1234' }
await factory.create('User', adminParams)
@ -15,6 +27,11 @@ beforeEach(async () => {
email: 'someone@example.org',
password: '1234',
})
await instance.create('Category', {
id: 'cat9',
name: 'Democracy & Politics',
icon: 'university',
})
// we need to be an admin, otherwise we're not authorized to create a user
headers = await login(adminParams)
authenticatedClient = new GraphQLClient(host, { headers })
@ -27,12 +44,7 @@ afterEach(async () => {
describe('slugify', () => {
describe('CreatePost', () => {
it('generates a slug based on title', async () => {
const response = await authenticatedClient.request(`mutation {
CreatePost(
title: "I am a brand new post",
content: "Some content"
) { slug }
}`)
const response = await authenticatedClient.request(createPostMutation, createPostVariables)
expect(response).toEqual({
CreatePost: { slug: 'i-am-a-brand-new-post' },
})
@ -47,16 +59,14 @@ describe('slugify', () => {
await asSomeoneElse.create('Post', {
title: 'Pre-existing post',
slug: 'pre-existing-post',
content: 'as Someone else content',
categoryIds,
})
})
it('chooses another slug', async () => {
const response = await authenticatedClient.request(`mutation {
CreatePost(
title: "Pre-existing post",
content: "Some content"
) { slug }
}`)
createPostVariables = { title: 'Pre-existing post', content: 'Some content', categoryIds }
const response = await authenticatedClient.request(createPostMutation, createPostVariables)
expect(response).toEqual({
CreatePost: { slug: 'pre-existing-post-1' },
})
@ -64,14 +74,14 @@ describe('slugify', () => {
describe('but if the client specifies a slug', () => {
it('rejects CreatePost', async () => {
createPostVariables = {
title: 'Pre-existing post',
content: 'Some content',
slug: 'pre-existing-post',
categoryIds,
}
await expect(
authenticatedClient.request(`mutation {
CreatePost(
title: "Pre-existing post",
content: "Some content",
slug: "pre-existing-post"
) { slug }
}`),
authenticatedClient.request(createPostMutation, createPostVariables),
).rejects.toThrow('already exists')
})
})

View File

@ -1,11 +1,15 @@
import { GraphQLClient } from 'graphql-request'
import Factory from '../seed/factories'
import { host, login } from '../jest/helpers'
import { neode } from '../bootstrap/neo4j'
const factory = Factory()
const instance = neode()
let client
let query
let action
const categoryIds = ['cat9']
beforeAll(async () => {
// For performance reasons we do this only once
@ -26,13 +30,23 @@ beforeAll(async () => {
email: 'troll@example.org',
password: '1234',
}),
instance.create('Category', {
id: 'cat9',
name: 'Democracy & Politics',
icon: 'university',
}),
])
await factory.authenticateAs({ email: 'user@example.org', password: '1234' })
await Promise.all([
factory.follow({ id: 'u2', type: 'User' }),
factory.create('Post', { id: 'p1', title: 'Deleted post', deleted: true }),
factory.create('Post', { id: 'p3', title: 'Publicly visible post', deleted: false }),
factory.create('Post', { id: 'p1', title: 'Deleted post', deleted: true, categoryIds }),
factory.create('Post', {
id: 'p3',
title: 'Publicly visible post',
deleted: false,
categoryIds,
}),
])
await Promise.all([
@ -53,6 +67,7 @@ beforeAll(async () => {
content: 'This is an offensive post content',
image: '/some/offensive/image.jpg',
deleted: false,
categoryIds,
})
await asTroll.create('Comment', { id: 'c1', postId: 'p3', content: 'Disabled comment' })
await Promise.all([asTroll.relate('Comment', 'Author', { from: 'u2', to: 'c1' })])

View File

@ -0,0 +1,21 @@
import uuid from 'uuid/v4'
module.exports = {
id: { type: 'string', primary: true, default: uuid },
name: { type: 'string', required: true, default: false },
slug: { type: 'string' },
icon: { type: 'string', required: true, default: false },
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
updatedAt: {
type: 'string',
isoDate: true,
required: true,
default: () => new Date().toISOString(),
},
post: {
type: 'relationship',
relationship: 'CATEGORIZED',
target: 'Post',
direction: 'in',
},
}

View File

@ -8,4 +8,5 @@ export default {
SocialMedia: require('./SocialMedia.js'),
Post: require('./Post.js'),
Notification: require('./Notification.js'),
Category: require('./Category.js'),
}

View File

@ -1,18 +1,21 @@
import { GraphQLClient } from 'graphql-request'
import Factory from '../../seed/factories'
import { host, login, gql } from '../../jest/helpers'
import { neode } from '../../bootstrap/neo4j'
const factory = Factory()
let client
let createCommentVariables
let createCommentVariablesSansPostId
let createCommentVariablesWithNonExistentPost
let userParams
let headers
const factory = Factory()
const instance = neode()
const categoryIds = ['cat9']
const createPostMutation = gql`
mutation($id: ID!, $title: String!, $content: String!) {
CreatePost(id: $id, title: $title, content: $content) {
mutation($id: ID, $title: String!, $content: String!, $categoryIds: [ID]!) {
CreatePost(id: $id, title: $title, content: $content, categoryIds: $categoryIds) {
id
}
}
@ -29,6 +32,7 @@ const createPostVariables = {
id: 'p1',
title: 'post to comment on',
content: 'please comment on me',
categoryIds,
}
beforeEach(async () => {
@ -38,6 +42,11 @@ beforeEach(async () => {
password: '1234',
}
await factory.create('User', userParams)
await instance.create('Category', {
id: 'cat9',
name: 'Democracy & Politics',
icon: 'university',
})
})
afterEach(async () => {
@ -199,6 +208,7 @@ describe('ManageComments', () => {
await asAuthor.create('Post', {
id: 'p1',
content: 'Post to be commented',
categoryIds,
})
await asAuthor.create('Comment', {
id: 'c456',

View File

@ -1,9 +1,12 @@
import { GraphQLClient } from 'graphql-request'
import Factory from '../../seed/factories'
import { host, login } from '../../jest/helpers'
import { host, login, gql } from '../../jest/helpers'
import { neode } from '../../bootstrap/neo4j'
const factory = Factory()
let client
const factory = Factory()
const instance = neode()
const categoryIds = ['cat9']
const setupAuthenticateClient = params => {
const authenticateClient = async () => {
@ -19,11 +22,16 @@ let authenticateClient
let createPostVariables
let createCommentVariables
beforeEach(() => {
beforeEach(async () => {
createResource = () => {}
authenticateClient = () => {
client = new GraphQLClient(host)
}
await instance.create('Category', {
id: 'cat9',
name: 'Democracy & Politics',
icon: 'university',
})
})
const setup = async () => {
@ -36,7 +44,7 @@ afterEach(async () => {
})
describe('disable', () => {
const mutation = `
const mutation = gql`
mutation($id: ID!) {
disable(id: $id)
}
@ -108,6 +116,7 @@ describe('disable', () => {
id: 'p3',
title: 'post to comment on',
content: 'please comment on me',
categoryIds,
}
createCommentVariables = {
id: 'c47',
@ -173,6 +182,7 @@ describe('disable', () => {
await factory.authenticateAs({ email: 'author@example.org', password: '1234' })
await factory.create('Post', {
id: 'p9', // that's the ID we will look for
categoryIds,
})
}
})
@ -214,7 +224,7 @@ describe('disable', () => {
})
describe('enable', () => {
const mutation = `
const mutation = gql`
mutation($id: ID!) {
enable(id: $id)
}
@ -286,6 +296,7 @@ describe('enable', () => {
id: 'p9',
title: 'post to comment on',
content: 'please comment on me',
categoryIds,
}
createCommentVariables = {
id: 'c456',
@ -305,7 +316,7 @@ describe('enable', () => {
await asAuthenticatedUser.create('Post', createPostVariables)
await asAuthenticatedUser.create('Comment', createCommentVariables)
const disableMutation = `
const disableMutation = gql`
mutation {
disable(id: "c456")
}
@ -362,9 +373,10 @@ describe('enable', () => {
await factory.authenticateAs({ email: 'author@example.org', password: '1234' })
await factory.create('Post', {
id: 'p9', // that's the ID we will look for
categoryIds,
})
const disableMutation = `
const disableMutation = gql`
mutation {
disable(id: "p9")
}

View File

@ -1,17 +1,25 @@
import { GraphQLClient } from 'graphql-request'
import Factory from '../../seed/factories'
import { host, login } from '../../jest/helpers'
import { host, login, gql } from '../../jest/helpers'
import { neode } from '../../bootstrap/neo4j'
const factory = Factory()
let client
const factory = Factory()
const instance = neode()
const userParams = {
id: 'you',
email: 'test@example.org',
password: '1234',
}
const categoryIds = ['cat9']
beforeEach(async () => {
await factory.create('User', userParams)
await instance.create('Category', {
id: 'cat9',
name: 'Democracy & Politics',
icon: 'university',
})
})
afterEach(async () => {
@ -19,11 +27,13 @@ afterEach(async () => {
})
describe('Notification', () => {
const query = `{
Notification {
id
const query = gql`
query {
Notification {
id
}
}
}`
`
describe('unauthenticated', () => {
it('throws authorization error', async () => {
@ -57,28 +67,30 @@ describe('currentUser { notifications }', () => {
])
await factory.create('Notification', { id: 'unseen' })
await factory.authenticateAs(neighborParams)
await factory.create('Post', { id: 'p1' })
await factory.create('Post', { id: 'p1', categoryIds })
await Promise.all([
factory.relate('Notification', 'User', { from: 'not-for-you', to: 'neighbor' }),
factory.relate('Notification', 'Post', { from: 'p1', to: 'not-for-you' }),
factory.relate('Notification', 'Post', { from: 'p1', to: 'not-for-you', categoryIds }),
factory.relate('Notification', 'User', { from: 'unseen', to: 'you' }),
factory.relate('Notification', 'Post', { from: 'p1', to: 'unseen' }),
factory.relate('Notification', 'Post', { from: 'p1', to: 'unseen', categoryIds }),
factory.relate('Notification', 'User', { from: 'already-seen', to: 'you' }),
factory.relate('Notification', 'Post', { from: 'p1', to: 'already-seen' }),
factory.relate('Notification', 'Post', { from: 'p1', to: 'already-seen', categoryIds }),
])
})
describe('filter for read: false', () => {
const query = `query($read: Boolean) {
currentUser {
notifications(read: $read, orderBy: createdAt_desc) {
id
post {
const query = gql`
query($read: Boolean) {
currentUser {
notifications(read: $read, orderBy: createdAt_desc) {
id
post {
id
}
}
}
}
}`
`
const variables = { read: false }
it('returns only unread notifications of current user', async () => {
const expected = {
@ -91,16 +103,18 @@ describe('currentUser { notifications }', () => {
})
describe('no filters', () => {
const query = `{
currentUser {
notifications(orderBy: createdAt_desc) {
id
post {
const query = gql`
query {
currentUser {
notifications(orderBy: createdAt_desc) {
id
post {
id
}
}
}
}
}`
`
it('returns all notifications of current user', async () => {
const expected = {
currentUser: {
@ -118,11 +132,14 @@ describe('currentUser { notifications }', () => {
})
describe('UpdateNotification', () => {
const mutation = `mutation($id: ID!, $read: Boolean){
UpdateNotification(id: $id, read: $read) {
id read
const mutation = gql`
mutation($id: ID!, $read: Boolean) {
UpdateNotification(id: $id, read: $read) {
id
read
}
}
}`
`
const variables = { id: 'to-be-updated', read: true }
describe('given a notifications', () => {
@ -138,7 +155,7 @@ describe('UpdateNotification', () => {
await factory.create('User', mentionedParams)
await factory.create('Notification', { id: 'to-be-updated' })
await factory.authenticateAs(userParams)
await factory.create('Post', { id: 'p1' })
await factory.create('Post', { id: 'p1', categoryIds })
await Promise.all([
factory.relate('Notification', 'User', { from: 'to-be-updated', to: 'mentioned-1' }),
factory.relate('Notification', 'Post', { from: 'p1', to: 'to-be-updated' }),

View File

@ -1,8 +1,10 @@
import { GraphQLClient } from 'graphql-request'
import Factory from '../../seed/factories'
import { host, login } from '../../jest/helpers'
import { neode } from '../../bootstrap/neo4j'
const factory = Factory()
const instance = neode()
describe('report', () => {
let mutation
@ -10,6 +12,7 @@ describe('report', () => {
let returnedObject
let variables
let createPostVariables
const categoryIds = ['cat9']
beforeEach(async () => {
returnedObject = '{ description }'
@ -28,6 +31,11 @@ describe('report', () => {
role: 'user',
email: 'abusive-user@example.org',
})
await instance.create('Category', {
id: 'cat9',
name: 'Democracy & Politics',
icon: 'university',
})
})
afterEach(async () => {
@ -126,6 +134,7 @@ describe('report', () => {
await factory.create('Post', {
id: 'p23',
title: 'Matt and Robert having a pair-programming',
categoryIds,
})
variables = {
id: 'p23',
@ -171,6 +180,7 @@ describe('report', () => {
id: 'p1',
title: 'post to comment on',
content: 'please comment on me',
categoryIds,
}
const asAuthenticatedUser = await factory.authenticateAs({
email: 'test@example.org',

View File

@ -1,22 +1,39 @@
import { GraphQLClient } from 'graphql-request'
import Factory from '../../seed/factories'
import { host, login } from '../../jest/helpers'
import { host, login, gql } from '../../jest/helpers'
import { neode } from '../../bootstrap/neo4j'
const factory = Factory()
let clientUser1, clientUser2
let headersUser1, headersUser2
const factory = Factory()
const instance = neode()
const categoryIds = ['cat9']
const mutationShoutPost = id => `
mutation {
shout(id: "${id}", type: Post)
const mutationShoutPost = gql`
mutation($id: ID!) {
shout(id: $id, type: Post)
}
`
const mutationUnshoutPost = id => `
mutation {
unshout(id: "${id}", type: Post)
const mutationUnshoutPost = gql`
mutation($id: ID!) {
unshout(id: $id, type: Post)
}
`
const createPostMutation = gql`
mutation($id: ID, $title: String!, $content: String!, $categoryIds: [ID]!) {
CreatePost(id: $id, title: $title, content: $content, categoryIds: $categoryIds) {
id
title
content
}
}
`
const createPostVariables = {
id: 'p1234',
title: 'Post Title 1234',
content: 'Some Post Content 1234',
categoryIds,
}
beforeEach(async () => {
await factory.create('User', {
id: 'u1',
@ -28,28 +45,23 @@ beforeEach(async () => {
email: 'test2@example.org',
password: '1234',
})
await instance.create('Category', {
id: 'cat9',
name: 'Democracy & Politics',
icon: 'university',
})
headersUser1 = await login({ email: 'test@example.org', password: '1234' })
headersUser2 = await login({ email: 'test2@example.org', password: '1234' })
clientUser1 = new GraphQLClient(host, { headers: headersUser1 })
clientUser2 = new GraphQLClient(host, { headers: headersUser2 })
await clientUser1.request(`
mutation {
CreatePost(id: "p1", title: "Post Title 1", content: "Some Post Content 1") {
id
title
}
}
`)
await clientUser2.request(`
mutation {
CreatePost(id: "p2", title: "Post Title 2", content: "Some Post Content 2") {
id
title
}
}
`)
await clientUser1.request(createPostMutation, createPostVariables)
await clientUser2.request(createPostMutation, {
id: 'p12345',
title: 'Post Title 12345',
content: 'Some Post Content 12345',
categoryIds,
})
})
afterEach(async () => {
@ -61,22 +73,26 @@ describe('shout', () => {
describe('unauthenticated shout', () => {
it('throws authorization error', async () => {
const client = new GraphQLClient(host)
await expect(client.request(mutationShoutPost('p1'))).rejects.toThrow('Not Authorised')
await expect(client.request(mutationShoutPost, { id: 'p1234' })).rejects.toThrow(
'Not Authorised',
)
})
})
it('I shout a post of another user', async () => {
const res = await clientUser1.request(mutationShoutPost('p2'))
const res = await clientUser1.request(mutationShoutPost, { id: 'p12345' })
const expected = {
shout: true,
}
expect(res).toMatchObject(expected)
const { Post } = await clientUser1.request(`{
Post(id: "p2") {
shoutedByCurrentUser
const { Post } = await clientUser1.request(gql`
query {
Post(id: "p12345") {
shoutedByCurrentUser
}
}
}`)
`)
const expected2 = {
shoutedByCurrentUser: true,
}
@ -84,17 +100,19 @@ describe('shout', () => {
})
it('I can`t shout my own post', async () => {
const res = await clientUser1.request(mutationShoutPost('p1'))
const res = await clientUser1.request(mutationShoutPost, { id: 'p1234' })
const expected = {
shout: false,
}
expect(res).toMatchObject(expected)
const { Post } = await clientUser1.request(`{
Post(id: "p1") {
shoutedByCurrentUser
const { Post } = await clientUser1.request(gql`
query {
Post(id: "p1234") {
shoutedByCurrentUser
}
}
}`)
`)
const expected2 = {
shoutedByCurrentUser: false,
}
@ -106,28 +124,32 @@ describe('shout', () => {
describe('unauthenticated shout', () => {
it('throws authorization error', async () => {
// shout
await clientUser1.request(mutationShoutPost('p2'))
await clientUser1.request(mutationShoutPost, { id: 'p12345' })
// unshout
const client = new GraphQLClient(host)
await expect(client.request(mutationUnshoutPost('p2'))).rejects.toThrow('Not Authorised')
await expect(client.request(mutationUnshoutPost, { id: 'p12345' })).rejects.toThrow(
'Not Authorised',
)
})
})
it('I unshout a post of another user', async () => {
// shout
await clientUser1.request(mutationShoutPost('p2'))
await clientUser1.request(mutationShoutPost, { id: 'p12345' })
const expected = {
unshout: true,
}
// unshout
const res = await clientUser1.request(mutationUnshoutPost('p2'))
const res = await clientUser1.request(mutationUnshoutPost, { id: 'p12345' })
expect(res).toMatchObject(expected)
const { Post } = await clientUser1.request(`{
Post(id: "p2") {
shoutedByCurrentUser
const { Post } = await clientUser1.request(gql`
query {
Post(id: "p12345") {
shoutedByCurrentUser
}
}
}`)
`)
const expected2 = {
shoutedByCurrentUser: false,
}

View File

@ -1,9 +1,12 @@
import { GraphQLClient } from 'graphql-request'
import Factory from '../../seed/factories'
import { host, login, gql } from '../../jest/helpers'
import { neode } from '../../bootstrap/neo4j'
const factory = Factory()
let client
const factory = Factory()
const instance = neode()
const categoryIds = ['cat9']
afterEach(async () => {
await factory.cleanDatabase()
@ -195,9 +198,15 @@ describe('users', () => {
email: 'test@example.org',
password: '1234',
})
await instance.create('Category', {
id: 'cat9',
name: 'Democracy & Politics',
icon: 'university',
})
await asAuthor.create('Post', {
id: 'p139',
content: 'Post by user u343',
categoryIds,
})
await asAuthor.create('Comment', {
id: 'c155',