Refactored user.server.routes.test.js
This commit is contained in:
parent
c09c8ee473
commit
2deeec5c84
|
@ -1,9 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var should = require('should'),
|
var should = require('should'),
|
||||||
_ = require('lodash'),
|
|
||||||
app = require('../../server'),
|
app = require('../../server'),
|
||||||
request = require('supertest'),
|
|
||||||
Session = require('supertest-session'),
|
Session = require('supertest-session'),
|
||||||
mongoose = require('mongoose'),
|
mongoose = require('mongoose'),
|
||||||
User = mongoose.model('User'),
|
User = mongoose.model('User'),
|
||||||
|
@ -13,11 +11,7 @@ var should = require('should'),
|
||||||
/**
|
/**
|
||||||
* Globals
|
* Globals
|
||||||
*/
|
*/
|
||||||
var credentials, _User;
|
var credentials, _User, activateToken, userSession;
|
||||||
var _tmpUser, activateToken;
|
|
||||||
var username, userSession;
|
|
||||||
|
|
||||||
username = 'testActiveAccount1.be1e58fb@mailosaur.in';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form routes tests
|
* Form routes tests
|
||||||
|
@ -50,7 +44,7 @@ describe('User CRUD tests', function() {
|
||||||
userSession.post('/auth/signup')
|
userSession.post('/auth/signup')
|
||||||
.send(_User)
|
.send(_User)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end(function(FormSaveErr, FormSaveRes) {
|
.end(function(FormSaveErr) {
|
||||||
console.log('CREATING USER');
|
console.log('CREATING USER');
|
||||||
// Handle error
|
// Handle error
|
||||||
should.not.exist(FormSaveErr);
|
should.not.exist(FormSaveErr);
|
||||||
|
@ -69,7 +63,10 @@ describe('User CRUD tests', function() {
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end(function(VerifyErr, VerifyRes) {
|
.end(function(VerifyErr, VerifyRes) {
|
||||||
// Handle error
|
// Handle error
|
||||||
if (VerifyErr) return done(VerifyErr);
|
if (VerifyErr) {
|
||||||
|
return done(VerifyErr);
|
||||||
|
}
|
||||||
|
|
||||||
(VerifyRes.text).should.equal('User successfully verified');
|
(VerifyRes.text).should.equal('User successfully verified');
|
||||||
|
|
||||||
userSession.post('/auth/signin')
|
userSession.post('/auth/signin')
|
||||||
|
@ -78,7 +75,9 @@ describe('User CRUD tests', function() {
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end(function(signinErr, signinRes) {
|
.end(function(signinErr, signinRes) {
|
||||||
// Handle signin error
|
// Handle signin error
|
||||||
if (signinErr) return done(signinErr);
|
if (signinErr) {
|
||||||
|
return done(signinErr);
|
||||||
|
}
|
||||||
|
|
||||||
var user = signinRes.body;
|
var user = signinRes.body;
|
||||||
(user.username).should.equal(credentials.username);
|
(user.username).should.equal(credentials.username);
|
||||||
|
@ -88,7 +87,9 @@ describe('User CRUD tests', function() {
|
||||||
.end(function(signoutErr, signoutRes) {
|
.end(function(signoutErr, signoutRes) {
|
||||||
|
|
||||||
// Handle signout error
|
// Handle signout error
|
||||||
if (signoutErr) return done(signoutErr);
|
if (signoutErr) {
|
||||||
|
return done(signoutErr);
|
||||||
|
}
|
||||||
|
|
||||||
(signoutRes.text).should.equal('You have successfully logged out.');
|
(signoutRes.text).should.equal('You have successfully logged out.');
|
||||||
|
|
||||||
|
@ -107,8 +108,8 @@ describe('User CRUD tests', function() {
|
||||||
afterEach(function(done) {
|
afterEach(function(done) {
|
||||||
User.remove().exec(function () {
|
User.remove().exec(function () {
|
||||||
tmpUser.remove().exec(function(){
|
tmpUser.remove().exec(function(){
|
||||||
userSession.destroy();
|
userSession.destroy();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue