fixed server tests

This commit is contained in:
David Baldwynn 2016-04-28 23:22:47 -07:00
parent 23834543b7
commit e33fdf2443
3 changed files with 20 additions and 20 deletions

View file

@ -303,7 +303,7 @@ exports.formByID = function(req, res, next, id) {
else { else {
Form.findById(id).populate('admin').exec(function(err, form) { Form.findById(id).populate('admin').exec(function(err, form) {
if (err) { if (err) {
return return next(err); return next(err);
} else if (form === undefined || form === null) { } else if (form === undefined || form === null) {
res.status(400).send({ res.status(400).send({
message: 'Form not found' message: 'Form not found'

View file

@ -241,7 +241,7 @@ function getDeletedIndexes(needle, haystack){
FormSchema.pre('save', function (next) { FormSchema.pre('save', function (next) {
var that = this; var that = this;
async.series([function(return cb) { async.series([function(cb) {
that.constructor that.constructor
.findOne({_id: that._id}).exec(function (err, original) { .findOne({_id: that._id}).exec(function (err, original) {
if (err) { if (err) {
@ -254,7 +254,7 @@ FormSchema.pre('save', function (next) {
return cb(null); return cb(null);
} }
}); });
}, function(return cb) { }, function(cb) {
//DAVID: TODO: Make this so we don't have to update the validFields property ever save //DAVID: TODO: Make this so we don't have to update the validFields property ever save
if (that.plugins.oscarhost.hasOwnProperty('baseUrl')) { if (that.plugins.oscarhost.hasOwnProperty('baseUrl')) {
var validUpdateTypes = mongoose.model('Form').schema.path('plugins.oscarhost.settings.updateType').enumValues; var validUpdateTypes = mongoose.model('Form').schema.path('plugins.oscarhost.settings.updateType').enumValues;
@ -262,10 +262,10 @@ FormSchema.pre('save', function (next) {
} }
return cb(null); return cb(null);
}, },
function(return cb) { function(cb) {
if (that.pdf) { if (that.pdf) {
async.series([ async.series([
function (return callback) { function (callback) {
if (that.isModified('pdf') && that.pdf.path) { if (that.isModified('pdf') && that.pdf.path) {
var new_filename = that.title.replace(/ /g, '') + '_template.pdf'; var new_filename = that.title.replace(/ /g, '') + '_template.pdf';
@ -279,7 +279,7 @@ FormSchema.pre('save', function (next) {
mkdirp.sync(newDestination); mkdirp.sync(newDestination);
} }
if (stat && !stat.isDirectory()) { if (stat && !stat.isDirectory()) {
return return callback(new Error('Directory cannot be created because an inode of a different type exists at "' + config.pdfUploadPath + '"'), null); return callback(new Error('Directory cannot be created because an inode of a different type exists at "' + config.pdfUploadPath + '"'), null);
} }
var old_path = that.pdf.path; var old_path = that.pdf.path;
@ -298,7 +298,7 @@ FormSchema.pre('save', function (next) {
return callback(null, 'task1'); return callback(null, 'task1');
} }
}, },
function (return callback) { function (callback) {
if (that.isGenerated) { if (that.isGenerated) {
that.pdf.path = config.pdfUploadPath + that.admin.username.replace(/ /g, '') + '/' + that.title.replace(/ /g, '') + '/' + that.title.replace(/ /g, '') + '_template.pdf'; that.pdf.path = config.pdfUploadPath + that.admin.username.replace(/ /g, '') + '/' + that.title.replace(/ /g, '') + '/' + that.title.replace(/ /g, '') + '_template.pdf';
that.pdf.name = that.title.replace(/ /g, '') + '_template.pdf'; that.pdf.name = that.title.replace(/ /g, '') + '_template.pdf';
@ -376,7 +376,7 @@ FormSchema.pre('save', function (next) {
} }
else return cb(); else return cb();
}, },
function(return cb) { function(cb) {
if(that.isModified('form_fields') && that.form_fields && _original){ if(that.isModified('form_fields') && that.form_fields && _original){
@ -391,7 +391,7 @@ FormSchema.pre('save', function (next) {
var modifiedSubmissions = []; var modifiedSubmissions = [];
async.forEachOfSeries(deletedIds, async.forEachOfSeries(deletedIds,
function (deletedIdIndex, key, return cb_id) { function (deletedIdIndex, key, cb_id) {
var deleted_id = old_ids[deletedIdIndex]; var deleted_id = old_ids[deletedIdIndex];
@ -420,7 +420,7 @@ FormSchema.pre('save', function (next) {
} else { } else {
//Iterate through all submissions with modified form_fields //Iterate through all submissions with modified form_fields
async.forEachOfSeries(modifiedSubmissions, function (submission, key, return callback) { async.forEachOfSeries(modifiedSubmissions, function (submission, key, callback) {
//Iterate through ids of deleted fields //Iterate through ids of deleted fields
for (var i = 0; i < deletedIds.length; i++) { for (var i = 0; i < deletedIds.length; i++) {

View file

@ -107,16 +107,16 @@ describe('FormSubmission Model Unit Tests:', function() {
{'fieldType':'radio', 'title':'And your sex', 'fieldOptions': [{ 'option_id': 0, 'option_title': 'Male', 'option_value': 'M' }, { 'option_id': 1, 'option_title': 'Female', 'option_value': 'F' }], 'fieldValue': ''}, {'fieldType':'radio', 'title':'And your sex', 'fieldOptions': [{ 'option_id': 0, 'option_title': 'Male', 'option_value': 'M' }, { 'option_id': 1, 'option_title': 'Female', 'option_value': 'F' }], 'fieldValue': ''},
{'fieldType':'date', 'title':'When were you born?', 'fieldValue': ''}, {'fieldType':'date', 'title':'When were you born?', 'fieldValue': ''},
{'fieldType':'number', 'title':'What\'s your phone #?', 'fieldValue': ''} {'fieldType':'number', 'title':'What\'s your phone #?', 'fieldValue': ''}
], ]
plugins: { // plugins: {
oscarhost: { // oscarhost: {
baseUrl: config.oscarhost.baseUrl, // baseUrl: config.oscarhost.baseUrl,
settings: { // settings: {
updateType: 'force_add' // updateType: 'force_add'
}, // },
auth: config.oscarhost.auth // auth: config.oscarhost.auth
} // }
} // }
}); });
myForm.save(function(err, form){ myForm.save(function(err, form){