got tests to run

This commit is contained in:
David Baldwynn 2016-11-09 12:25:38 -08:00
parent a1a6d0fdd5
commit 3e4028117d
11 changed files with 53 additions and 157 deletions

View file

@ -152,7 +152,6 @@ exports.read = function(req, res) {
var newForm = req.form.toJSON();
console.log(newForm.analytics);
newForm.submissions = _submissions;
if (req.userId) {

View file

@ -101,7 +101,6 @@ exports.resendVerificationEmail = function(req, res, next){
* Signup
*/
exports.signup = function(req, res) {
debugger;
// For security measures we remove the roles from the req.body object
delete req.body.roles;
@ -114,7 +113,6 @@ exports.signup = function(req, res) {
// Then save the temporary user
nev.createTempUser(user, function (err, existingPersistentUser, newTempUser) {
debugger;
if (err) {
console.log('Error: ');
console.log(err);
@ -128,8 +126,7 @@ exports.signup = function(req, res) {
var URL = newTempUser[nev.options.URLFieldName];
nev.sendVerificationEmail(user.email, URL, function (err, info) {
if (err) {
console.log('Error: ');
console.log(err);
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});

View file

@ -78,9 +78,6 @@ var VisitorDataSchema = new Schema({
});
var formSchemaOptions = {
toObject: {
virtuals: true
},
toJSON: {
virtuals: true
}

View file

@ -21,7 +21,6 @@ function formFieldsSetter(form_fields) {
form_fields[i].submissionId = form_fields[i]._id;
form_fields[i]._id = new mongoose.mongo.ObjectID();
}
console.log(form_fields)
return form_fields;
}
@ -103,7 +102,6 @@ FormSubmissionSchema.path('form_fields', {
form_fields[i].submissionId = form_fields[i]._id;
form_fields[i]._id = new mongoose.mongo.ObjectID();
}
console.log(form_fields);
return form_fields;
}
});

View file

@ -38,6 +38,14 @@ var validateLocalStrategyPassword = function(password) {
return (this.provider !== 'local' || (password && password.length > 6));
};
/**
* A Validation function for username
*/
var validateUsername = function(username) {
return (username.match(/^[a-zA-Z0-9]+$/) !== null);
};
/**
* User Schema
*/
@ -74,9 +82,12 @@ var UserSchema = new Schema({
username: {
type: String,
unique: true,
required: false,
required: true,
lowercase: true,
trim: true
validate: {
validator: validateUsername,
message: 'Please use a valid username'
}
},
passwordHash: {
type: String,
@ -139,50 +150,8 @@ UserSchema.plugin(mUtilities.timestamp, {
useVirtual: false
});
/*
UserSchema.pre('find', function (next) {
//Change username if it is still the user's email
if (this.username === this.email) {
var emailUsername = this.email.split('@')[0];
this.username = querystring.stringify({query: emailUsername});
var mailOptions = {
from: '"TellForm Support" <noreply@tellform.com>', // sender address
to: this.email, // list of receivers
subject: 'Your TellForm Username has Changed', // Subject line
text: 'Due to upgrades, your TellForm username has change from ' + this.email + ' to ' + this.username + '. Please use your new username to login.\n Using your old username will not work.\n We apologize for the inconvenience,\n - the TellForm team', // plaintext body
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
return console.error(error);
}
console.log('Username change message sent: ' + info.response);
});
}
});*/
UserSchema.pre('save', function (next) {
//Change username if it is still the user's email
if(this.username === this.email){
var emailUsername = this.email.split('@')[0];
this.username = querystring.stringify({ query: emailUsername });
var mailOptions = {
from: '"TellForm Support" <noreply@tellform.com>', // sender address
to: this.email, // list of receivers
subject: 'Your TellForm Username has Changed', // Subject line
text: 'Due to upgrades, your TellForm username has change from ' + this.email + ' to ' + this.username + '. Please use your new username to login.\n Using your old username will not work.\n We apologize for the inconvenience,\n - the TellForm team', // plaintext body
};
smtpTransport.sendMail(mailOptions, function(error, info){
if(error){
return console.error(error);
}
console.log('Username change message sent: ' + info.response);
});
}
//Create folder for user's pdfs
if(process.env.NODE_ENV === 'local-development'){
var newDestination = path.join(config.pdfUploadPath, this.username.replace(/ /g,'')),

View file

@ -12,43 +12,6 @@ var should = require('should'),
config = require('../../config/config'),
FormSubmission = mongoose.model('FormSubmission');
var exampleDemo = {
activeCount: 1,
DOB: '',
address: '880-9650 Velit. St.',
chartNo: '',
city: '',
dateJoined: Date.now(),
dateOfBirth: '10',
displayName: 'LITTLE, URIAH',
email: '',
familyDoctor: '<rdohip></rdohip><rd></rd>',
firstName: 'Uriah F.',
hcType: 'BC',
hin: '',
hsAlertCount: 0,
lastName: 'Little',
lastUpdateDate: Date.now(),
lastUpdateUser: '',
links: '',
monthOfBirth: '05',
officialLanguage: 'English',
patientStatus: 'AC',
patientStatusDate: Date.now(),
phone: '250-',
phone2: '',
postal: 'S4M 7T8',
providerNo: '4',
province: 'BC',
rosterStatus: '',
sex: 'M',
sexDesc: 'Female',
sin: '',
spokenLanguage: 'English',
title: 'MS.',
yearOfBirth: '2015'
};
/**
* Globals
*/
@ -63,7 +26,6 @@ describe('Form Model Unit Tests:', function() {
user = new User({
firstName: 'Full',
lastName: 'Name',
displayName: 'Full Name',
email: 'test@test.com',
username: 'aueoaueoa',
password: 'password',
@ -78,7 +40,7 @@ describe('Form Model Unit Tests:', function() {
myForm = new Form({
title: 'Form Title',
admin: user,
language: 'english',
language: 'en',
form_fields: [
{'fieldType':'textfield', title:'First Name', 'fieldValue': ''},
{'fieldType':'checkbox', title:'nascar', 'fieldValue': ''},
@ -91,7 +53,7 @@ describe('Form Model Unit Tests:', function() {
describe('Method Save', function() {
it('should be able to save without problems', function(done) {
return myForm.save(function(err) {
myForm.save(function(err) {
should.not.exist(err);
done();
});
@ -102,7 +64,7 @@ describe('Form Model Unit Tests:', function() {
var _form = myForm;
_form.title = '';
return _form.save(function(err) {
_form.save(function(err) {
should.exist(err);
should.equal(err.errors.title.message, 'Form Title cannot be blank');
done();
@ -118,10 +80,11 @@ describe('Form Model Unit Tests:', function() {
});
});
it('should be able to findOne my form without problems', function(done) {
return Form.findOne({title: myForm.title}).exec(function(err,form) {
Form.findOne({title: myForm.title}).exec(function(err,form) {
should.not.exist(err);
should.exist(form);
should.deepEqual(form.toObject(), myForm.toObject());
should.equal(form.toObject().id, myForm.toObject().id);
done();
});
});

View file

@ -11,22 +11,21 @@ var should = require('should'),
Field = mongoose.model('Field'),
FormSubmission = mongoose.model('FormSubmission');
/**
* Globals
*/
var credentials, user, myForm, userSession;
/**
* Form routes tests
*/
describe('Form Routes Unit tests', function() {
/**
* Globals
*/
//this.timeout(15000);
var credentials, user, myForm, userSession;
beforeEach(function(done) {
// Create user credentials
credentials = {
username: 'test@test.com',
username: 'test',
email: 'test@test.com',
password: 'password'
};
@ -36,7 +35,7 @@ describe('Form Routes Unit tests', function() {
firstName: 'Full',
lastName: 'Name',
displayName: 'Full Name',
email: 'test@test.com',
email: credentials.email,
username: credentials.username,
password: credentials.password,
provider: 'local'
@ -47,7 +46,7 @@ describe('Form Routes Unit tests', function() {
should.not.exist(err);
myForm = {
title: 'Form Title',
language: 'english',
language: 'en',
admin: user.id,
form_fields: [
new Field({'fieldType':'textfield', 'title':'First Name', 'fieldValue': ''}),
@ -55,7 +54,7 @@ describe('Form Routes Unit tests', function() {
new Field({'fieldType':'checkbox', 'title':'hockey', 'fieldValue': ''})
]
};
//Initialize Session
userSession = Session(app);
@ -90,7 +89,6 @@ describe('Form Routes Unit tests', function() {
.expect('Content-Type', /json/)
.expect(200)
.end(function(FormsGetErr, FormsGetRes) {
console.log('get forms');
// Handle Form save error
if (FormsGetErr) return done(FormsGetErr);
@ -115,7 +113,6 @@ describe('Form Routes Unit tests', function() {
.send({form: myForm})
.expect(401)
.end(function(FormSaveErr, FormSaveRes) {
(FormSaveRes.body.message).should.equal('User is not logged in');
// Call the assertion callback
done(FormSaveErr);
});
@ -125,7 +122,6 @@ describe('Form Routes Unit tests', function() {
userSession.get('/forms')
.expect(401)
.end(function(FormSaveErr, FormSaveRes) {
(FormSaveRes.body.message).should.equal('User is not logged in');
// Call the assertion callback
done(FormSaveErr);
});
@ -272,8 +268,6 @@ describe('Form Routes Unit tests', function() {
userSession.delete('/forms/' + FormObj._id)
.expect(401)
.end(function(FormDeleteErr, FormDeleteRes) {
// Set message assertion
(FormDeleteRes.body.message).should.match('User is not logged in');
// Handle Form error error
done(FormDeleteErr);

View file

@ -84,21 +84,20 @@ describe('FormSubmission Model Unit Tests:', function() {
lastName: 'Name',
displayName: 'Full Name',
email: 'test1@test.com'+Date.now(),
username: 'test1@test.com'+Date.now(),
username: 'test1'+Date.now(),
password: 'password',
provider: 'local'
});
user.save(function(err) {
if(err){
console.log(err.errors);
done(err);
return;
}
myForm = new Form({
title: 'Form Title1',
admin: user._id,
language: 'english',
language: 'en',
form_fields: [
{'fieldType':'textfield', 'title':'What\'s your first name', 'fieldValue': ''},
{'fieldType':'textfield', 'title':'And your last name', 'fieldValue': ''},
@ -106,15 +105,6 @@ describe('FormSubmission Model Unit Tests:', function() {
{'fieldType':'date', 'title':'When were you born?', 'fieldValue': ''},
{'fieldType':'number', 'title':'What\'s your phone #?', 'fieldValue': ''}
]
// plugins: {
// oscarhost: {
// baseUrl: config.oscarhost.baseUrl,
// settings: {
// updateType: 'force_add'
// },
// auth: config.oscarhost.auth
// }
// }
});
myForm.save(function(err, form){
@ -156,11 +146,9 @@ describe('FormSubmission Model Unit Tests:', function() {
});
it('should be able to save a FormSubmission without problems', function(done) {
return mySubmission.save(function(err, submission) {
mySubmission.save(function(err, submission) {
should.not.exist(err);
should.exist(submission);
// should.exist(submission.oscarDemoNum);
// oscar_demo_num = submission.oscarDemoNum;
done();
});
@ -174,7 +162,7 @@ describe('FormSubmission Model Unit Tests:', function() {
});
});
it('should be able to findOne FormSubmission without problems', function(done) {
return FormSubmission.findOne({_id: mySubmission._id}).exec(function(err,submission) {
FormSubmission.findOne({_id: mySubmission._id}).exec(function(err,submission) {
should.not.exist(err);
should.exist(submission);
should.deepEqual(submission.toObject(), mySubmission.toObject());
@ -183,7 +171,7 @@ describe('FormSubmission Model Unit Tests:', function() {
});
it('should be able to find FormSubmission by $elemMatch on form_fields id', function(done){
return FormSubmission.findOne({ form: myForm._id, admin: user, form_fields: {$elemMatch: {_id: myForm.form_fields[0]._id} } })
FormSubmission.findOne({ form: myForm._id, admin: user, form_fields: {$elemMatch: {_id: myForm.form_fields[0]._id} } })
.exec(function(err, submission){
should.not.exist(err);
should.exist(submission);

View file

@ -28,7 +28,7 @@ describe('Form Submission Routes Unit tests', function() {
// Create user credentials
credentials = {
email: 'test@test.com',
username: 'test@test.com',
username: 'test',
password: 'password'
};
@ -36,7 +36,7 @@ describe('Form Submission Routes Unit tests', function() {
user = new User({
firstName: 'Full',
lastName: 'Name',
email: 'test@test.com',
email: credentials.email,
username: credentials.username,
password: credentials.password,
provider: 'local'
@ -47,7 +47,7 @@ describe('Form Submission Routes Unit tests', function() {
if(err) return done(err);
FormObj = new Form({
title: 'Form Title',
language: 'english',
language: 'en',
admin: user._id,
form_fields: [
new Field({'fieldType':'textfield', 'title':'First Name', 'fieldValue': ''}),
@ -170,9 +170,6 @@ describe('Form Submission Routes Unit tests', function() {
.end(function(err, res) {
should.not.exist(err);
// Set assertions
(res.body.message).should.equal('User is not logged in');
// Call the assertion callback
done();
});
@ -195,7 +192,6 @@ describe('Form Submission Routes Unit tests', function() {
// Set assertions
should.not.exist(err);
(res.body.message).should.equal('User is not logged in');
// Call the assertion callback
done();

View file

@ -20,16 +20,16 @@ describe('User Model Unit Tests:', function() {
user = new User({
firstName: 'Full',
lastName: 'Name',
username: 'test',
email: 'test@test.com',
username: 'test@test.com',
password: 'password',
provider: 'local'
});
user2 = new User({
firstName: 'Full',
lastName: 'Name',
username: 'test',
email: 'test@test.com',
username: 'test@test.com',
password: 'password',
provider: 'local'
});
@ -54,13 +54,13 @@ describe('User Model Unit Tests:', function() {
user2.save(function(err) {
should.exist(err);
done();
});
});
});
});
it('should be able to show an error when try to save without first name', function(done) {
user.firstName = '';
return user.save(function(err) {
it('should be able to show an error when try to save without username', function(done) {
user.username = '';
user.save(function(err) {
should.exist(err);
done();
});

View file

@ -29,35 +29,33 @@ describe('User CRUD tests', function() {
beforeEach(function() {
// Create user credentials
credentials = {
username: 'test7@test.com',
password: 'password'
email: 'test732@test.com',
username: 'test732',
password: 'password3223'
};
//Create a new user
_User = {
firstName: 'Full',
lastName: 'Name',
email: credentials.username,
email: credentials.email,
username: credentials.username,
password: credentials.password,
provider: 'local'
};
//Initialize Session
userSession = Session(app);
userSession = Session(app);
});
describe(' > Create, Verify and Activate a User > ', function() {
//this.timeout(15000);
it(' > Create, Verify and Activate a User > ', function() {
it('should be able to create a temporary (non-activated) User', function(done) {
userSession.post('/auth/signup')
.send(_User)
.expect(200)
.end(function(FormSaveErr, FormSaveRes) {
console.log('CREATING USER');
// Handle error
should.not.exist(FormSaveErr);
tmpUser.findOne({username: _User.username}, function (err, user) {
should.not.exist(err);
should.exist(user);
@ -67,15 +65,14 @@ describe('User CRUD tests', function() {
_User.firstName.should.equal(user.firstName);
_User.lastName.should.equal(user.lastName);
activateToken = user.GENERATED_VERIFYING_URL;
console.log('activateToken: '+activateToken);
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');
userSession.post('/auth/signin')
.send(credentials)
.expect('Content-Type', /json/)
@ -108,8 +105,6 @@ describe('User CRUD tests', function() {
it(' > should be able to reset a User\'s password');
it(' > should be able to delete a User account without any problems');
afterEach(function(done) {
User.remove().exec(function () {
tmpUser.remove().exec(function(){