Added new form_route tests for update route
This commit is contained in:
parent
8c1964146f
commit
9d2a548dca
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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 = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user