Last active
January 8, 2016 03:29
-
-
Save miyamotodev123/389d1e548dcdb44ad2db to your computer and use it in GitHub Desktop.
This file contains 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
var app = require('../../server.js'), | |
should = require('should'), | |
request = require('supertest'), | |
mongoose = require('mongoose'), | |
User = mongoose.model('User'), | |
api = request(app); | |
describe('testing user authentication endpoints', function () { | |
// clear users out from the test database | |
// before each test is run | |
beforeEach(function (done) { | |
User.remove({}, function() { | |
}); | |
// create a new user | |
var newUser = new User() | |
newUser.local.email = 'newuser' | |
newUser.local.password = 'password' | |
newUser.save(function (err) { | |
if (err) { | |
return done(err); | |
} | |
done(); | |
}) | |
}) | |
it('successfully created a user', function (done) { | |
// make a post reqeust to the /signup route | |
api.post('/signup') | |
// send an email and password as part of the request body | |
.send({ | |
email: 'foobar', | |
password: 'password' | |
}) | |
.expect(200) // check to see that the response status is the expected 200 status | |
.end(function (err, res) { | |
if (err) return done(err); | |
// check to see that the response body returns the expected | |
// json object of {redirect: '/profile'} | |
res.body.should.eql({redirect: '/profile'}); | |
// indicate that the test is done | |
done(); | |
}) | |
}) | |
it('fails to create a user with a duplicate email', function (done) { | |
api.post('/signup') | |
.send({ | |
email: 'newuser', | |
password: 'password' | |
}) | |
.expect(400) // check for a response status to equal 400 bad request | |
.end(function (err, res) { | |
if (err) return done(err); | |
// assert that the response body returns | |
// the expected error message | |
res.body.should.eql({error: 'That email is already taken.'}) | |
done(); | |
}) | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment