diff --git a/package.json b/package.json index 97ce9e141..f40f582e9 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "eslint-plugin-node": "~8.0.0", "eslint-plugin-promise": "~4.0.1", "eslint-plugin-standard": "~4.0.0", + "graphql-request": "^1.8.2", "jest": "^23.6.0", "nodemon": "~1.18.9", "nyc": "^13.1.0", diff --git a/src/graphql-schema.test.js b/src/graphql-schema.test.js index a44e74fbc..80b1bba54 100644 --- a/src/graphql-schema.test.js +++ b/src/graphql-schema.test.js @@ -1,28 +1,42 @@ -import request from "supertest" -import server from './server' +import { request } from "graphql-request"; +import server from "./server"; +describe("login", () => { + describe("asking for a `token`", () => { + describe("with valid email/password combination", () => { + xit("responds with a JWT token", () => {}); + }); - -describe('login', () => { - describe('asking for a `token`', () => { - describe('with valid email/password combination', () => { - xit('responds with a JWT token', () => {}) - }) - - describe('with a valid email but incorrect password', () => { + describe("with a valid email but incorrect password", () => { beforeEach(() => { // create a user in the database - }) - xit('responds with "Wrong email/password combination"', () => {}) - }) + }); + xit('responds with "Wrong email/password combination"', () => {}); + }); - describe('with a non-existing email', () => { + describe("with a non-existing email", () => { + let getHost; + + beforeEach(async () => { + const app = await server.start({ port: 0 }); + const { port } = app.address(); + getHost = () => `http://127.0.0.1:${port}`; + }); + + const email = "tom@bob.com"; + const password = "jalksdf"; + + const mutation = ` + mutation { + login(email:"asfasf@baldf.cm", password:"asdfasd"){ + token + } + }`; it('responds with "Wrong email/password combination"', async () => { - const app = (await server).createHttpServer({}); - - request(app).post('/graphql').send({}).expect(400) - }) - }) - }) -}) + const response = await request(getHost(), mutation); + expect(response).toBe({}); + }); + }); + }); +}); diff --git a/yarn.lock b/yarn.lock index c7c6167df..19abca68e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3506,7 +3506,7 @@ graphql-playground-middleware-lambda@1.7.6: dependencies: graphql-playground-html "1.6.4" -graphql-request@^1.5.0: +graphql-request@^1.5.0, graphql-request@^1.8.2: version "1.8.2" resolved "https://registry.yarnpkg.com/graphql-request/-/graphql-request-1.8.2.tgz#398d10ae15c585676741bde3fc01d5ca948f8fbe" integrity sha512-dDX2M+VMsxXFCmUX0Vo0TopIZIX4ggzOtiCsThgtrKR4niiaagsGTDIHj3fsOMFETpa064vzovI+4YV4QnMbcg==