diff --git a/app/libs/send-email-notifications.js b/app/libs/send-email-notifications.js index bbbc8548..158882e7 100644 --- a/app/libs/send-email-notifications.js +++ b/app/libs/send-email-notifications.js @@ -39,8 +39,8 @@ module.exports = { createFieldDict: function(form_fields){ var formFieldDict = {}; form_fields.forEach(function(field){ - if(field.hasOwnProperty('fieldValue')){ - formFieldDict[field.id] = String(field.fieldValue); + if(field.hasOwnProperty('fieldValue') && field.hasOwnProperty('_id')){ + formFieldDict[field._id] = String(field.fieldValue); } }); return formFieldDict; diff --git a/app/tests/form.server.routes.test.js b/app/tests/form.server.routes.test.js index fbdd1259..e55e35ea 100644 --- a/app/tests/form.server.routes.test.js +++ b/app/tests/form.server.routes.test.js @@ -10,7 +10,22 @@ var should = require('should'), Form = mongoose.model('Form'), Field = mongoose.model('Field'), FormSubmission = mongoose.model('FormSubmission'), - async = require('async'); + async = require('async'), + _ = require('lodash'); + +function omitDeep(collection, excludeKeys) { + + function omitFn(value) { + + if (value && typeof value === 'object') { + excludeKeys.forEach((key) => { + delete value[key]; + }); + } + } + + return _.cloneDeepWith(collection, omitFn); +} /** * Globals @@ -473,8 +488,6 @@ describe('Form Routes Unit tests', function() { .send({ form: formUpdateObject }) .expect(200) .end(function(err, OldForm) { - console.log(OldForm.body); - should.not.exist(err); Form.findById(InitialForm.id, function (FormFindErr, UpdatedForm){ @@ -484,8 +497,8 @@ describe('Form Routes Unit tests', function() { var updatedFormObj = UpdatedForm.toJSON(); var oldFormObj = InitialForm.toJSON(); - delete oldFormObj.lastModified; - delete updatedFormObj.lastModified; + updatedFormObj = omitDeep('lastModified'); + oldFormObj = omitDeep('lastModified'); updatedFormObj.should.deepEqual(oldFormObj); diff --git a/app/tests/form_submission.model.test.js b/app/tests/form_submission.model.test.js index 219f5d87..36935165 100644 --- a/app/tests/form_submission.model.test.js +++ b/app/tests/form_submission.model.test.js @@ -166,7 +166,7 @@ describe('FormSubmission Model Unit Tests:', function() { }); it('should be able to find FormSubmission by $elemMatch on form_fields id', function(done){ - FormSubmission.findOne({ form: myForm.id, form_fields: {$elemMatch: {id: myForm.form_fields[0].id} } }) + FormSubmission.findOne({ form: myForm.id, form_fields: {$elemMatch: {_id: myForm.form_fields[0]._id} } }) .exec(function(err, submission){ should.not.exist(err); should.exist(submission); diff --git a/app/tests/libs/send-email-notifications.test.js b/app/tests/libs/send-email-notifications.test.js index 38beb031..772328ee 100644 --- a/app/tests/libs/send-email-notifications.test.js +++ b/app/tests/libs/send-email-notifications.test.js @@ -14,9 +14,9 @@ const should = require('should'), * Globals */ const validFormFields = [ - {fieldType:'textfield', title:'First Name', fieldValue: 'John Smith', deletePreserved: false, id:'56340745f59a6fc9e22028e9'}, - {fieldType:'link', title:'Your Website', fieldValue: 'https://johnsmith.me', deletePreserved: false, id:'5c9e22028e907634f45f59a6'}, - {fieldType:'number', title:'Your Age', fieldValue: 45, deletePreserved: false, id:'56e90745f5934fc9e22028a6'} + {fieldType:'textfield', title:'First Name', fieldValue: 'John Smith', deletePreserved: false, _id:'56340745f59a6fc9e22028e9'}, + {fieldType:'link', title:'Your Website', fieldValue: 'https://johnsmith.me', deletePreserved: false, _id:'5c9e22028e907634f45f59a6'}, + {fieldType:'number', title:'Your Age', fieldValue: 45, deletePreserved: false, _id:'56e90745f5934fc9e22028a6'} ]; const validFieldDict = {