diff --git a/src/graphql-schema.test.js b/src/graphql-schema.test.js index 76050a2a8..4956c3ab0 100644 --- a/src/graphql-schema.test.js +++ b/src/graphql-schema.test.js @@ -8,17 +8,15 @@ let getHost let app let port -beforeEach(async (done) => { +beforeEach(async () => { const server = createServer({ mocks }) app = await server.start({ port: 0 }) port = app.address().port getHost = () => `http://127.0.0.1:${port}` - done() }) -afterAll(async (done) => { +afterEach(async () => { await app.close() - done() }) describe.only('login', () => { @@ -33,50 +31,45 @@ describe.only('login', () => { } describe('given an existing user', () => { - beforeEach(async (done) => { + beforeEach(async () => { await create('user', { email: 'test@example.org', password: '1234' }) - done() }) - afterEach(async (done) => { + afterEach(async () => { await cleanDatabase() - done() }) describe('asking for a `token`', () => { describe('with valid email/password combination', () => { - it('responds with a JWT token', async (done) => { + it('responds with a JWT token', async () => { const data = await request(getHost(), mutation({ email: 'test@example.org', password: '1234' })) const { token } = data.login jwt.verify(token, process.env.JWT_SECRET, (err, data) => { expect(data.email).toEqual('test@example.org') expect(err).toBeNull() - done() }) }) }) describe('with a valid email but incorrect password', () => { - it('responds with "Incorrect email address or password."', async (done) => { + it('responds with "Incorrect email address or password."', async () => { try { await request(getHost(), mutation({ email: 'test@example.org', password: 'wrong' })) } catch (error) { expect(error.response.errors[0].message).toEqual('Incorrect email address or password.') - done() } }) }) describe('with a non-existing email', () => { - it('responds with "Incorrect email address or password."', async (done) => { + it('responds with "Incorrect email address or password."', async () => { try { await request(getHost(), mutation({ email: 'non-existent@example.org', password: 'wrong' })) } catch (error) { expect(error.response.errors[0].message).toEqual('Incorrect email address or password.') - done() } }) })