Created
June 23, 2020 08:07
-
-
Save kianaditya/42e965272c12671c065b606fcbb988cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const app = require('../../app') | |
const supertest = require('supertest') | |
const { factory, expect } = require('../test_helper') | |
let server, request | |
before((done) => { | |
server = app.listen(done) | |
request = supertest.agent(server) | |
}) | |
after((done) => { | |
server.close(done) | |
}) | |
afterEach(async () => { | |
await factory.cleanUp() | |
}) | |
describe('GET /api/v1/auth', () => { | |
describe('with valid credentials', async () => { | |
const response = await request | |
.post('/api/v1/auth/login') | |
.send({ email: '[email protected]', password: 'password' }) | |
it('should respond with 200', () => { | |
expect(response.status).to.equal(200) | |
}) | |
it('should return a token', () => { | |
expect(response.body) | |
.to.be.an.instanceof(Object) | |
.and.to.have.property('token') | |
}) | |
}) | |
describe('with invalid credentials', async () => { | |
const response = await request | |
.post('/api/v1/auth/login') | |
.send({ email: '[email protected]', password: 'wrong-password' }) | |
it('should respond with 401', () => { | |
expect(response.status).to.equal(401) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment