From 697c0010752e0622e8a56d31f82c82de0f3af45e Mon Sep 17 00:00:00 2001 From: Adrian Obelmejias Date: Mon, 15 Feb 2016 17:42:21 -0500 Subject: [PATCH] Add tests for user sign up --- test/users.spec.js | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/test/users.spec.js b/test/users.spec.js index b7438ac..774bb03 100644 --- a/test/users.spec.js +++ b/test/users.spec.js @@ -1,15 +1,39 @@ import app from '../config/server' import supertest from 'supertest' +import { expect, should } from 'chai' +should() const request = supertest.agent(app.listen()) +const context = {} describe('Users', () => { - describe('GET /users', () => { - it('should respond with 200', (done) => { + describe('POST /users', () => { + it('should reject signup when data is incomplete', (done) => { request - .get('/users') - .expect(200) - .expect({}, done) + .post('/users') + .set('Accept', 'application/json') + .send({ username: 'supercoolname' }) + .expect(422, done) + }) + + it('should sign up', (done) => { + request + .post('/users') + .set('Accept', 'application/json') + .send({ user: { username: 'supercoolname', password: 'supersecretpassword' } }) + .expect(200, (err, res) => { + if (err) { return done(err) } + + res.body.user.should.have.property('username') + res.body.user.username.should.equal('supercoolname') + expect(res.body.user.password).to.not.exist + expect(res.body.user.salt).to.not.exist + + context.user = res.body.user + context.token = res.body.token + + done() + }) }) }) })