mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Update backend tests
- Every test that created or updated a post needed to be updated to add categoryIds
This commit is contained in:
parent
c614e4de47
commit
29f39c4f45
@ -1,8 +1,10 @@
|
|||||||
import { GraphQLClient } from 'graphql-request'
|
import { GraphQLClient } from 'graphql-request'
|
||||||
import { host, login } from '../../jest/helpers'
|
import { host, login } from '../../jest/helpers'
|
||||||
import Factory from '../../seed/factories'
|
import Factory from '../../seed/factories'
|
||||||
|
import { neode } from '../../bootstrap/neo4j'
|
||||||
|
|
||||||
const factory = Factory()
|
const factory = Factory()
|
||||||
|
const instance = neode()
|
||||||
|
|
||||||
const currentUserParams = {
|
const currentUserParams = {
|
||||||
id: 'u1',
|
id: 'u1',
|
||||||
@ -21,6 +23,7 @@ const randomAuthorParams = {
|
|||||||
name: 'Someone else',
|
name: 'Someone else',
|
||||||
password: 'else',
|
password: 'else',
|
||||||
}
|
}
|
||||||
|
const categoryIds = ['cat9']
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
@ -28,14 +31,19 @@ beforeEach(async () => {
|
|||||||
factory.create('User', followedAuthorParams),
|
factory.create('User', followedAuthorParams),
|
||||||
factory.create('User', randomAuthorParams),
|
factory.create('User', randomAuthorParams),
|
||||||
])
|
])
|
||||||
|
await instance.create('Category', {
|
||||||
|
id: 'cat9',
|
||||||
|
name: 'Democracy & Politics',
|
||||||
|
icon: 'university',
|
||||||
|
})
|
||||||
const [asYourself, asFollowedUser, asSomeoneElse] = await Promise.all([
|
const [asYourself, asFollowedUser, asSomeoneElse] = await Promise.all([
|
||||||
Factory().authenticateAs(currentUserParams),
|
Factory().authenticateAs(currentUserParams),
|
||||||
Factory().authenticateAs(followedAuthorParams),
|
Factory().authenticateAs(followedAuthorParams),
|
||||||
Factory().authenticateAs(randomAuthorParams),
|
Factory().authenticateAs(randomAuthorParams),
|
||||||
])
|
])
|
||||||
await asYourself.follow({ id: 'u2', type: 'User' })
|
await asYourself.follow({ id: 'u2', type: 'User' })
|
||||||
await asFollowedUser.create('Post', { title: 'This is the post of a followed user' })
|
await asFollowedUser.create('Post', { title: 'This is the post of a followed user', categoryIds })
|
||||||
await asSomeoneElse.create('Post', { title: 'This is some random post' })
|
await asSomeoneElse.create('Post', { title: 'This is some random post', categoryIds })
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
|||||||
@ -4,14 +4,32 @@ import { createTestClient } from 'apollo-server-testing'
|
|||||||
import { neode, getDriver } from '../../bootstrap/neo4j'
|
import { neode, getDriver } from '../../bootstrap/neo4j'
|
||||||
import createServer from '../../server'
|
import createServer from '../../server'
|
||||||
|
|
||||||
const factory = Factory()
|
|
||||||
const driver = getDriver()
|
|
||||||
const instance = neode()
|
|
||||||
let server
|
let server
|
||||||
let query
|
let query
|
||||||
let mutate
|
let mutate
|
||||||
let user
|
let user
|
||||||
let authenticatedUser
|
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(() => {
|
beforeAll(() => {
|
||||||
const createServerResult = createServer({
|
const createServerResult = createServer({
|
||||||
@ -37,6 +55,11 @@ beforeEach(async () => {
|
|||||||
email: 'test@example.org',
|
email: 'test@example.org',
|
||||||
password: '1234',
|
password: '1234',
|
||||||
})
|
})
|
||||||
|
await instance.create('Category', {
|
||||||
|
id: 'cat9',
|
||||||
|
name: 'Democracy & Politics',
|
||||||
|
icon: 'university',
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
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?'
|
'Hey <a class="mention" data-mention-id="you" href="/profile/you/al-capone">@al-capone</a> how do you do?'
|
||||||
|
|
||||||
const createPostAction = async () => {
|
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()
|
authenticatedUser = await author.toJson()
|
||||||
await mutate({
|
await mutate({
|
||||||
mutation: createPostMutation,
|
mutation: createPostMutation,
|
||||||
variables: { id: 'p47', title, content },
|
variables: { id: 'p47', title, content, categoryIds },
|
||||||
})
|
})
|
||||||
authenticatedUser = await user.toJson()
|
authenticatedUser = await user.toJson()
|
||||||
}
|
}
|
||||||
@ -126,14 +140,6 @@ describe('notifications', () => {
|
|||||||
@al-capone
|
@al-capone
|
||||||
</a>
|
</a>
|
||||||
`
|
`
|
||||||
const updatePostMutation = gql`
|
|
||||||
mutation($id: ID!, $title: String!, $content: String!) {
|
|
||||||
UpdatePost(id: $id, content: $content, title: $title) {
|
|
||||||
title
|
|
||||||
content
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`
|
|
||||||
authenticatedUser = await author.toJson()
|
authenticatedUser = await author.toJson()
|
||||||
await mutate({
|
await mutate({
|
||||||
mutation: updatePostMutation,
|
mutation: updatePostMutation,
|
||||||
@ -141,6 +147,7 @@ describe('notifications', () => {
|
|||||||
id: 'p47',
|
id: 'p47',
|
||||||
title,
|
title,
|
||||||
content: updatedContent,
|
content: updatedContent,
|
||||||
|
categoryIds,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
authenticatedUser = await user.toJson()
|
authenticatedUser = await user.toJson()
|
||||||
@ -189,9 +196,9 @@ describe('notifications', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('Hashtags', () => {
|
describe('Hashtags', () => {
|
||||||
const postId = 'p135'
|
const id = 'p135'
|
||||||
const postTitle = 'Two Hashtags'
|
const title = 'Two Hashtags'
|
||||||
const postContent =
|
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>'
|
'<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`
|
const postWithHastagsQuery = gql`
|
||||||
query($id: ID) {
|
query($id: ID) {
|
||||||
@ -203,17 +210,8 @@ describe('Hashtags', () => {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
const postWithHastagsVariables = {
|
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', () => {
|
describe('authenticated', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@ -225,9 +223,10 @@ describe('Hashtags', () => {
|
|||||||
await mutate({
|
await mutate({
|
||||||
mutation: createPostMutation,
|
mutation: createPostMutation,
|
||||||
variables: {
|
variables: {
|
||||||
postId,
|
id,
|
||||||
postTitle,
|
title,
|
||||||
postContent,
|
content,
|
||||||
|
categoryIds,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -251,25 +250,17 @@ describe('Hashtags', () => {
|
|||||||
|
|
||||||
describe('afterwards update the Post by removing a Hashtag, leaving a Hashtag and add a Hashtag', () => {
|
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.
|
// 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>'
|
'<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 () => {
|
it('only one previous Hashtag and the new Hashtag exists', async () => {
|
||||||
await mutate({
|
await mutate({
|
||||||
mutation: updatePostMutation,
|
mutation: updatePostMutation,
|
||||||
variables: {
|
variables: {
|
||||||
postId,
|
id,
|
||||||
postTitle,
|
title,
|
||||||
updatedPostContent,
|
content,
|
||||||
|
categoryIds,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,25 @@
|
|||||||
import { GraphQLClient } from 'graphql-request'
|
import { GraphQLClient } from 'graphql-request'
|
||||||
import Factory from '../seed/factories'
|
import Factory from '../seed/factories'
|
||||||
import { host, login } from '../jest/helpers'
|
import { host, login, gql } from '../jest/helpers'
|
||||||
import { neode } from '../bootstrap/neo4j'
|
import { neode } from '../bootstrap/neo4j'
|
||||||
|
|
||||||
let authenticatedClient
|
let authenticatedClient
|
||||||
let headers
|
let headers
|
||||||
const factory = Factory()
|
const factory = Factory()
|
||||||
const instance = neode()
|
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 () => {
|
beforeEach(async () => {
|
||||||
const adminParams = { role: 'admin', email: 'admin@example.org', password: '1234' }
|
const adminParams = { role: 'admin', email: 'admin@example.org', password: '1234' }
|
||||||
await factory.create('User', adminParams)
|
await factory.create('User', adminParams)
|
||||||
@ -15,6 +27,11 @@ beforeEach(async () => {
|
|||||||
email: 'someone@example.org',
|
email: 'someone@example.org',
|
||||||
password: '1234',
|
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
|
// we need to be an admin, otherwise we're not authorized to create a user
|
||||||
headers = await login(adminParams)
|
headers = await login(adminParams)
|
||||||
authenticatedClient = new GraphQLClient(host, { headers })
|
authenticatedClient = new GraphQLClient(host, { headers })
|
||||||
@ -27,12 +44,7 @@ afterEach(async () => {
|
|||||||
describe('slugify', () => {
|
describe('slugify', () => {
|
||||||
describe('CreatePost', () => {
|
describe('CreatePost', () => {
|
||||||
it('generates a slug based on title', async () => {
|
it('generates a slug based on title', async () => {
|
||||||
const response = await authenticatedClient.request(`mutation {
|
const response = await authenticatedClient.request(createPostMutation, createPostVariables)
|
||||||
CreatePost(
|
|
||||||
title: "I am a brand new post",
|
|
||||||
content: "Some content"
|
|
||||||
) { slug }
|
|
||||||
}`)
|
|
||||||
expect(response).toEqual({
|
expect(response).toEqual({
|
||||||
CreatePost: { slug: 'i-am-a-brand-new-post' },
|
CreatePost: { slug: 'i-am-a-brand-new-post' },
|
||||||
})
|
})
|
||||||
@ -47,16 +59,14 @@ describe('slugify', () => {
|
|||||||
await asSomeoneElse.create('Post', {
|
await asSomeoneElse.create('Post', {
|
||||||
title: 'Pre-existing post',
|
title: 'Pre-existing post',
|
||||||
slug: 'pre-existing-post',
|
slug: 'pre-existing-post',
|
||||||
|
content: 'as Someone else content',
|
||||||
|
categoryIds,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('chooses another slug', async () => {
|
it('chooses another slug', async () => {
|
||||||
const response = await authenticatedClient.request(`mutation {
|
createPostVariables = { title: 'Pre-existing post', content: 'Some content', categoryIds }
|
||||||
CreatePost(
|
const response = await authenticatedClient.request(createPostMutation, createPostVariables)
|
||||||
title: "Pre-existing post",
|
|
||||||
content: "Some content"
|
|
||||||
) { slug }
|
|
||||||
}`)
|
|
||||||
expect(response).toEqual({
|
expect(response).toEqual({
|
||||||
CreatePost: { slug: 'pre-existing-post-1' },
|
CreatePost: { slug: 'pre-existing-post-1' },
|
||||||
})
|
})
|
||||||
@ -64,14 +74,14 @@ describe('slugify', () => {
|
|||||||
|
|
||||||
describe('but if the client specifies a slug', () => {
|
describe('but if the client specifies a slug', () => {
|
||||||
it('rejects CreatePost', async () => {
|
it('rejects CreatePost', async () => {
|
||||||
|
createPostVariables = {
|
||||||
|
title: 'Pre-existing post',
|
||||||
|
content: 'Some content',
|
||||||
|
slug: 'pre-existing-post',
|
||||||
|
categoryIds,
|
||||||
|
}
|
||||||
await expect(
|
await expect(
|
||||||
authenticatedClient.request(`mutation {
|
authenticatedClient.request(createPostMutation, createPostVariables),
|
||||||
CreatePost(
|
|
||||||
title: "Pre-existing post",
|
|
||||||
content: "Some content",
|
|
||||||
slug: "pre-existing-post"
|
|
||||||
) { slug }
|
|
||||||
}`),
|
|
||||||
).rejects.toThrow('already exists')
|
).rejects.toThrow('already exists')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,11 +1,15 @@
|
|||||||
import { GraphQLClient } from 'graphql-request'
|
import { GraphQLClient } from 'graphql-request'
|
||||||
import Factory from '../seed/factories'
|
import Factory from '../seed/factories'
|
||||||
import { host, login } from '../jest/helpers'
|
import { host, login } from '../jest/helpers'
|
||||||
|
import { neode } from '../bootstrap/neo4j'
|
||||||
|
|
||||||
const factory = Factory()
|
const factory = Factory()
|
||||||
|
const instance = neode()
|
||||||
|
|
||||||
let client
|
let client
|
||||||
let query
|
let query
|
||||||
let action
|
let action
|
||||||
|
const categoryIds = ['cat9']
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// For performance reasons we do this only once
|
// For performance reasons we do this only once
|
||||||
@ -26,13 +30,23 @@ beforeAll(async () => {
|
|||||||
email: 'troll@example.org',
|
email: 'troll@example.org',
|
||||||
password: '1234',
|
password: '1234',
|
||||||
}),
|
}),
|
||||||
|
instance.create('Category', {
|
||||||
|
id: 'cat9',
|
||||||
|
name: 'Democracy & Politics',
|
||||||
|
icon: 'university',
|
||||||
|
}),
|
||||||
])
|
])
|
||||||
|
|
||||||
await factory.authenticateAs({ email: 'user@example.org', password: '1234' })
|
await factory.authenticateAs({ email: 'user@example.org', password: '1234' })
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
factory.follow({ id: 'u2', type: 'User' }),
|
factory.follow({ id: 'u2', type: 'User' }),
|
||||||
factory.create('Post', { id: 'p1', title: 'Deleted post', deleted: true }),
|
factory.create('Post', { id: 'p1', title: 'Deleted post', deleted: true, categoryIds }),
|
||||||
factory.create('Post', { id: 'p3', title: 'Publicly visible post', deleted: false }),
|
factory.create('Post', {
|
||||||
|
id: 'p3',
|
||||||
|
title: 'Publicly visible post',
|
||||||
|
deleted: false,
|
||||||
|
categoryIds,
|
||||||
|
}),
|
||||||
])
|
])
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
@ -53,6 +67,7 @@ beforeAll(async () => {
|
|||||||
content: 'This is an offensive post content',
|
content: 'This is an offensive post content',
|
||||||
image: '/some/offensive/image.jpg',
|
image: '/some/offensive/image.jpg',
|
||||||
deleted: false,
|
deleted: false,
|
||||||
|
categoryIds,
|
||||||
})
|
})
|
||||||
await asTroll.create('Comment', { id: 'c1', postId: 'p3', content: 'Disabled comment' })
|
await asTroll.create('Comment', { id: 'c1', postId: 'p3', content: 'Disabled comment' })
|
||||||
await Promise.all([asTroll.relate('Comment', 'Author', { from: 'u2', to: 'c1' })])
|
await Promise.all([asTroll.relate('Comment', 'Author', { from: 'u2', to: 'c1' })])
|
||||||
|
|||||||
21
backend/src/models/Category.js
Normal file
21
backend/src/models/Category.js
Normal 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',
|
||||||
|
},
|
||||||
|
}
|
||||||
@ -8,4 +8,5 @@ export default {
|
|||||||
SocialMedia: require('./SocialMedia.js'),
|
SocialMedia: require('./SocialMedia.js'),
|
||||||
Post: require('./Post.js'),
|
Post: require('./Post.js'),
|
||||||
Notification: require('./Notification.js'),
|
Notification: require('./Notification.js'),
|
||||||
|
Category: require('./Category.js'),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,18 +1,21 @@
|
|||||||
import { GraphQLClient } from 'graphql-request'
|
import { GraphQLClient } from 'graphql-request'
|
||||||
import Factory from '../../seed/factories'
|
import Factory from '../../seed/factories'
|
||||||
import { host, login, gql } from '../../jest/helpers'
|
import { host, login, gql } from '../../jest/helpers'
|
||||||
|
import { neode } from '../../bootstrap/neo4j'
|
||||||
|
|
||||||
const factory = Factory()
|
|
||||||
let client
|
let client
|
||||||
let createCommentVariables
|
let createCommentVariables
|
||||||
let createCommentVariablesSansPostId
|
let createCommentVariablesSansPostId
|
||||||
let createCommentVariablesWithNonExistentPost
|
let createCommentVariablesWithNonExistentPost
|
||||||
let userParams
|
let userParams
|
||||||
let headers
|
let headers
|
||||||
|
const factory = Factory()
|
||||||
|
const instance = neode()
|
||||||
|
const categoryIds = ['cat9']
|
||||||
|
|
||||||
const createPostMutation = gql`
|
const createPostMutation = gql`
|
||||||
mutation($id: ID!, $title: String!, $content: String!) {
|
mutation($id: ID, $title: String!, $content: String!, $categoryIds: [ID]!) {
|
||||||
CreatePost(id: $id, title: $title, content: $content) {
|
CreatePost(id: $id, title: $title, content: $content, categoryIds: $categoryIds) {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -29,6 +32,7 @@ const createPostVariables = {
|
|||||||
id: 'p1',
|
id: 'p1',
|
||||||
title: 'post to comment on',
|
title: 'post to comment on',
|
||||||
content: 'please comment on me',
|
content: 'please comment on me',
|
||||||
|
categoryIds,
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@ -38,6 +42,11 @@ beforeEach(async () => {
|
|||||||
password: '1234',
|
password: '1234',
|
||||||
}
|
}
|
||||||
await factory.create('User', userParams)
|
await factory.create('User', userParams)
|
||||||
|
await instance.create('Category', {
|
||||||
|
id: 'cat9',
|
||||||
|
name: 'Democracy & Politics',
|
||||||
|
icon: 'university',
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
@ -199,6 +208,7 @@ describe('ManageComments', () => {
|
|||||||
await asAuthor.create('Post', {
|
await asAuthor.create('Post', {
|
||||||
id: 'p1',
|
id: 'p1',
|
||||||
content: 'Post to be commented',
|
content: 'Post to be commented',
|
||||||
|
categoryIds,
|
||||||
})
|
})
|
||||||
await asAuthor.create('Comment', {
|
await asAuthor.create('Comment', {
|
||||||
id: 'c456',
|
id: 'c456',
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
import { GraphQLClient } from 'graphql-request'
|
import { GraphQLClient } from 'graphql-request'
|
||||||
import Factory from '../../seed/factories'
|
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
|
let client
|
||||||
|
const factory = Factory()
|
||||||
|
const instance = neode()
|
||||||
|
const categoryIds = ['cat9']
|
||||||
|
|
||||||
const setupAuthenticateClient = params => {
|
const setupAuthenticateClient = params => {
|
||||||
const authenticateClient = async () => {
|
const authenticateClient = async () => {
|
||||||
@ -19,11 +22,16 @@ let authenticateClient
|
|||||||
let createPostVariables
|
let createPostVariables
|
||||||
let createCommentVariables
|
let createCommentVariables
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
createResource = () => {}
|
createResource = () => {}
|
||||||
authenticateClient = () => {
|
authenticateClient = () => {
|
||||||
client = new GraphQLClient(host)
|
client = new GraphQLClient(host)
|
||||||
}
|
}
|
||||||
|
await instance.create('Category', {
|
||||||
|
id: 'cat9',
|
||||||
|
name: 'Democracy & Politics',
|
||||||
|
icon: 'university',
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const setup = async () => {
|
const setup = async () => {
|
||||||
@ -36,7 +44,7 @@ afterEach(async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('disable', () => {
|
describe('disable', () => {
|
||||||
const mutation = `
|
const mutation = gql`
|
||||||
mutation($id: ID!) {
|
mutation($id: ID!) {
|
||||||
disable(id: $id)
|
disable(id: $id)
|
||||||
}
|
}
|
||||||
@ -108,6 +116,7 @@ describe('disable', () => {
|
|||||||
id: 'p3',
|
id: 'p3',
|
||||||
title: 'post to comment on',
|
title: 'post to comment on',
|
||||||
content: 'please comment on me',
|
content: 'please comment on me',
|
||||||
|
categoryIds,
|
||||||
}
|
}
|
||||||
createCommentVariables = {
|
createCommentVariables = {
|
||||||
id: 'c47',
|
id: 'c47',
|
||||||
@ -173,6 +182,7 @@ describe('disable', () => {
|
|||||||
await factory.authenticateAs({ email: 'author@example.org', password: '1234' })
|
await factory.authenticateAs({ email: 'author@example.org', password: '1234' })
|
||||||
await factory.create('Post', {
|
await factory.create('Post', {
|
||||||
id: 'p9', // that's the ID we will look for
|
id: 'p9', // that's the ID we will look for
|
||||||
|
categoryIds,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -214,7 +224,7 @@ describe('disable', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('enable', () => {
|
describe('enable', () => {
|
||||||
const mutation = `
|
const mutation = gql`
|
||||||
mutation($id: ID!) {
|
mutation($id: ID!) {
|
||||||
enable(id: $id)
|
enable(id: $id)
|
||||||
}
|
}
|
||||||
@ -286,6 +296,7 @@ describe('enable', () => {
|
|||||||
id: 'p9',
|
id: 'p9',
|
||||||
title: 'post to comment on',
|
title: 'post to comment on',
|
||||||
content: 'please comment on me',
|
content: 'please comment on me',
|
||||||
|
categoryIds,
|
||||||
}
|
}
|
||||||
createCommentVariables = {
|
createCommentVariables = {
|
||||||
id: 'c456',
|
id: 'c456',
|
||||||
@ -305,7 +316,7 @@ describe('enable', () => {
|
|||||||
await asAuthenticatedUser.create('Post', createPostVariables)
|
await asAuthenticatedUser.create('Post', createPostVariables)
|
||||||
await asAuthenticatedUser.create('Comment', createCommentVariables)
|
await asAuthenticatedUser.create('Comment', createCommentVariables)
|
||||||
|
|
||||||
const disableMutation = `
|
const disableMutation = gql`
|
||||||
mutation {
|
mutation {
|
||||||
disable(id: "c456")
|
disable(id: "c456")
|
||||||
}
|
}
|
||||||
@ -362,9 +373,10 @@ describe('enable', () => {
|
|||||||
await factory.authenticateAs({ email: 'author@example.org', password: '1234' })
|
await factory.authenticateAs({ email: 'author@example.org', password: '1234' })
|
||||||
await factory.create('Post', {
|
await factory.create('Post', {
|
||||||
id: 'p9', // that's the ID we will look for
|
id: 'p9', // that's the ID we will look for
|
||||||
|
categoryIds,
|
||||||
})
|
})
|
||||||
|
|
||||||
const disableMutation = `
|
const disableMutation = gql`
|
||||||
mutation {
|
mutation {
|
||||||
disable(id: "p9")
|
disable(id: "p9")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,25 @@
|
|||||||
import { GraphQLClient } from 'graphql-request'
|
import { GraphQLClient } from 'graphql-request'
|
||||||
import Factory from '../../seed/factories'
|
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
|
let client
|
||||||
|
const factory = Factory()
|
||||||
|
const instance = neode()
|
||||||
const userParams = {
|
const userParams = {
|
||||||
id: 'you',
|
id: 'you',
|
||||||
email: 'test@example.org',
|
email: 'test@example.org',
|
||||||
password: '1234',
|
password: '1234',
|
||||||
}
|
}
|
||||||
|
const categoryIds = ['cat9']
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await factory.create('User', userParams)
|
await factory.create('User', userParams)
|
||||||
|
await instance.create('Category', {
|
||||||
|
id: 'cat9',
|
||||||
|
name: 'Democracy & Politics',
|
||||||
|
icon: 'university',
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
@ -19,11 +27,13 @@ afterEach(async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('Notification', () => {
|
describe('Notification', () => {
|
||||||
const query = `{
|
const query = gql`
|
||||||
Notification {
|
query {
|
||||||
id
|
Notification {
|
||||||
|
id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}`
|
`
|
||||||
|
|
||||||
describe('unauthenticated', () => {
|
describe('unauthenticated', () => {
|
||||||
it('throws authorization error', async () => {
|
it('throws authorization error', async () => {
|
||||||
@ -57,28 +67,30 @@ describe('currentUser { notifications }', () => {
|
|||||||
])
|
])
|
||||||
await factory.create('Notification', { id: 'unseen' })
|
await factory.create('Notification', { id: 'unseen' })
|
||||||
await factory.authenticateAs(neighborParams)
|
await factory.authenticateAs(neighborParams)
|
||||||
await factory.create('Post', { id: 'p1' })
|
await factory.create('Post', { id: 'p1', categoryIds })
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
factory.relate('Notification', 'User', { from: 'not-for-you', to: 'neighbor' }),
|
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', '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', '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', () => {
|
describe('filter for read: false', () => {
|
||||||
const query = `query($read: Boolean) {
|
const query = gql`
|
||||||
currentUser {
|
query($read: Boolean) {
|
||||||
notifications(read: $read, orderBy: createdAt_desc) {
|
currentUser {
|
||||||
id
|
notifications(read: $read, orderBy: createdAt_desc) {
|
||||||
post {
|
|
||||||
id
|
id
|
||||||
|
post {
|
||||||
|
id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`
|
`
|
||||||
const variables = { read: false }
|
const variables = { read: false }
|
||||||
it('returns only unread notifications of current user', async () => {
|
it('returns only unread notifications of current user', async () => {
|
||||||
const expected = {
|
const expected = {
|
||||||
@ -91,16 +103,18 @@ describe('currentUser { notifications }', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('no filters', () => {
|
describe('no filters', () => {
|
||||||
const query = `{
|
const query = gql`
|
||||||
currentUser {
|
query {
|
||||||
notifications(orderBy: createdAt_desc) {
|
currentUser {
|
||||||
id
|
notifications(orderBy: createdAt_desc) {
|
||||||
post {
|
|
||||||
id
|
id
|
||||||
|
post {
|
||||||
|
id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`
|
`
|
||||||
it('returns all notifications of current user', async () => {
|
it('returns all notifications of current user', async () => {
|
||||||
const expected = {
|
const expected = {
|
||||||
currentUser: {
|
currentUser: {
|
||||||
@ -118,11 +132,14 @@ describe('currentUser { notifications }', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('UpdateNotification', () => {
|
describe('UpdateNotification', () => {
|
||||||
const mutation = `mutation($id: ID!, $read: Boolean){
|
const mutation = gql`
|
||||||
UpdateNotification(id: $id, read: $read) {
|
mutation($id: ID!, $read: Boolean) {
|
||||||
id read
|
UpdateNotification(id: $id, read: $read) {
|
||||||
|
id
|
||||||
|
read
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}`
|
`
|
||||||
const variables = { id: 'to-be-updated', read: true }
|
const variables = { id: 'to-be-updated', read: true }
|
||||||
|
|
||||||
describe('given a notifications', () => {
|
describe('given a notifications', () => {
|
||||||
@ -138,7 +155,7 @@ describe('UpdateNotification', () => {
|
|||||||
await factory.create('User', mentionedParams)
|
await factory.create('User', mentionedParams)
|
||||||
await factory.create('Notification', { id: 'to-be-updated' })
|
await factory.create('Notification', { id: 'to-be-updated' })
|
||||||
await factory.authenticateAs(userParams)
|
await factory.authenticateAs(userParams)
|
||||||
await factory.create('Post', { id: 'p1' })
|
await factory.create('Post', { id: 'p1', categoryIds })
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
factory.relate('Notification', 'User', { from: 'to-be-updated', to: 'mentioned-1' }),
|
factory.relate('Notification', 'User', { from: 'to-be-updated', to: 'mentioned-1' }),
|
||||||
factory.relate('Notification', 'Post', { from: 'p1', to: 'to-be-updated' }),
|
factory.relate('Notification', 'Post', { from: 'p1', to: 'to-be-updated' }),
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
import { GraphQLClient } from 'graphql-request'
|
import { GraphQLClient } from 'graphql-request'
|
||||||
import Factory from '../../seed/factories'
|
import Factory from '../../seed/factories'
|
||||||
import { host, login } from '../../jest/helpers'
|
import { host, login } from '../../jest/helpers'
|
||||||
|
import { neode } from '../../bootstrap/neo4j'
|
||||||
|
|
||||||
const factory = Factory()
|
const factory = Factory()
|
||||||
|
const instance = neode()
|
||||||
|
|
||||||
describe('report', () => {
|
describe('report', () => {
|
||||||
let mutation
|
let mutation
|
||||||
@ -10,6 +12,7 @@ describe('report', () => {
|
|||||||
let returnedObject
|
let returnedObject
|
||||||
let variables
|
let variables
|
||||||
let createPostVariables
|
let createPostVariables
|
||||||
|
const categoryIds = ['cat9']
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
returnedObject = '{ description }'
|
returnedObject = '{ description }'
|
||||||
@ -28,6 +31,11 @@ describe('report', () => {
|
|||||||
role: 'user',
|
role: 'user',
|
||||||
email: 'abusive-user@example.org',
|
email: 'abusive-user@example.org',
|
||||||
})
|
})
|
||||||
|
await instance.create('Category', {
|
||||||
|
id: 'cat9',
|
||||||
|
name: 'Democracy & Politics',
|
||||||
|
icon: 'university',
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
@ -126,6 +134,7 @@ describe('report', () => {
|
|||||||
await factory.create('Post', {
|
await factory.create('Post', {
|
||||||
id: 'p23',
|
id: 'p23',
|
||||||
title: 'Matt and Robert having a pair-programming',
|
title: 'Matt and Robert having a pair-programming',
|
||||||
|
categoryIds,
|
||||||
})
|
})
|
||||||
variables = {
|
variables = {
|
||||||
id: 'p23',
|
id: 'p23',
|
||||||
@ -171,6 +180,7 @@ describe('report', () => {
|
|||||||
id: 'p1',
|
id: 'p1',
|
||||||
title: 'post to comment on',
|
title: 'post to comment on',
|
||||||
content: 'please comment on me',
|
content: 'please comment on me',
|
||||||
|
categoryIds,
|
||||||
}
|
}
|
||||||
const asAuthenticatedUser = await factory.authenticateAs({
|
const asAuthenticatedUser = await factory.authenticateAs({
|
||||||
email: 'test@example.org',
|
email: 'test@example.org',
|
||||||
|
|||||||
@ -1,22 +1,39 @@
|
|||||||
import { GraphQLClient } from 'graphql-request'
|
import { GraphQLClient } from 'graphql-request'
|
||||||
import Factory from '../../seed/factories'
|
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 clientUser1, clientUser2
|
||||||
let headersUser1, headersUser2
|
let headersUser1, headersUser2
|
||||||
|
const factory = Factory()
|
||||||
|
const instance = neode()
|
||||||
|
const categoryIds = ['cat9']
|
||||||
|
|
||||||
const mutationShoutPost = id => `
|
const mutationShoutPost = gql`
|
||||||
mutation {
|
mutation($id: ID!) {
|
||||||
shout(id: "${id}", type: Post)
|
shout(id: $id, type: Post)
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
const mutationUnshoutPost = id => `
|
const mutationUnshoutPost = gql`
|
||||||
mutation {
|
mutation($id: ID!) {
|
||||||
unshout(id: "${id}", type: Post)
|
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 () => {
|
beforeEach(async () => {
|
||||||
await factory.create('User', {
|
await factory.create('User', {
|
||||||
id: 'u1',
|
id: 'u1',
|
||||||
@ -28,28 +45,23 @@ beforeEach(async () => {
|
|||||||
email: 'test2@example.org',
|
email: 'test2@example.org',
|
||||||
password: '1234',
|
password: '1234',
|
||||||
})
|
})
|
||||||
|
await instance.create('Category', {
|
||||||
|
id: 'cat9',
|
||||||
|
name: 'Democracy & Politics',
|
||||||
|
icon: 'university',
|
||||||
|
})
|
||||||
headersUser1 = await login({ email: 'test@example.org', password: '1234' })
|
headersUser1 = await login({ email: 'test@example.org', password: '1234' })
|
||||||
headersUser2 = await login({ email: 'test2@example.org', password: '1234' })
|
headersUser2 = await login({ email: 'test2@example.org', password: '1234' })
|
||||||
clientUser1 = new GraphQLClient(host, { headers: headersUser1 })
|
clientUser1 = new GraphQLClient(host, { headers: headersUser1 })
|
||||||
clientUser2 = new GraphQLClient(host, { headers: headersUser2 })
|
clientUser2 = new GraphQLClient(host, { headers: headersUser2 })
|
||||||
|
|
||||||
await clientUser1.request(`
|
await clientUser1.request(createPostMutation, createPostVariables)
|
||||||
mutation {
|
await clientUser2.request(createPostMutation, {
|
||||||
CreatePost(id: "p1", title: "Post Title 1", content: "Some Post Content 1") {
|
id: 'p12345',
|
||||||
id
|
title: 'Post Title 12345',
|
||||||
title
|
content: 'Some Post Content 12345',
|
||||||
}
|
categoryIds,
|
||||||
}
|
})
|
||||||
`)
|
|
||||||
await clientUser2.request(`
|
|
||||||
mutation {
|
|
||||||
CreatePost(id: "p2", title: "Post Title 2", content: "Some Post Content 2") {
|
|
||||||
id
|
|
||||||
title
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
@ -61,22 +73,26 @@ describe('shout', () => {
|
|||||||
describe('unauthenticated shout', () => {
|
describe('unauthenticated shout', () => {
|
||||||
it('throws authorization error', async () => {
|
it('throws authorization error', async () => {
|
||||||
const client = new GraphQLClient(host)
|
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 () => {
|
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 = {
|
const expected = {
|
||||||
shout: true,
|
shout: true,
|
||||||
}
|
}
|
||||||
expect(res).toMatchObject(expected)
|
expect(res).toMatchObject(expected)
|
||||||
|
|
||||||
const { Post } = await clientUser1.request(`{
|
const { Post } = await clientUser1.request(gql`
|
||||||
Post(id: "p2") {
|
query {
|
||||||
shoutedByCurrentUser
|
Post(id: "p12345") {
|
||||||
|
shoutedByCurrentUser
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}`)
|
`)
|
||||||
const expected2 = {
|
const expected2 = {
|
||||||
shoutedByCurrentUser: true,
|
shoutedByCurrentUser: true,
|
||||||
}
|
}
|
||||||
@ -84,17 +100,19 @@ describe('shout', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('I can`t shout my own post', async () => {
|
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 = {
|
const expected = {
|
||||||
shout: false,
|
shout: false,
|
||||||
}
|
}
|
||||||
expect(res).toMatchObject(expected)
|
expect(res).toMatchObject(expected)
|
||||||
|
|
||||||
const { Post } = await clientUser1.request(`{
|
const { Post } = await clientUser1.request(gql`
|
||||||
Post(id: "p1") {
|
query {
|
||||||
shoutedByCurrentUser
|
Post(id: "p1234") {
|
||||||
|
shoutedByCurrentUser
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}`)
|
`)
|
||||||
const expected2 = {
|
const expected2 = {
|
||||||
shoutedByCurrentUser: false,
|
shoutedByCurrentUser: false,
|
||||||
}
|
}
|
||||||
@ -106,28 +124,32 @@ describe('shout', () => {
|
|||||||
describe('unauthenticated shout', () => {
|
describe('unauthenticated shout', () => {
|
||||||
it('throws authorization error', async () => {
|
it('throws authorization error', async () => {
|
||||||
// shout
|
// shout
|
||||||
await clientUser1.request(mutationShoutPost('p2'))
|
await clientUser1.request(mutationShoutPost, { id: 'p12345' })
|
||||||
// unshout
|
// unshout
|
||||||
const client = new GraphQLClient(host)
|
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 () => {
|
it('I unshout a post of another user', async () => {
|
||||||
// shout
|
// shout
|
||||||
await clientUser1.request(mutationShoutPost('p2'))
|
await clientUser1.request(mutationShoutPost, { id: 'p12345' })
|
||||||
const expected = {
|
const expected = {
|
||||||
unshout: true,
|
unshout: true,
|
||||||
}
|
}
|
||||||
// unshout
|
// unshout
|
||||||
const res = await clientUser1.request(mutationUnshoutPost('p2'))
|
const res = await clientUser1.request(mutationUnshoutPost, { id: 'p12345' })
|
||||||
expect(res).toMatchObject(expected)
|
expect(res).toMatchObject(expected)
|
||||||
|
|
||||||
const { Post } = await clientUser1.request(`{
|
const { Post } = await clientUser1.request(gql`
|
||||||
Post(id: "p2") {
|
query {
|
||||||
shoutedByCurrentUser
|
Post(id: "p12345") {
|
||||||
|
shoutedByCurrentUser
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}`)
|
`)
|
||||||
const expected2 = {
|
const expected2 = {
|
||||||
shoutedByCurrentUser: false,
|
shoutedByCurrentUser: false,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
import { GraphQLClient } from 'graphql-request'
|
import { GraphQLClient } from 'graphql-request'
|
||||||
import Factory from '../../seed/factories'
|
import Factory from '../../seed/factories'
|
||||||
import { host, login, gql } from '../../jest/helpers'
|
import { host, login, gql } from '../../jest/helpers'
|
||||||
|
import { neode } from '../../bootstrap/neo4j'
|
||||||
|
|
||||||
const factory = Factory()
|
|
||||||
let client
|
let client
|
||||||
|
const factory = Factory()
|
||||||
|
const instance = neode()
|
||||||
|
const categoryIds = ['cat9']
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await factory.cleanDatabase()
|
await factory.cleanDatabase()
|
||||||
@ -195,9 +198,15 @@ describe('users', () => {
|
|||||||
email: 'test@example.org',
|
email: 'test@example.org',
|
||||||
password: '1234',
|
password: '1234',
|
||||||
})
|
})
|
||||||
|
await instance.create('Category', {
|
||||||
|
id: 'cat9',
|
||||||
|
name: 'Democracy & Politics',
|
||||||
|
icon: 'university',
|
||||||
|
})
|
||||||
await asAuthor.create('Post', {
|
await asAuthor.create('Post', {
|
||||||
id: 'p139',
|
id: 'p139',
|
||||||
content: 'Post by user u343',
|
content: 'Post by user u343',
|
||||||
|
categoryIds,
|
||||||
})
|
})
|
||||||
await asAuthor.create('Comment', {
|
await asAuthor.create('Comment', {
|
||||||
id: 'c155',
|
id: 'c155',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user