Refactor factory for comments

This commit is contained in:
roschaefer 2020-01-28 19:56:57 +01:00
parent 95bfb090fd
commit 2fc71d75a5
12 changed files with 890 additions and 527 deletions

View File

@ -385,101 +385,149 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
])
const [p0, p1, p3, p4, p5, p6, p9, p10, p11, p13, p14, p15] = await Promise.all([
factory.create('Post', {
id: 'p0',
language: sample(languages),
image: faker.image.unsplash.food(300, 169),
imageBlurred: true,
imageAspectRatio: 300 / 169,
}, {
categoryIds: ['cat16'],
author: peterLustig,
}),
factory.create('Post', {
id: 'p1',
language: sample(languages),
image: faker.image.unsplash.technology(300, 1500),
imageAspectRatio: 300 / 1500,
}, {
categoryIds: ['cat1'],
author: bobDerBaumeister,
}),
factory.create('Post', {
id: 'p3',
language: sample(languages),
}, {
categoryIds: ['cat3'],
author: huey,
}),
factory.create('Post', {
id: 'p4',
language: sample(languages),
}, {
categoryIds: ['cat4'],
author: dewey,
}),
factory.create('Post', {
id: 'p5',
language: sample(languages),
}, {
categoryIds: ['cat5'],
author: louie,
}),
factory.create('Post', {
id: 'p6',
language: sample(languages),
image: faker.image.unsplash.buildings(300, 857),
imageAspectRatio: 300 / 857,
}, {
categoryIds: ['cat6'],
author: peterLustig,
}),
factory.create('Post', {
id: 'p9',
language: sample(languages),
}, {
categoryIds: ['cat9'],
author: huey,
}),
factory.create('Post', {
id: 'p10',
imageBlurred: true,
}, {
author: dewey,
categoryIds: ['cat10'],
}),
factory.create('Post', {
id: 'p11',
language: sample(languages),
image: faker.image.unsplash.people(300, 901),
imageAspectRatio: 300 / 901,
}, {
categoryIds: ['cat11'],
author: louie,
}),
factory.create('Post', {
id: 'p13',
language: sample(languages),
}, {
author: bobDerBaumeister,
categoryIds: ['cat13'],
}),
factory.create('Post', {
id: 'p14',
language: sample(languages),
image: faker.image.unsplash.objects(300, 200),
imageAspectRatio: 300 / 450,
}, {
author: jennyRostock,
categoryIds: ['cat14'],
}),
factory.create('Post', {
id: 'p15',
language: sample(languages),
}, {
author: huey,
categoryIds: ['cat15'],
}),
factory.create(
'Post',
{
id: 'p0',
language: sample(languages),
image: faker.image.unsplash.food(300, 169),
imageBlurred: true,
imageAspectRatio: 300 / 169,
},
{
categoryIds: ['cat16'],
author: peterLustig,
},
),
factory.create(
'Post',
{
id: 'p1',
language: sample(languages),
image: faker.image.unsplash.technology(300, 1500),
imageAspectRatio: 300 / 1500,
},
{
categoryIds: ['cat1'],
author: bobDerBaumeister,
},
),
factory.create(
'Post',
{
id: 'p3',
language: sample(languages),
},
{
categoryIds: ['cat3'],
author: huey,
},
),
factory.create(
'Post',
{
id: 'p4',
language: sample(languages),
},
{
categoryIds: ['cat4'],
author: dewey,
},
),
factory.create(
'Post',
{
id: 'p5',
language: sample(languages),
},
{
categoryIds: ['cat5'],
author: louie,
},
),
factory.create(
'Post',
{
id: 'p6',
language: sample(languages),
image: faker.image.unsplash.buildings(300, 857),
imageAspectRatio: 300 / 857,
},
{
categoryIds: ['cat6'],
author: peterLustig,
},
),
factory.create(
'Post',
{
id: 'p9',
language: sample(languages),
},
{
categoryIds: ['cat9'],
author: huey,
},
),
factory.create(
'Post',
{
id: 'p10',
imageBlurred: true,
},
{
author: dewey,
categoryIds: ['cat10'],
},
),
factory.create(
'Post',
{
id: 'p11',
language: sample(languages),
image: faker.image.unsplash.people(300, 901),
imageAspectRatio: 300 / 901,
},
{
categoryIds: ['cat11'],
author: louie,
},
),
factory.create(
'Post',
{
id: 'p13',
language: sample(languages),
},
{
author: bobDerBaumeister,
categoryIds: ['cat13'],
},
),
factory.create(
'Post',
{
id: 'p14',
language: sample(languages),
image: faker.image.unsplash.objects(300, 200),
imageAspectRatio: 300 / 450,
},
{
author: jennyRostock,
categoryIds: ['cat14'],
},
),
factory.create(
'Post',
{
id: 'p15',
language: sample(languages),
},
{
author: huey,
categoryIds: ['cat15'],
},
),
])
authenticatedUser = await louie.toJson()
@ -601,61 +649,116 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
authenticatedUser = null
const comments = await Promise.all([
factory.create('Comment', {
author: jennyRostock,
id: 'c1',
postId: 'p1',
}),
factory.create('Comment', {
author: huey,
id: 'c2',
postId: 'p1',
}),
factory.create('Comment', {
author: louie,
id: 'c3',
postId: 'p3',
}),
factory.create('Comment', {
author: jennyRostock,
id: 'c5',
postId: 'p3',
}),
factory.create('Comment', {
author: peterLustig,
id: 'c6',
postId: 'p4',
}),
factory.create('Comment', {
author: jennyRostock,
id: 'c7',
postId: 'p2',
}),
factory.create('Comment', {
author: huey,
id: 'c8',
postId: 'p15',
}),
factory.create('Comment', {
author: dewey,
id: 'c9',
postId: 'p15',
}),
factory.create('Comment', {
author: louie,
id: 'c10',
postId: 'p15',
}),
factory.create('Comment', {
author: jennyRostock,
id: 'c11',
postId: 'p15',
}),
factory.create('Comment', {
author: jennyRostock,
id: 'c12',
postId: 'p15',
}),
factory.create(
'Comment',
{
id: 'c1',
},
{
author: jennyRostock,
postId: 'p1',
},
),
factory.create(
'Comment',
{
id: 'c2',
},
{
author: huey,
postId: 'p1',
},
),
factory.create(
'Comment',
{
id: 'c3',
},
{
author: louie,
postId: 'p3',
},
),
factory.create(
'Comment',
{
id: 'c5',
},
{
author: jennyRostock,
postId: 'p3',
},
),
factory.create(
'Comment',
{
id: 'c6',
},
{
author: peterLustig,
postId: 'p4',
},
),
factory.create(
'Comment',
{
id: 'c7',
},
{
author: jennyRostock,
postId: 'p2',
},
),
factory.create(
'Comment',
{
id: 'c8',
},
{
author: huey,
postId: 'p15',
},
),
factory.create(
'Comment',
{
id: 'c9',
},
{
author: dewey,
postId: 'p15',
},
),
factory.create(
'Comment',
{
id: 'c10',
},
{
author: louie,
postId: 'p15',
},
),
factory.create(
'Comment',
{
id: 'c11',
},
{
author: jennyRostock,
postId: 'p15',
},
),
factory.create(
'Comment',
{
id: 'c12',
},
{
author: jennyRostock,
postId: 'p15',
},
),
])
const trollingComment = comments[0]
@ -839,224 +942,320 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
await Promise.all(
[...Array(30).keys()].map(() => {
return factory.create('Post', {
image: faker.image.unsplash.objects(),
}, {
categoryIds: ['cat1'],
author: jennyRostock,
})
return factory.create(
'Post',
{
image: faker.image.unsplash.objects(),
},
{
categoryIds: ['cat1'],
author: jennyRostock,
},
)
}),
)
await Promise.all(
[...Array(6).keys()].map(() => {
return factory.create('Comment', {
author: jennyRostock,
postId: 'p2',
})
return factory.create(
'Comment',
{},
{
author: jennyRostock,
postId: 'p2',
},
)
}),
)
await Promise.all(
[...Array(4).keys()].map(() => {
return factory.create('Comment', {
author: jennyRostock,
postId: 'p15',
})
return factory.create(
'Comment',
{},
{
author: jennyRostock,
postId: 'p15',
},
)
}),
)
await Promise.all(
[...Array(2).keys()].map(() => {
return factory.create('Comment', {
author: jennyRostock,
postId: 'p4',
})
return factory.create(
'Comment',
{},
{
author: jennyRostock,
postId: 'p4',
},
)
}),
)
await Promise.all(
[...Array(21).keys()].map(() => {
return factory.create('Post', {
image: faker.image.unsplash.buildings(),
}, {
author: peterLustig,
})
return factory.create(
'Post',
{
image: faker.image.unsplash.buildings(),
},
{
author: peterLustig,
},
)
}),
)
await Promise.all(
[...Array(3).keys()].map(() => {
return factory.create('Comment', {
author: peterLustig,
postId: 'p4',
})
return factory.create(
'Comment',
{},
{
author: peterLustig,
postId: 'p4',
},
)
}),
)
await Promise.all(
[...Array(5).keys()].map(() => {
return factory.create('Comment', {
author: peterLustig,
postId: 'p14',
})
return factory.create(
'Comment',
{},
{
author: peterLustig,
postId: 'p14',
},
)
}),
)
await Promise.all(
[...Array(6).keys()].map(() => {
return factory.create('Comment', {
author: peterLustig,
postId: 'p0',
})
return factory.create(
'Comment',
{},
{
author: peterLustig,
postId: 'p0',
},
)
}),
)
await Promise.all(
[...Array(11).keys()].map(() => {
return factory.create('Post', {
image: faker.image.unsplash.food(),
}, {
author: dewey,
})
return factory.create(
'Post',
{
image: faker.image.unsplash.food(),
},
{
author: dewey,
},
)
}),
)
await Promise.all(
[...Array(7).keys()].map(() => {
return factory.create('Comment', {
author: dewey,
postId: 'p2',
})
return factory.create(
'Comment',
{},
{
author: dewey,
postId: 'p2',
},
)
}),
)
await Promise.all(
[...Array(5).keys()].map(() => {
return factory.create('Comment', {
author: dewey,
postId: 'p6',
})
return factory.create(
'Comment',
{},
{
author: dewey,
postId: 'p6',
},
)
}),
)
await Promise.all(
[...Array(2).keys()].map(() => {
return factory.create('Comment', {
author: dewey,
postId: 'p9',
})
return factory.create(
'Comment',
{},
{
author: dewey,
postId: 'p9',
},
)
}),
)
await Promise.all(
[...Array(16).keys()].map(() => {
return factory.create('Post', {
image: faker.image.unsplash.technology(),
}, {
author: louie,
})
return factory.create(
'Post',
{
image: faker.image.unsplash.technology(),
},
{
author: louie,
},
)
}),
)
await Promise.all(
[...Array(4).keys()].map(() => {
return factory.create('Comment', {
postId: 'p1',
author: louie,
})
return factory.create(
'Comment',
{},
{
postId: 'p1',
author: louie,
},
)
}),
)
await Promise.all(
[...Array(8).keys()].map(() => {
return factory.create('Comment', {
author: louie,
postId: 'p10',
})
return factory.create(
'Comment',
{},
{
author: louie,
postId: 'p10',
},
)
}),
)
await Promise.all(
[...Array(5).keys()].map(() => {
return factory.create('Comment', {
author: louie,
postId: 'p13',
})
return factory.create(
'Comment',
{},
{
author: louie,
postId: 'p13',
},
)
}),
)
await Promise.all(
[...Array(45).keys()].map(() => {
return factory.create('Post', {
image: faker.image.unsplash.people(),
}, {
author: bobDerBaumeister,
})
return factory.create(
'Post',
{
image: faker.image.unsplash.people(),
},
{
author: bobDerBaumeister,
},
)
}),
)
await Promise.all(
[...Array(2).keys()].map(() => {
return factory.create('Comment', {
author: bobDerBaumeister,
postId: 'p2',
})
return factory.create(
'Comment',
{},
{
author: bobDerBaumeister,
postId: 'p2',
},
)
}),
)
await Promise.all(
[...Array(3).keys()].map(() => {
return factory.create('Comment', {
author: bobDerBaumeister,
postId: 'p12',
})
return factory.create(
'Comment',
{},
{
author: bobDerBaumeister,
postId: 'p12',
},
)
}),
)
await Promise.all(
[...Array(7).keys()].map(() => {
return factory.create('Comment', {
author: bobDerBaumeister,
postId: 'p13',
})
return factory.create(
'Comment',
{},
{
author: bobDerBaumeister,
postId: 'p13',
},
)
}),
)
await Promise.all(
[...Array(8).keys()].map(() => {
return factory.create('Post', {
image: faker.image.unsplash.nature(),
}, {
author: huey,
})
return factory.create(
'Post',
{
image: faker.image.unsplash.nature(),
},
{
author: huey,
},
)
}),
)
await Promise.all(
[...Array(6).keys()].map(() => {
return factory.create('Comment', {
author: huey,
postId: 'p0',
})
return factory.create(
'Comment',
{},
{
author: huey,
postId: 'p0',
},
)
}),
)
await Promise.all(
[...Array(8).keys()].map(() => {
return factory.create('Comment', {
author: huey,
postId: 'p13',
})
return factory.create(
'Comment',
{},
{
author: huey,
postId: 'p13',
},
)
}),
)
await Promise.all(
[...Array(9).keys()].map(() => {
return factory.create('Comment', {
author: huey,
postId: 'p15',
})
return factory.create(
'Comment',
{},
{
author: huey,
postId: 'p15',
},
)
}),
)

View File

@ -1,38 +1,42 @@
import faker from 'faker'
import uuid from 'uuid/v4'
import { Factory } from 'rosie'
import { getNeode } from '../db/neo4j'
const neode = getNeode()
Factory.define('comment')
.option('postId', null)
.option('post', ['postId'], postId => {
if (postId) return neode.find('Post', postId)
return Factory.build('post')
})
.option('authorId', null)
.option('author', ['authorId'], authorId => {
if (authorId) return neode.find('User', authorId)
return Factory.build('user')
})
.attrs({
id: uuid,
content: faker.lorem.sentence,
})
.attr('contentExcerpt', ['contentExcerpt', 'content'], (contentExcerpt, content) => {
return contentExcerpt || content
})
.after(async (buildObject, options) => {
const [comment, author, post] = await Promise.all([
neode.create('Comment', buildObject),
options.author,
options.post,
])
await Promise.all([comment.relateTo(author, 'author'), comment.relateTo(post, 'post')])
return comment
})
export default function create() {
return {
factory: async ({ args, neodeInstance, factoryInstance }) => {
const defaults = {
id: uuid(),
content: [faker.lorem.sentence(), faker.lorem.sentence()].join('. '),
}
args = {
...defaults,
...args,
}
args.contentExcerpt = args.contentExcerpt || args.content
let { post, postId } = args
delete args.post
delete args.postId
if (post && postId) throw new Error('You provided both post and postId')
if (postId) post = await neodeInstance.find('Post', postId)
post = post || (await factoryInstance.create('Post'))
let { author, authorId } = args
delete args.author
delete args.authorId
if (author && authorId) throw new Error('You provided both author and authorId')
if (authorId) author = await neodeInstance.find('User', authorId)
author = author || (await factoryInstance.create('User'))
delete args.author
const comment = await neodeInstance.create('Comment', args)
await comment.relateTo(post, 'post')
await comment.relateTo(author, 'author')
return comment
factory: async ({ args, options, neodeInstance, factoryInstance }) => {
return Factory.build('comment', args, options)
},
}
}

View File

@ -8,17 +8,17 @@ const neode = getNeode()
Factory.define('post')
.option('categoryIds', [])
.option('categories', ['categoryIds'], (categoryIds) => {
.option('categories', ['categoryIds'], categoryIds => {
if (categoryIds.length) return Promise.all(categoryIds.map(id => neode.find('Category', id)))
// there must be at least one category
return Promise.all([Factory.build('category')])
})
.option('tagIds', [])
.option('tags', ['tagIds'], (tagIds) => {
.option('tags', ['tagIds'], tagIds => {
return Promise.all(tagIds.map(id => neode.find('Tag', id)))
})
.option('authorId', null)
.option('author', ['authorId'], (authorId) => {
.option('author', ['authorId'], authorId => {
if (authorId) return neode.find('User', authorId)
return Factory.build('user')
})
@ -33,7 +33,7 @@ Factory.define('post')
imageBlurred: false,
imageAspectRatio: 1.333,
})
.attr('pinned', ['pinned'], (pinned) => {
.attr('pinned', ['pinned'], pinned => {
// Convert false to null
return pinned || null
})

View File

@ -88,13 +88,17 @@ describe('slugifyMiddleware', () => {
describe('if slug exists', () => {
beforeEach(async () => {
await factory.create('Post', {
title: 'Pre-existing post',
slug: 'pre-existing-post',
content: 'as Someone else content',
}, {
categoryIds,
})
await factory.create(
'Post',
{
title: 'Pre-existing post',
slug: 'pre-existing-post',
content: 'as Someone else content',
},
{
categoryIds,
},
)
})
it('chooses another slug', async () => {

View File

@ -50,51 +50,73 @@ beforeAll(async () => {
await Promise.all([
user.relateTo(troll, 'following'),
factory.create('Post', {
id: 'p1',
title: 'Deleted post',
slug: 'deleted-post',
deleted: true,
}, {
author: user,
categoryIds,
}),
factory.create('Post', {
id: 'p3',
title: 'Publicly visible post',
slug: 'publicly-visible-post',
deleted: false,
}, {
author: user,
categoryIds,
}),
factory.create(
'Post',
{
id: 'p1',
title: 'Deleted post',
slug: 'deleted-post',
deleted: true,
},
{
author: user,
categoryIds,
},
),
factory.create(
'Post',
{
id: 'p3',
title: 'Publicly visible post',
slug: 'publicly-visible-post',
deleted: false,
},
{
author: user,
categoryIds,
},
),
])
const resources = await Promise.all([
factory.create('Comment', {
author: user,
id: 'c2',
postId: 'p3',
content: 'Enabled comment on public post',
}),
factory.create('Post', {
id: 'p2',
title: 'Disabled post',
content: 'This is an offensive post content',
contentExcerpt: 'This is an offensive post content',
image: '/some/offensive/image.jpg',
deleted: false,
}, {
author: troll,
categoryIds,
}),
factory.create('Comment', {
id: 'c1',
author: troll,
postId: 'p3',
content: 'Disabled comment',
contentExcerpt: 'Disabled comment',
}),
factory.create(
'Comment',
{
id: 'c2',
content: 'Enabled comment on public post',
},
{
author: user,
postId: 'p3',
},
),
factory.create(
'Post',
{
id: 'p2',
title: 'Disabled post',
content: 'This is an offensive post content',
contentExcerpt: 'This is an offensive post content',
image: '/some/offensive/image.jpg',
deleted: false,
},
{
author: troll,
categoryIds,
},
),
factory.create(
'Comment',
{
id: 'c1',
content: 'Disabled comment',
contentExcerpt: 'Disabled comment',
},
{
author: troll,
postId: 'p3',
},
),
])
const { server } = createServer({

View File

@ -119,16 +119,24 @@ beforeEach(async () => {
moderatingUser = users[1]
commentingUser = users[2]
const posts = await Promise.all([
factory.create('Post', {
id: 'offensive-post',
}, {
authorId: 'moderating-user',
}),
factory.create('Post', {
id: 'post-4-commenting',
}, {
authorId: 'commenting-user',
}),
factory.create(
'Post',
{
id: 'offensive-post',
},
{
authorId: 'moderating-user',
},
),
factory.create(
'Post',
{
id: 'post-4-commenting',
},
{
authorId: 'commenting-user',
},
),
])
offensivePost = posts[0]
})
@ -184,10 +192,15 @@ describe('validateCreateComment', () => {
describe('validateUpdateComment', () => {
let updateCommentVariables
beforeEach(async () => {
await factory.create('Comment', {
id: 'comment-id',
authorId: 'commenting-user',
})
await factory.create(
'Comment',
{
id: 'comment-id',
},
{
authorId: 'commenting-user',
},
)
updateCommentVariables = {
id: 'whatever',
content: '',

View File

@ -49,18 +49,27 @@ const createCommentMutation = gql`
`
const setupPostAndComment = async () => {
commentAuthor = await factory.create('User')
await factory.create('Post', {
id: 'p1',
content: 'Post to be commented',
}, {
categoryIds: ['cat9'],
})
newlyCreatedComment = await factory.create('Comment', {
id: 'c456',
postId: 'p1',
author: commentAuthor,
content: 'Comment to be deleted',
})
await factory.create(
'Post',
{
id: 'p1',
content: 'Post to be commented',
},
{
categoryIds: ['cat9'],
},
)
newlyCreatedComment = await factory.create(
'Comment',
{
id: 'c456',
content: 'Comment to be deleted',
},
{
postId: 'p1',
author: commentAuthor,
},
)
variables = {
...variables,
id: 'c456',
@ -89,7 +98,7 @@ describe('CreateComment', () => {
describe('given a post', () => {
beforeEach(async () => {
await factory.create('Post', { id: 'p1' }, { categoryIds: ['cat9'] } )
await factory.create('Post', { id: 'p1' }, { categoryIds: ['cat9'] })
variables = {
...variables,
postId: 'p1',

View File

@ -46,40 +46,63 @@ describe('given some notifications', () => {
])
const [post1, post2, post3] = await Promise.all([
factory.create('Post', { id: 'p1', content: 'Not for you' }, { author, categoryIds }),
factory.create('Post', {
id: 'p2',
content: 'Already seen post mention',
}, {
author,
categoryIds,
}),
factory.create('Post', {
id: 'p3',
content: 'You have been mentioned in a post',
}, {
author,
categoryIds,
}),
factory.create(
'Post',
{
id: 'p2',
content: 'Already seen post mention',
},
{
author,
categoryIds,
},
),
factory.create(
'Post',
{
id: 'p3',
content: 'You have been mentioned in a post',
},
{
author,
categoryIds,
},
),
])
const [comment1, comment2, comment3] = await Promise.all([
factory.create('Comment', {
author,
postId: 'p3',
id: 'c1',
content: 'You have seen this comment mentioning already',
}),
factory.create('Comment', {
author,
postId: 'p3',
id: 'c2',
content: 'You have been mentioned in a comment',
}),
factory.create('Comment', {
author,
postId: 'p3',
id: 'c3',
content: 'Somebody else was mentioned in a comment',
}),
factory.create(
'Comment',
{
id: 'c1',
content: 'You have seen this comment mentioning already',
},
{
author,
postId: 'p3',
},
),
factory.create(
'Comment',
{
id: 'c2',
content: 'You have been mentioned in a comment',
},
{
author,
postId: 'p3',
},
),
factory.create(
'Comment',
{
id: 'c3',
content: 'Somebody else was mentioned in a comment',
},
{
author,
postId: 'p3',
},
),
])
await Promise.all([
post1.relateTo(neighbor, 'notified', {

View File

@ -115,13 +115,17 @@ describe('Post', () => {
])
;[happyPost, cryPost] = await Promise.all([
factory.create('Post', { id: 'happy-post' }, { categoryIds: ['cat4'] }),
factory.create('Post', { id: 'cry-post'} , { categoryIds: ['cat15'] }),
factory.create('Post', {
id: 'post-by-followed-user',
}, {
categoryIds: ['cat9'],
author: followedUser,
}),
factory.create('Post', { id: 'cry-post' }, { categoryIds: ['cat15'] }),
factory.create(
'Post',
{
id: 'post-by-followed-user',
},
{
categoryIds: ['cat9'],
author: followedUser,
},
),
])
})
@ -352,14 +356,18 @@ describe('UpdatePost', () => {
`
beforeEach(async () => {
author = await factory.create('User', { slug: 'the-author' })
newlyCreatedPost = await factory.create('Post', {
id: 'p9876',
title: 'Old title',
content: 'Old content',
}, {
author,
categoryIds,
})
newlyCreatedPost = await factory.create(
'Post',
{
id: 'p9876',
title: 'Old title',
content: 'Old content',
},
{
author,
categoryIds,
},
)
variables = {
id: 'p9876',
@ -541,11 +549,15 @@ describe('UpdatePost', () => {
describe('are allowed to pin posts', () => {
beforeEach(async () => {
await factory.create('Post', {
id: 'created-and-pinned-by-same-admin',
}, {
author: admin,
})
await factory.create(
'Post',
{
id: 'created-and-pinned-by-same-admin',
},
{
author: admin,
},
)
variables = { ...variables, id: 'created-and-pinned-by-same-admin' }
})
@ -607,11 +619,15 @@ describe('UpdatePost', () => {
name: 'otherAdmin',
})
authenticatedUser = await otherAdmin.toJson()
await factory.create('Post', {
id: 'created-by-one-admin-pinned-by-different-one',
}, {
author: otherAdmin,
})
await factory.create(
'Post',
{
id: 'created-by-one-admin-pinned-by-different-one',
},
{
author: otherAdmin,
},
)
})
it('responds with the updated Post', async () => {
@ -668,11 +684,15 @@ describe('UpdatePost', () => {
describe('pinned post already exists', () => {
let pinnedPost
beforeEach(async () => {
await factory.create('Post', {
id: 'only-pinned-post',
}, {
author: admin,
})
await factory.create(
'Post',
{
id: 'only-pinned-post',
},
{
author: admin,
},
)
await mutate({ mutation: pinPostMutation, variables })
})
@ -890,15 +910,19 @@ describe('DeletePost', () => {
beforeEach(async () => {
author = await factory.create('User')
await factory.create('Post', {
id: 'p4711',
title: 'I will be deleted',
content: 'To be deleted',
image: 'path/to/some/image',
}, {
author,
categoryIds,
})
await factory.create(
'Post',
{
id: 'p4711',
title: 'I will be deleted',
content: 'To be deleted',
image: 'path/to/some/image',
},
{
author,
categoryIds,
},
)
variables = { ...variables, id: 'p4711' }
})
@ -945,11 +969,16 @@ describe('DeletePost', () => {
describe('if there are comments on the post', () => {
beforeEach(async () => {
await factory.create('Comment', {
postId: 'p4711',
content: 'to be deleted comment content',
contentExcerpt: 'to be deleted comment content',
})
await factory.create(
'Comment',
{
content: 'to be deleted comment content',
contentExcerpt: 'to be deleted comment content',
},
{
postId: 'p4711',
},
)
})
it('marks the comments as deleted', async () => {
@ -1004,12 +1033,16 @@ describe('emotions', () => {
beforeEach(async () => {
author = await neode.create('User', { id: 'u257' })
postToEmote = await factory.create('Post', {
id: 'p1376',
}, {
author,
categoryIds,
})
postToEmote = await factory.create(
'Post',
{
id: 'p1376',
},
{
author,
categoryIds,
},
)
variables = {
...variables,

View File

@ -356,13 +356,17 @@ describe('file a report on a resource', () => {
describe('reported resource is a post', () => {
beforeEach(async () => {
await factory.create('Post', {
id: 'post-to-report-id',
title: 'This is a post that is going to be reported',
}, {
author: currentUser,
categoryIds,
})
await factory.create(
'Post',
{
id: 'post-to-report-id',
title: 'This is a post that is going to be reported',
},
{
author: currentUser,
categoryIds,
},
)
})
it('returns type "Post"', async () => {
@ -411,20 +415,29 @@ describe('file a report on a resource', () => {
describe('reported resource is a comment', () => {
beforeEach(async () => {
await factory.create('Post', {
id: 'p1',
title: 'post to comment on',
content: 'please comment on me',
}, {
categoryIds,
author: currentUser
})
await factory.create('Comment', {
author: currentUser,
postId: 'p1',
id: 'comment-to-report-id',
content: 'Post comment to be reported.',
})
await factory.create(
'Post',
{
id: 'p1',
title: 'post to comment on',
content: 'please comment on me',
},
{
categoryIds,
author: currentUser,
},
)
await factory.create(
'Comment',
{
id: 'comment-to-report-id',
content: 'Post comment to be reported.',
},
{
author: currentUser,
postId: 'p1',
},
)
})
it('returns type "Comment"', async () => {
@ -571,34 +584,51 @@ describe('file a report on a resource', () => {
})
await Promise.all([
factory.create('Post', {
id: 'abusive-post-1',
content: 'Interesting Knowledge',
}, {
categoryIds,
author: abusiveUser,
}),
factory.create('Post', {
id: 'post-2',
content: 'More things to do …',
}, {
author: moderator,
categoryIds,
}),
factory.create('Post', {
id: 'post-3',
content: 'I am at school …',
}, {
categoryIds,
author: currentUser,
}),
factory.create(
'Post',
{
id: 'abusive-post-1',
content: 'Interesting Knowledge',
},
{
categoryIds,
author: abusiveUser,
},
),
factory.create(
'Post',
{
id: 'post-2',
content: 'More things to do …',
},
{
author: moderator,
categoryIds,
},
),
factory.create(
'Post',
{
id: 'post-3',
content: 'I am at school …',
},
{
categoryIds,
author: currentUser,
},
),
])
await Promise.all([
factory.create('Comment', {
author: currentUser,
id: 'abusive-comment-1',
postId: 'post-1',
}),
factory.create(
'Comment',
{
id: 'abusive-comment-1',
},
{
postId: 'post-2',
author: currentUser,
},
),
])
authenticatedUser = await currentUser.toJson()
await Promise.all([

View File

@ -88,18 +88,26 @@ describe('shout and unshout posts', () => {
describe('authenticated', () => {
beforeEach(async () => {
authenticatedUser = await currentUser.toJson()
await factory.create('Post', {
name: 'Other user post',
id: 'another-user-post-id',
}, {
author: postAuthor,
})
await factory.create('Post', {
name: 'current user post',
id: 'current-user-post-id',
}, {
author: currentUser,
})
await factory.create(
'Post',
{
name: 'Other user post',
id: 'another-user-post-id',
},
{
author: postAuthor,
},
)
await factory.create(
'Post',
{
name: 'current user post',
id: 'current-user-post-id',
},
{
author: currentUser,
},
)
variables = {}
})
@ -156,12 +164,16 @@ describe('shout and unshout posts', () => {
describe('authenticated', () => {
beforeEach(async () => {
authenticatedUser = await currentUser.toJson()
await factory.create('Post', {
name: 'Posted By Another User',
id: 'posted-by-another-user',
}, {
author: postAuthor,
})
await factory.create(
'Post',
{
name: 'Posted By Another User',
id: 'posted-by-another-user',
},
{
author: postAuthor,
},
)
await mutate({
mutation: mutationShoutPost,
variables: { id: 'posted-by-another-user' },

View File

@ -328,23 +328,37 @@ describe('DeleteUser', () => {
name: 'Democracy & Politics',
icon: 'university',
})
await factory.create('Post', {
id: 'p139',
content: 'Post by user u343',
}, {
author: user,
categoryIds,
})
await factory.create('Comment', {
author: user,
id: 'c155',
content: 'Comment by user u343',
})
await factory.create('Comment', {
postId: 'p139',
id: 'c156',
content: "A comment by someone else on user u343's post",
})
await factory.create(
'Post',
{
id: 'p139',
content: 'Post by user u343',
},
{
author: user,
categoryIds,
},
)
await factory.create(
'Comment',
{
id: 'c155',
content: 'Comment by user u343',
},
{
author: user,
},
)
await factory.create(
'Comment',
{
id: 'c156',
content: "A comment by someone else on user u343's post",
},
{
postId: 'p139',
},
)
})
it("deletes my account, but doesn't delete posts or comments by default", async () => {