2016-03-30 01:21:45 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var should = require('should'),
|
|
|
|
_ = require('lodash'),
|
|
|
|
app = require('../../server'),
|
|
|
|
request = require('supertest'),
|
|
|
|
Session = require('supertest-session'),
|
|
|
|
mongoose = require('mongoose'),
|
|
|
|
User = mongoose.model('User'),
|
|
|
|
config = require('../../config/config'),
|
2017-04-21 04:50:15 +00:00
|
|
|
tmpUser = mongoose.model(config.tempUserCollection);
|
2016-03-30 01:21:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Globals
|
|
|
|
*/
|
2016-03-30 03:45:16 +00:00
|
|
|
var credentials, _User;
|
|
|
|
var _tmpUser, activateToken;
|
|
|
|
var username, userSession;
|
|
|
|
|
|
|
|
username = 'testActiveAccount1.be1e58fb@mailosaur.in';
|
|
|
|
|
2016-03-30 01:21:45 +00:00
|
|
|
/**
|
|
|
|
* Form routes tests
|
|
|
|
*/
|
|
|
|
describe('User CRUD tests', function() {
|
2016-04-21 17:56:54 +00:00
|
|
|
this.timeout(30000);
|
2016-03-30 01:21:45 +00:00
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
// Create user credentials
|
|
|
|
credentials = {
|
2016-11-09 20:25:38 +00:00
|
|
|
email: 'test732@test.com',
|
|
|
|
username: 'test732',
|
|
|
|
password: 'password3223'
|
2016-03-30 01:21:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//Create a new user
|
|
|
|
_User = {
|
2016-11-09 20:25:38 +00:00
|
|
|
email: credentials.email,
|
2016-03-30 01:21:45 +00:00
|
|
|
username: credentials.username,
|
2017-04-23 19:46:15 +00:00
|
|
|
password: credentials.password
|
2016-03-30 01:21:45 +00:00
|
|
|
};
|
2016-11-09 20:25:38 +00:00
|
|
|
|
2016-04-21 17:56:54 +00:00
|
|
|
//Initialize Session
|
2016-11-09 20:25:38 +00:00
|
|
|
userSession = Session(app);
|
2016-03-30 01:21:45 +00:00
|
|
|
});
|
|
|
|
|
2016-11-09 20:25:38 +00:00
|
|
|
it(' > Create, Verify and Activate a User > ', function() {
|
2016-03-30 01:21:45 +00:00
|
|
|
|
|
|
|
it('should be able to create a temporary (non-activated) User', function(done) {
|
|
|
|
userSession.post('/auth/signup')
|
|
|
|
.send(_User)
|
2016-03-30 03:45:16 +00:00
|
|
|
.expect(200)
|
2016-03-30 01:21:45 +00:00
|
|
|
.end(function(FormSaveErr, FormSaveRes) {
|
2016-11-09 20:25:38 +00:00
|
|
|
console.log('CREATING USER');
|
2016-03-30 01:21:45 +00:00
|
|
|
// Handle error
|
2016-03-30 03:45:16 +00:00
|
|
|
should.not.exist(FormSaveErr);
|
2016-11-09 20:25:38 +00:00
|
|
|
|
2016-04-21 17:56:54 +00:00
|
|
|
tmpUser.findOne({username: _User.username}, function (err, user) {
|
|
|
|
should.not.exist(err);
|
|
|
|
should.exist(user);
|
|
|
|
_tmpUser = user;
|
|
|
|
|
|
|
|
_User.username.should.equal(user.username);
|
|
|
|
_User.firstName.should.equal(user.firstName);
|
|
|
|
_User.lastName.should.equal(user.lastName);
|
|
|
|
activateToken = user.GENERATED_VERIFYING_URL;
|
2016-11-09 20:25:38 +00:00
|
|
|
|
2016-04-21 17:56:54 +00:00
|
|
|
userSession.get('/auth/verify/'+activateToken)
|
|
|
|
.expect(200)
|
|
|
|
.end(function(VerifyErr, VerifyRes) {
|
|
|
|
// Handle error
|
|
|
|
if (VerifyErr) return done(VerifyErr);
|
|
|
|
(VerifyRes.text).should.equal('User successfully verified');
|
2016-11-09 20:25:38 +00:00
|
|
|
|
2016-04-21 17:56:54 +00:00
|
|
|
userSession.post('/auth/signin')
|
|
|
|
.send(credentials)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
|
|
|
.end(function(signinErr, signinRes) {
|
|
|
|
// Handle signin error
|
|
|
|
if (signinErr) return done(signinErr);
|
|
|
|
|
|
|
|
var user = signinRes.body;
|
|
|
|
(user.username).should.equal(credentials.username);
|
|
|
|
|
|
|
|
userSession.get('/auth/signout')
|
|
|
|
.expect(200)
|
|
|
|
.end(function(signoutErr, signoutRes) {
|
|
|
|
|
|
|
|
// Handle signout error
|
|
|
|
if (signoutErr) return done(signoutErr);
|
|
|
|
|
|
|
|
(signoutRes.text).should.equal('You have successfully logged out.');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-03-30 01:21:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-04-21 17:56:54 +00:00
|
|
|
});
|
2017-04-23 19:46:15 +00:00
|
|
|
|
2016-03-30 01:21:45 +00:00
|
|
|
afterEach(function(done) {
|
|
|
|
User.remove().exec(function () {
|
|
|
|
tmpUser.remove().exec(function(){
|
2016-04-21 17:56:54 +00:00
|
|
|
userSession.destroy();
|
|
|
|
done();
|
2016-03-30 01:21:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|