From 3f5ac61b73b161c4bef6aea7a31fd7d931c53eb9 Mon Sep 17 00:00:00 2001 From: roschaefer Date: Sat, 31 Aug 2019 00:47:40 +0200 Subject: [PATCH] Fix users and report resolver specs This time I did not refactor the whole tests suites because of time and complexity of the PR review. --- backend/src/schema/resolvers/reports.spec.js | 19 +++++++------------ backend/src/schema/resolvers/users.spec.js | 13 +++++++------ 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/backend/src/schema/resolvers/reports.spec.js b/backend/src/schema/resolvers/reports.spec.js index 7287a79f4..512d8d956 100644 --- a/backend/src/schema/resolvers/reports.spec.js +++ b/backend/src/schema/resolvers/reports.spec.js @@ -12,6 +12,7 @@ describe('report', () => { let returnedObject let variables let createPostVariables + let user const categoryIds = ['cat9'] beforeEach(async () => { @@ -20,10 +21,10 @@ describe('report', () => { id: 'whatever', } headers = {} - await factory.create('User', { - id: 'u1', + user = await factory.create('User', { email: 'test@example.org', password: '1234', + id: 'u1', }) await factory.create('User', { id: 'u2', @@ -127,11 +128,8 @@ describe('report', () => { describe('reported resource is a post', () => { beforeEach(async () => { - await factory.authenticateAs({ - email: 'test@example.org', - password: '1234', - }) await factory.create('Post', { + author: user, id: 'p23', title: 'Matt and Robert having a pair-programming', categoryIds, @@ -182,12 +180,9 @@ describe('report', () => { content: 'please comment on me', categoryIds, } - const asAuthenticatedUser = await factory.authenticateAs({ - email: 'test@example.org', - password: '1234', - }) - await asAuthenticatedUser.create('Post', createPostVariables) - await asAuthenticatedUser.create('Comment', { + await factory.create('Post', { ...createPostVariables, author: user }) + await factory.create('Comment', { + author: user, postId: 'p1', id: 'c34', content: 'Robert getting tired.', diff --git a/backend/src/schema/resolvers/users.spec.js b/backend/src/schema/resolvers/users.spec.js index 454b457e6..bf7a7ec2d 100644 --- a/backend/src/schema/resolvers/users.spec.js +++ b/backend/src/schema/resolvers/users.spec.js @@ -7,6 +7,7 @@ let client const factory = Factory() const instance = neode() const categoryIds = ['cat9'] +let user afterEach(async () => { await factory.cleanDatabase() @@ -132,7 +133,6 @@ describe('users', () => { describe('DeleteUser', () => { let deleteUserVariables - let asAuthor const deleteUserMutation = gql` mutation($id: ID!, $resource: [Deletable]) { DeleteUser(id: $id, resource: $resource) { @@ -149,7 +149,7 @@ describe('users', () => { } ` beforeEach(async () => { - await factory.create('User', { + user = await factory.create('User', { email: 'test@example.org', password: '1234', id: 'u343', @@ -193,8 +193,7 @@ describe('users', () => { describe('attempting to delete my own account', () => { let expectedResponse beforeEach(async () => { - asAuthor = Factory() - await asAuthor.authenticateAs({ + await factory.authenticateAs({ email: 'test@example.org', password: '1234', }) @@ -203,12 +202,14 @@ describe('users', () => { name: 'Democracy & Politics', icon: 'university', }) - await asAuthor.create('Post', { + await factory.create('Post', { + author: user, id: 'p139', content: 'Post by user u343', categoryIds, }) - await asAuthor.create('Comment', { + await factory.create('Comment', { + author: user, id: 'c155', postId: 'p139', content: 'Comment by user u343',