Guest User

Untitled

a guest
Jul 21st, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const mongoose = require('mongoose')
  2. const should = require('should')
  3. const schema = require('../../models/user')
  4. const User = mongoose.model('User', schema)
  5. const app = require('../../app')
  6. const request = require('supertest')
  7.  
  8. describe('User: Routes', () => {
  9.  
  10.   describe('POST /auth/signup', () => {
  11.  
  12.     it('should create user if the form is valid', (done) => {
  13.       const data = {
  14.         name: 'Max',
  15.         email: '[email protected]',
  16.         password: 'secret',
  17.       }
  18.       request(app)
  19.         .post('/auth/signup')
  20.         .send(data)
  21.         .expect(200)
  22.         .end((err, res) => { //eslint-disable-line no-unused-vars
  23.           should.not.exist(err)
  24.           User.find((err, users) => {
  25.             users.length.should.equal(1)
  26.             const u = users[0]
  27.             u.name.should.equal(data.name)
  28.             u.email.should.equal(data.email)
  29.             should.exist(u.passwordHash)
  30.             done()
  31.           })
  32.         })
  33.     })
  34.  
  35.     it('should send errors array, if the form is invalid', (done) => {
  36.       const data = {
  37.         name: '',
  38.         email: 'test@',
  39.         password: 'sec', //less than 4
  40.       }
  41.       request(app)
  42.         .post('/auth/signup')
  43.         .send(data)
  44.         .expect(400)
  45.         .end((err, res) => {
  46.           should.not.exist(err)
  47.           res.body.errors.should.be.an.Array()
  48.           res.body.errors.should.have.length(2)
  49.           done()
  50.         })
  51.     })
  52.  
  53.   })
  54. })
Add Comment
Please, Sign In to add comment