From 5bcfb065114470510132478ce87929b0058ba256 Mon Sep 17 00:00:00 2001 From: aonomike Date: Mon, 30 Sep 2019 11:22:12 +0300 Subject: [PATCH 1/2] Make clearDatabase() await --- backend/src/schema/resolvers/shout.spec.js | 46 ++++++++-------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/backend/src/schema/resolvers/shout.spec.js b/backend/src/schema/resolvers/shout.spec.js index e39ac2e24..097aec279 100644 --- a/backend/src/schema/resolvers/shout.spec.js +++ b/backend/src/schema/resolvers/shout.spec.js @@ -46,8 +46,23 @@ describe('shout and unshout posts', () => { mutate = createTestClient(server).mutate query = createTestClient(server).query }) - afterEach(() => { - factory.cleanDatabase() + beforeEach(async () => { + 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', + }) + }) + afterEach(async () => { + await factory.cleanDatabase() }) describe('shout', () => { @@ -62,19 +77,6 @@ describe('shout and unshout posts', () => { }) describe('authenticated', () => { beforeEach(async () => { - 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: 'post-author-id', - name: 'Post Author', - email: 'post.author@example.org', - password: '1234', - }) authenticatedUser = await currentUser.toJson() await factory.create('Post', { name: 'Other user post', @@ -125,19 +127,6 @@ describe('shout and unshout posts', () => { describe('authenticated', () => { beforeEach(async () => { - 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', - }) authenticatedUser = await currentUser.toJson() await factory.create('Post', { name: 'Posted By Another User', @@ -148,7 +137,6 @@ describe('shout and unshout posts', () => { mutation: mutationShoutPost, variables: { id: 'posted-by-another-user' }, }) - variables = {} }) it("another user's post", async () => { From ff91cb231fcd9aacea9566c7ca758b961a20cf89 Mon Sep 17 00:00:00 2001 From: aonomike Date: Mon, 30 Sep 2019 11:33:59 +0300 Subject: [PATCH 2/2] Refactor it clauses --- backend/src/schema/resolvers/shout.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/schema/resolvers/shout.spec.js b/backend/src/schema/resolvers/shout.spec.js index 097aec279..63617541e 100644 --- a/backend/src/schema/resolvers/shout.spec.js +++ b/backend/src/schema/resolvers/shout.spec.js @@ -91,7 +91,7 @@ describe('shout and unshout posts', () => { variables = {} }) - it("another user's post", async () => { + it("can shout another user's post", async () => { variables = { id: 'another-user-post-id' } await expect(mutate({ mutation: mutationShoutPost, variables })).resolves.toMatchObject({ data: { shout: true }, @@ -102,7 +102,7 @@ describe('shout and unshout posts', () => { }) }) - it('my own post', async () => { + it('can not shout my own post', async () => { variables = { id: 'current-user-post-id' } await expect(mutate({ mutation: mutationShoutPost, variables })).resolves.toMatchObject({ data: { shout: false }, @@ -139,7 +139,7 @@ describe('shout and unshout posts', () => { }) }) - it("another user's post", async () => { + it("can unshout another user's post", async () => { variables = { id: 'posted-by-another-user' } await expect(mutate({ mutation: mutationUnshoutPost, variables })).resolves.toMatchObject({ data: { unshout: true },