Refactor user factory

This commit is contained in:
roschaefer 2020-01-28 01:52:20 +01:00
parent 63939fa9e0
commit 2a79c53765
24 changed files with 611 additions and 362 deletions

View File

@ -147,55 +147,90 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
louie,
dagobert,
] = await Promise.all([
factory.create('User', {
id: 'u1',
name: 'Peter Lustig',
slug: 'peter-lustig',
role: 'admin',
email: 'admin@example.org',
}),
factory.create('User', {
id: 'u2',
name: 'Bob der Baumeister',
slug: 'bob-der-baumeister',
role: 'moderator',
email: 'moderator@example.org',
}),
factory.create('User', {
id: 'u3',
name: 'Jenny Rostock',
slug: 'jenny-rostock',
role: 'user',
email: 'user@example.org',
}),
factory.create('User', {
id: 'u4',
name: 'Huey',
slug: 'huey',
role: 'user',
email: 'huey@example.org',
}),
factory.create('User', {
id: 'u5',
name: 'Dewey',
slug: 'dewey',
role: 'user',
email: 'dewey@example.org',
}),
factory.create('User', {
id: 'u6',
name: 'Louie',
slug: 'louie',
role: 'user',
email: 'louie@example.org',
}),
factory.create('User', {
id: 'u7',
name: 'Dagobert',
slug: 'dagobert',
role: 'user',
email: 'dagobert@example.org',
}),
factory.create(
'User',
{
id: 'u1',
name: 'Peter Lustig',
slug: 'peter-lustig',
role: 'admin',
},
{
email: 'admin@example.org',
},
),
factory.create(
'User',
{
id: 'u2',
name: 'Bob der Baumeister',
slug: 'bob-der-baumeister',
role: 'moderator',
},
{
email: 'moderator@example.org',
},
),
factory.create(
'User',
{
id: 'u3',
name: 'Jenny Rostock',
slug: 'jenny-rostock',
role: 'user',
},
{
email: 'user@example.org',
},
),
factory.create(
'User',
{
id: 'u4',
name: 'Huey',
slug: 'huey',
role: 'user',
},
{
email: 'huey@example.org',
},
),
factory.create(
'User',
{
id: 'u5',
name: 'Dewey',
slug: 'dewey',
role: 'user',
},
{
email: 'dewey@example.org',
},
),
factory.create(
'User',
{
id: 'u6',
name: 'Louie',
slug: 'louie',
role: 'user',
},
{
email: 'louie@example.org',
},
),
factory.create(
'User',
{
id: 'u7',
name: 'Dagobert',
slug: 'dagobert',
role: 'user',
},
{
email: 'dagobert@example.org',
},
),
])
await Promise.all([

View File

@ -40,10 +40,11 @@ export default function Factory(options = {}) {
factories,
lastResponse: null,
neodeInstance,
async create(node, args = {}) {
async create(node, args = {}, options = {}) {
const { factory } = this.factories[node](args)
this.lastResponse = await factory({
args,
options,
neodeInstance,
factoryInstance: this,
})

View File

@ -13,7 +13,7 @@ Factory.define('socialMedia')
export default function create() {
return {
factory: async ({ args, neodeInstance }) => {
factory: async ({ args }) => {
return Factory.build('socialMedia', args)
},
}

View File

@ -1,44 +1,54 @@
import faker from 'faker'
import uuid from 'uuid/v4'
import encryptPassword from '../helpers/encryptPassword'
import slugify from 'slug'
import { Factory } from 'rosie'
import { getNeode } from '../db/neo4j'
import { hashSync } from 'bcryptjs'
const neode = getNeode()
Factory.define('userWithoutEmailAddress')
.option('password', '1234')
.attrs({
id: uuid,
name: faker.name.findName,
email: faker.internet.email,
password: '1234',
role: 'user',
avatar: faker.internet.avatar,
about: faker.lorem.paragraph,
termsAndConditionsAgreedVersion: '0.0.1',
termsAndConditionsAgreedAt: '2019-08-01T10:47:19.212Z',
allowEmbedIframes: false,
showShoutsPublicly: false,
locale: 'en',
})
.attr('slug', ['slug', 'name'], (slug, name) => {
return slug || slugify(name, { lower: true })
})
.attr('encryptedPassword', ['password'], password => {
return hashSync(password, 10)
})
.after(async (buildObject, options) => {
return neode.create('User', buildObject)
})
Factory.define('user')
.option('email', faker.internet.exampleEmail)
.extend('userWithoutEmailAddress')
.after(async (buildObject, options) => {
const [user, email] = await Promise.all([
buildObject,
neode.create('EmailAddress', { email: options.email }),
])
await Promise.all([user.relateTo(email, 'primaryEmail'), email.relateTo(user, 'belongsTo')])
return user
})
export default function create() {
return {
factory: async ({ args, neodeInstance, factoryInstance }) => {
const defaults = {
id: uuid(),
name: faker.name.findName(),
email: faker.internet.email(),
password: '1234',
role: 'user',
avatar: faker.internet.avatar(),
about: faker.lorem.paragraph(),
termsAndConditionsAgreedVersion: '0.0.1',
termsAndConditionsAgreedAt: '2019-08-01T10:47:19.212Z',
allowEmbedIframes: false,
showShoutsPublicly: false,
locale: 'en',
}
defaults.slug = slugify(defaults.name, { lower: true })
args = {
...defaults,
...args,
}
args = await encryptPassword(args)
const user = await neodeInstance.create('User', args)
let email
if (typeof args.email === 'object') {
// probably a neode node
email = args.email
} else {
email = await factoryInstance.create('EmailAddress', { email: args.email })
}
await user.relateTo(email, 'primaryEmail')
await email.relateTo(user, 'belongsTo')
return user
factory: async ({ args, options }) => {
return Factory.build('user', args, options)
},
}
}

View File

@ -65,14 +65,19 @@ describe('decode', () => {
describe('and corresponding user in the database', () => {
let user
beforeEach(async () => {
user = await factory.create('User', {
role: 'user',
name: 'Jenny Rostock',
avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/sasha_shestakov/128.jpg',
id: 'u3',
email: 'user@example.org',
slug: 'jenny-rostock',
})
user = await factory.create(
'User',
{
role: 'user',
name: 'Jenny Rostock',
avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/sasha_shestakov/128.jpg',
id: 'u3',
slug: 'jenny-rostock',
},
{
email: 'user@example.org',
},
)
})
it('returns user object except email', async () => {

View File

@ -48,13 +48,18 @@ beforeAll(() => {
})
beforeEach(async () => {
hashtagingUser = await neode.create('User', {
id: 'you',
name: 'Al Capone',
slug: 'al-capone',
email: 'test@example.org',
password: '1234',
})
hashtagingUser = await neode.create(
'User',
{
id: 'you',
name: 'Al Capone',
slug: 'al-capone',
},
{
password: '1234',
email: 'test@example.org',
},
)
await neode.create('Category', {
id: 'cat9',
name: 'Democracy & Politics',

View File

@ -53,13 +53,18 @@ beforeAll(async () => {
})
beforeEach(async () => {
notifiedUser = await neode.create('User', {
id: 'you',
name: 'Al Capone',
slug: 'al-capone',
email: 'test@example.org',
password: '1234',
})
notifiedUser = await neode.create(
'User',
{
id: 'you',
name: 'Al Capone',
slug: 'al-capone',
},
{
email: 'test@example.org',
password: '1234',
},
)
await neode.create('Category', {
id: 'cat9',
name: 'Democracy & Politics',
@ -143,13 +148,18 @@ describe('notifications', () => {
describe('commenter is not me', () => {
beforeEach(async () => {
commentContent = 'Commenters comment.'
commentAuthor = await neode.create('User', {
id: 'commentAuthor',
name: 'Mrs Comment',
slug: 'mrs-comment',
email: 'commentauthor@example.org',
password: '1234',
})
commentAuthor = await neode.create(
'User',
{
id: 'commentAuthor',
name: 'Mrs Comment',
slug: 'mrs-comment',
},
{
email: 'commentauthor@example.org',
password: '1234',
},
)
})
it('sends me a notification', async () => {
@ -224,13 +234,18 @@ describe('notifications', () => {
})
beforeEach(async () => {
postAuthor = await neode.create('User', {
id: 'postAuthor',
name: 'Mrs Post',
slug: 'mrs-post',
email: 'post-author@example.org',
password: '1234',
})
postAuthor = await neode.create(
'User',
{
id: 'postAuthor',
name: 'Mrs Post',
slug: 'mrs-post',
},
{
email: 'post-author@example.org',
password: '1234',
},
)
})
describe('mentions me in a post', () => {
@ -428,23 +443,33 @@ describe('notifications', () => {
beforeEach(async () => {
commentContent =
'One mention about me with <a data-mention-id="you" class="mention" href="/profile/you" target="_blank">@al-capone</a>.'
commentAuthor = await neode.create('User', {
id: 'commentAuthor',
name: 'Mrs Comment',
slug: 'mrs-comment',
email: 'comment-author@example.org',
password: '1234',
})
commentAuthor = await neode.create(
'User',
{
id: 'commentAuthor',
name: 'Mrs Comment',
slug: 'mrs-comment',
},
{
email: 'comment-author@example.org',
password: '1234',
},
)
})
it('sends only one notification with reason mentioned_in_comment', async () => {
postAuthor = await neode.create('User', {
id: 'MrPostAuthor',
name: 'Mr Author',
slug: 'mr-author',
email: 'post-author@example.org',
password: '1234',
})
postAuthor = await neode.create(
'User',
{
id: 'MrPostAuthor',
name: 'Mr Author',
slug: 'mr-author',
},
{
email: 'post-author@example.org',
password: '1234',
},
)
await createCommentOnPostAction()
const expected = expect.objectContaining({
@ -514,13 +539,18 @@ describe('notifications', () => {
await postAuthor.relateTo(notifiedUser, 'blocked')
commentContent =
'One mention about me with <a data-mention-id="you" class="mention" href="/profile/you" target="_blank">@al-capone</a>.'
commentAuthor = await neode.create('User', {
id: 'commentAuthor',
name: 'Mrs Comment',
slug: 'mrs-comment',
email: 'comment-author@example.org',
password: '1234',
})
commentAuthor = await neode.create(
'User',
{
id: 'commentAuthor',
name: 'Mrs Comment',
slug: 'mrs-comment',
},
{
email: 'comment-author@example.org',
password: '1234',
},
)
})
it('sends no notification', async () => {

View File

@ -34,28 +34,48 @@ describe('authorization', () => {
describe('given two existing users', () => {
beforeEach(async () => {
;[owner, anotherRegularUser, administrator, moderator] = await Promise.all([
factory.create('User', {
email: 'owner@example.org',
name: 'Owner',
password: 'iamtheowner',
}),
factory.create('User', {
email: 'another.regular.user@example.org',
name: 'Another Regular User',
password: 'else',
}),
factory.create('User', {
email: 'admin@example.org',
name: 'Admin',
password: 'admin',
role: 'admin',
}),
factory.create('User', {
email: 'moderator@example.org',
name: 'Moderator',
password: 'moderator',
role: 'moderator',
}),
factory.create(
'User',
{
name: 'Owner',
},
{
email: 'owner@example.org',
password: 'iamtheowner',
},
),
factory.create(
'User',
{
name: 'Another Regular User',
},
{
email: 'another.regular.user@example.org',
password: 'else',
},
),
factory.create(
'User',
{
name: 'Admin',
role: 'admin',
},
{
email: 'admin@example.org',
password: 'admin',
},
),
factory.create(
'User',
{
name: 'Moderator',
role: 'moderator',
},
{
email: 'moderator@example.org',
password: 'moderator',
},
),
])
variables = {}
})

View File

@ -31,10 +31,14 @@ beforeEach(async () => {
const admin = await factory.create('User', {
role: 'admin',
})
await factory.create('User', {
email: 'someone@example.org',
password: '1234',
})
await factory.create(
'User',
{},
{
email: 'someone@example.org',
password: '1234',
},
)
await factory.create('Category', {
id: 'cat9',
name: 'Democracy & Politics',

View File

@ -19,11 +19,16 @@ beforeAll(async () => {
// For performance reasons we do this only once
const users = await Promise.all([
factory.create('User', { id: 'u1', role: 'user' }),
factory.create('User', {
id: 'm1',
role: 'moderator',
password: '1234',
}),
factory.create(
'User',
{
id: 'm1',
role: 'moderator',
},
{
password: '1234',
},
),
factory.create('User', {
id: 'u2',
role: 'user',

View File

@ -63,7 +63,7 @@ describe('AddEmailAddress', () => {
describe('authenticated', () => {
beforeEach(async () => {
user = await factory.create('User', { id: '567', email: 'user@example.org' })
user = await factory.create('User', { id: '567' }, { email: 'user@example.org' })
authenticatedUser = await user.toJson()
})
@ -128,7 +128,7 @@ describe('AddEmailAddress', () => {
describe('but if another user owns an `EmailAddress` already with that email', () => {
it('throws UserInputError because of unique constraints', async () => {
await factory.create('User', { email: 'new-email@example.org' })
await factory.create('User', {}, { email: 'new-email@example.org' })
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
data: { AddEmailAddress: null },
errors: [{ message: 'A user account with this email already exists.' }],
@ -169,7 +169,7 @@ describe('VerifyEmailAddress', () => {
describe('authenticated', () => {
beforeEach(async () => {
user = await factory.create('User', { id: '567', email: 'user@example.org' })
user = await factory.create('User', { id: '567' }, { email: 'user@example.org' })
authenticatedUser = await user.toJson()
})

View File

@ -73,20 +73,30 @@ beforeAll(async () => {
beforeEach(async () => {
user1 = await factory
.create('User', {
id: 'u1',
name: 'user1',
email: 'test@example.org',
password: '1234',
})
.create(
'User',
{
id: 'u1',
name: 'user1',
},
{
email: 'test@example.org',
password: '1234',
},
)
.then(user => user.toJson())
user2 = await factory
.create('User', {
id: 'u2',
name: 'user2',
email: 'test2@example.org',
password: '1234',
})
.create(
'User',
{
id: 'u2',
name: 'user2',
},
{
email: 'test2@example.org',
password: '1234',
},
)
.then(user => user.toJson())
authenticatedUser = user1

View File

@ -80,19 +80,29 @@ describe('moderate resources', () => {
closed: false,
}
authenticatedUser = null
moderator = await factory.create('User', {
id: 'moderator-id',
name: 'Moderator',
email: 'moderator@example.org',
password: '1234',
role: 'moderator',
})
nonModerator = await factory.create('User', {
id: 'non-moderator',
name: 'Non Moderator',
email: 'non.moderator@example.org',
password: '1234',
})
moderator = await factory.create(
'User',
{
id: 'moderator-id',
name: 'Moderator',
role: 'moderator',
},
{
email: 'moderator@example.org',
password: '1234',
},
)
nonModerator = await factory.create(
'User',
{
id: 'non-moderator',
name: 'Non Moderator',
},
{
email: 'non.moderator@example.org',
password: '1234',
},
)
})
afterEach(async () => {

View File

@ -45,9 +45,13 @@ afterEach(async () => {
describe('passwordReset', () => {
describe('given a user', () => {
beforeEach(async () => {
await factory.create('User', {
email: 'user@example.org',
})
await factory.create(
'User',
{},
{
email: 'user@example.org',
},
)
})
describe('requestPasswordReset', () => {
@ -123,11 +127,16 @@ describe('resetPassword', () => {
describe('given a user', () => {
beforeEach(async () => {
await factory.create('User', {
email: 'user@example.org',
role: 'user',
password: '1234',
})
await factory.create(
'User',
{
role: 'user',
},
{
email: 'user@example.org',
password: '1234',
},
)
})
describe('invalid email', () => {

View File

@ -56,12 +56,17 @@ beforeAll(async () => {
beforeEach(async () => {
variables = {}
user = await factory.create('User', {
id: 'current-user',
name: 'TestUser',
email: 'test@example.org',
password: '1234',
})
user = await factory.create(
'User',
{
id: 'current-user',
name: 'TestUser',
},
{
email: 'test@example.org',
password: '1234',
},
)
await Promise.all([
neode.create('Category', {
id: 'cat9',
@ -96,12 +101,17 @@ describe('Post', () => {
let followedUser, happyPost, cryPost
beforeEach(async () => {
;[followedUser] = await Promise.all([
factory.create('User', {
id: 'followed-by-me',
email: 'followed@example.org',
name: 'Followed User',
password: '1234',
}),
factory.create(
'User',
{
id: 'followed-by-me',
name: 'Followed User',
},
{
email: 'followed@example.org',
password: '1234',
},
),
])
;[happyPost, cryPost] = await Promise.all([
factory.create('Post', { id: 'happy-post', categoryIds: ['cat4'] }),

View File

@ -1,4 +1,5 @@
import Factory from '../../factories'
import { Factory as RosieFactory } from 'rosie'
import { gql } from '../../helpers/jest'
import { getDriver, getNeode } from '../../db/neo4j'
import createServer from '../../server'
@ -58,11 +59,16 @@ describe('Signup', () => {
describe('as admin', () => {
beforeEach(async () => {
const admin = await factory.create('User', {
role: 'admin',
email: 'admin@example.org',
password: '1234',
})
const admin = await factory.create(
'User',
{
role: 'admin',
},
{
email: 'admin@example.org',
password: '1234',
},
)
authenticatedUser = await admin.toJson()
})
@ -90,9 +96,9 @@ describe('Signup', () => {
})
describe('if the email already exists', () => {
let email
let emailAddress
beforeEach(async () => {
email = await factory.create('EmailAddress', {
emailAddress = await factory.create('EmailAddress', {
email: 'someuser@example.org',
verifiedAt: null,
})
@ -100,7 +106,8 @@ describe('Signup', () => {
describe('and the user has registered already', () => {
beforeEach(async () => {
await factory.create('User', { email })
const user = await RosieFactory.build('userWithoutEmailAddress')
await emailAddress.relateTo(user, 'belongsTo')
})
it('throws UserInputError error because of unique constraint violation', async () => {

View File

@ -84,24 +84,39 @@ describe('file a report on a resource', () => {
describe('authenticated', () => {
beforeEach(async () => {
currentUser = await factory.create('User', {
id: 'current-user-id',
role: 'user',
email: 'test@example.org',
password: '1234',
})
otherReportingUser = await factory.create('User', {
id: 'other-reporting-user-id',
role: 'user',
email: 'reporting@example.org',
password: '1234',
})
await factory.create('User', {
id: 'abusive-user-id',
role: 'user',
name: 'abusive-user',
email: 'abusive-user@example.org',
})
currentUser = await factory.create(
'User',
{
id: 'current-user-id',
role: 'user',
},
{
email: 'test@example.org',
password: '1234',
},
)
otherReportingUser = await factory.create(
'User',
{
id: 'other-reporting-user-id',
role: 'user',
},
{
email: 'reporting@example.org',
password: '1234',
},
)
await factory.create(
'User',
{
id: 'abusive-user-id',
role: 'user',
name: 'abusive-user',
},
{
email: 'abusive-user@example.org',
},
)
await instance.create('Category', {
id: 'cat9',
name: 'Democracy & Politics',
@ -515,24 +530,39 @@ describe('file a report on a resource', () => {
beforeEach(async () => {
authenticatedUser = null
moderator = await factory.create('User', {
id: 'moderator-1',
role: 'moderator',
email: 'moderator@example.org',
password: '1234',
})
currentUser = await factory.create('User', {
id: 'current-user-id',
role: 'user',
email: 'current.user@example.org',
password: '1234',
})
abusiveUser = await factory.create('User', {
id: 'abusive-user-1',
role: 'user',
name: 'abusive-user',
email: 'abusive-user@example.org',
})
moderator = await factory.create(
'User',
{
id: 'moderator-1',
role: 'moderator',
},
{
email: 'moderator@example.org',
password: '1234',
},
)
currentUser = await factory.create(
'User',
{
id: 'current-user-id',
role: 'user',
},
{
email: 'current.user@example.org',
password: '1234',
},
)
abusiveUser = await factory.create(
'User',
{
id: 'abusive-user-1',
role: 'user',
name: 'abusive-user',
},
{
email: 'abusive-user@example.org',
},
)
await instance.create('Category', {
id: 'cat9',
name: 'Democracy & Politics',

View File

@ -31,22 +31,37 @@ describe('rewards', () => {
})
beforeEach(async () => {
regularUser = await factory.create('User', {
id: 'regular-user-id',
role: 'user',
email: 'user@example.org',
password: '1234',
})
moderator = await factory.create('User', {
id: 'moderator-id',
role: 'moderator',
email: 'moderator@example.org',
})
administrator = await factory.create('User', {
id: 'admin-id',
role: 'admin',
email: 'admin@example.org',
})
regularUser = await factory.create(
'User',
{
id: 'regular-user-id',
role: 'user',
},
{
email: 'user@example.org',
password: '1234',
},
)
moderator = await factory.create(
'User',
{
id: 'moderator-id',
role: 'moderator',
},
{
email: 'moderator@example.org',
},
)
administrator = await factory.create(
'User',
{
id: 'admin-id',
role: 'admin',
},
{
email: 'admin@example.org',
},
)
badge = await factory.create('Badge', {
id: 'indiegogo_en_rhino',
type: 'crowdfunding',
@ -172,10 +187,15 @@ describe('rewards', () => {
},
errors: undefined,
}
await factory.create('User', {
id: 'regular-user-2-id',
email: 'regular2@email.com',
})
await factory.create(
'User',
{
id: 'regular-user-2-id',
},
{
email: 'regular2@email.com',
},
)
await mutate({
mutation: rewardMutation,
variables,

View File

@ -47,19 +47,29 @@ describe('shout and unshout posts', () => {
query = createTestClient(server).query
})
beforeEach(async () => {
currentUser = await factory.create('User', {
id: 'current-user-id',
name: 'Current User',
email: 'current.user@example.org',
password: '1234',
})
currentUser = await factory.create(
'User',
{
id: 'current-user-id',
name: 'Current User',
},
{
email: 'current.user@example.org',
password: '1234',
},
)
postAuthor = await factory.create('User', {
id: 'id-of-another-user',
name: 'Another User',
email: 'another.user@example.org',
password: '1234',
})
postAuthor = await factory.create(
'User',
{
id: 'id-of-another-user',
name: 'Another User',
},
{
email: 'another.user@example.org',
password: '1234',
},
)
})
afterEach(async () => {
await factory.cleanDatabase()

View File

@ -2,40 +2,46 @@ import { createTestClient } from 'apollo-server-testing'
import createServer from '../../server'
import Factory from '../../factories'
import { gql } from '../../helpers/jest'
import { getNeode, getDriver } from '../../db/neo4j'
import { getDriver } from '../../db/neo4j'
const driver = getDriver()
const factory = Factory()
const neode = getNeode()
describe('SocialMedia', () => {
let socialMediaAction, someUser, ownerNode, owner
const ownerParams = {
email: 'pippi@example.com',
password: '1234',
name: 'Pippi Langstrumpf',
}
const userParams = {
email: 'kalle@example.com',
password: 'abcd',
name: 'Kalle Blomqvist',
}
const url = 'https://twitter.com/pippi-langstrumpf'
const newUrl = 'https://twitter.com/bullerby'
const setUpSocialMedia = async () => {
const socialMediaNode = await neode.create('SocialMedia', { url })
const socialMediaNode = await factory.create('SocialMedia', { url })
await socialMediaNode.relateTo(ownerNode, 'ownedBy')
return socialMediaNode.toJson()
}
beforeEach(async () => {
const someUserNode = await neode.create('User', userParams)
const someUserNode = await factory.create(
'User',
{
name: 'Kalle Blomqvist',
},
{
email: 'kalle@example.com',
password: 'abcd',
},
)
someUser = await someUserNode.toJson()
ownerNode = await neode.create('User', ownerParams)
ownerNode = await factory.create(
'User',
{
name: 'Pippi Langstrumpf',
},
{
email: 'pippi@example.com',
password: '1234',
},
)
owner = await ownerNode.toJson()
socialMediaAction = async (user, mutation, variables) => {

View File

@ -127,15 +127,20 @@ describe('currentUser', () => {
describe('authenticated', () => {
describe('and corresponding user in the database', () => {
beforeEach(async () => {
await factory.create('User', {
id: 'u3',
// the `id` is the only thing that has to match the decoded JWT bearer token
avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/jimmuirhead/128.jpg',
email: 'test@example.org',
name: 'Matilde Hermiston',
slug: 'matilde-hermiston',
role: 'user',
})
await factory.create(
'User',
{
id: 'u3',
// the `id` is the only thing that has to match the decoded JWT bearer token
avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/jimmuirhead/128.jpg',
name: 'Matilde Hermiston',
slug: 'matilde-hermiston',
role: 'user',
},
{
email: 'test@example.org',
},
)
const userBearerToken = encode({ id: 'u3' })
req = { headers: { authorization: `Bearer ${userBearerToken}` } }
})
@ -172,10 +177,13 @@ describe('login', () => {
beforeEach(async () => {
variables = { email: 'test@example.org', password: '1234' }
user = await factory.create('User', {
...variables,
id: 'acb2d923-f3af-479e-9f00-61b12e864666',
})
user = await factory.create(
'User',
{
id: 'acb2d923-f3af-479e-9f00-61b12e864666',
},
variables,
)
})
describe('ask for a `token`', () => {

View File

@ -37,7 +37,7 @@ afterEach(async () => {
describe('User', () => {
describe('query by email address', () => {
beforeEach(async () => {
await factory.create('User', { name: 'Johnny', email: 'any-email-address@example.org' })
await factory.create('User', { name: 'Johnny' }, { email: 'any-email-address@example.org' })
})
const userQuery = gql`
@ -57,11 +57,16 @@ describe('User', () => {
describe('as admin', () => {
beforeEach(async () => {
const admin = await factory.create('User', {
role: 'admin',
email: 'admin@example.org',
password: '1234',
})
const admin = await factory.create(
'User',
{
role: 'admin',
},
{
email: 'admin@example.org',
password: '1234',
},
)
authenticatedUser = await admin.toJson()
})
@ -91,19 +96,9 @@ describe('User', () => {
})
describe('UpdateUser', () => {
let userParams, variables
let variables
beforeEach(async () => {
userParams = {
email: 'user@example.org',
password: '1234',
id: 'u47',
name: 'John Doe',
termsAndConditionsAgreedVersion: null,
termsAndConditionsAgreedAt: null,
allowEmbedIframes: false,
}
variables = {
id: 'u47',
name: 'John Doughnut',
@ -133,18 +128,33 @@ describe('UpdateUser', () => {
`
beforeEach(async () => {
user = await factory.create('User', userParams)
user = await factory.create(
'User',
{
id: 'u47',
name: 'John Doe',
termsAndConditionsAgreedVersion: null,
termsAndConditionsAgreedAt: null,
allowEmbedIframes: false,
},
{
email: 'user@example.org',
},
)
})
describe('as another user', () => {
beforeEach(async () => {
const someoneElseParams = {
email: 'someone-else@example.org',
password: '1234',
name: 'James Doe',
}
const someoneElse = await factory.create(
'User',
{
name: 'James Doe',
},
{
email: 'someone-else@example.org',
},
)
const someoneElse = await factory.create('User', someoneElseParams)
authenticatedUser = await someoneElse.toJson()
})
@ -272,11 +282,15 @@ describe('DeleteUser', () => {
about: 'along with my about',
id: 'u343',
})
await factory.create('User', {
email: 'friends-account@example.org',
password: '1234',
id: 'not-my-account',
})
await factory.create(
'User',
{
id: 'not-my-account',
},
{
email: 'friends-account@example.org',
},
)
})
describe('unauthenticated', () => {

View File

@ -146,7 +146,7 @@ describe('userMiddleware', () => {
})
describe('UpdateUser', () => {
let user, userParams
let user
beforeEach(async () => {
newlyCreatedNodesWithLocales = [
{
@ -182,10 +182,9 @@ describe('userMiddleware', () => {
},
},
]
userParams = {
user = await factory.create('User', {
id: 'updating-user',
}
user = await factory.create('User', userParams)
})
authenticatedUser = await user.toJson()
})

View File

@ -13,8 +13,9 @@ function createUser (slug) {
debug(`creating user ${slug}`)
return factory.create('User', {
name: slug,
email: 'example@test.org',
}, {
password: '1234'
email: 'example@test.org',
})
// await login({ email: 'example@test.org', password: '1234' })
}