/* tslint:disable:no-unused-expression */ import chai from 'chai'; import chaiHttp from 'chai-http'; import app from '../../src/app'; import { clearUsers, createUser } from './helper'; chai.use(chaiHttp); const request = chai.request; const expect = chai.expect; chai.should(); describe('User API', () => { describe('POST /signup', () => { let server: ChaiHttp.Agent; beforeEach(() => { server = request(app).keepOpen(); }); it('when supplied with user details, returns that user', async () => { const res = await server .post('/signup') .type('form') .send({ display_name: 'Test', email: 'test@example.com', password: 'passw0rd', }); res.status .should.equal(201); res .should.be.json; res.body.display_name .should.equal('Test'); res.body.email .should.equal('test@example.com'); res.body.password .should.equal('passw0rd'); res.body.id .should.not.be.empty; }); afterEach(async () => { return clearUsers(server).then(() => { server.close(); }); }); }); describe('GET /v1/users/{user_id}', () => { let server: ChaiHttp.Agent; let userId: string; beforeEach(async () => { server = request(app).keepOpen(); const res = await createUser(server, { display_name: 'Test', email: 'test@example.com', password: 'passw0rd', }); userId = res.body.id; }); it('given a user has been created, when supplied with user id, returns the correct user', async () => { const res = await server.get(`/v1/users/${userId}`); res.status .should.equal(200); res .should.be.json; res.body.display_name .should.equal('Test'); expect(res.body.email) .to.be.undefined; expect(res.body.password) .to.be.undefined; res.body.id .should.not.be.empty; }); afterEach(async () => { await clearUsers(server); server.close(); }); }); });