'use strict';
/**
* Module dependencies.
*/
var should = require('should'),
mongoose = require('mongoose'),
User = mongoose.model('User'),
Form = mongoose.model('Form'),
Field = mongoose.model('Field'),
_ = require('lodash'),
config = require('../../config/config'),
FormSubmission = mongoose.model('FormSubmission');
var exampleDemo = {
activeCount: 1,
unparsedDOB: '',
address: '880-9650 Velit. St.',
chartNo: '',
city: '',
dateJoined: Date.now(),
dateOfBirth: '10',
displayName: 'LITTLE, URIAH',
email: '',
familyDoctor: '',
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
*/
var user, myForm, mySubmission;
/**
* Unit tests
*/
describe('FormSubmission Model Unit Tests:', function() {
beforeEach(function(done) {
user = new User({
firstName: 'Full',
lastName: 'Name',
displayName: 'Full Name',
email: 'test1@test.com',
username: 'test1@test.com',
password: 'password'
});
user.save(function(err, _user) {
if(err) done(err);
myForm = new Form({
title: 'Form Title',
admin: _user,
language: 'english',
form_fields: [
{'fieldType':'textfield', 'title':'What\'s your first name', 'fieldValue': ''},
{'fieldType':'textfield', 'title':'And your last name', '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':'number', 'title':'What\'s your phone #?', 'fieldValue': ''},
],
plugins: {
oscarhost: {
baseUrl: config.oscarhost.baseUrl,
settings: {
lookupField: '',
updateType: 'force_add',
},
auth: config.oscarhost.auth,
}
}
});
done();
});
});
describe('Method Save', function() {
var myFieldMap = {};
beforeEach(function(done){
myFieldMap[myForm.form_fields[0]._id+''] = 'firstName';
myFieldMap[myForm.form_fields[1]._id+''] = 'lastName';
myFieldMap[myForm.form_fields[2]._id+''] = 'sex';
myFieldMap[myForm.form_fields[3]._id+''] = 'unparsedDOB';
myFieldMap[myForm.form_fields[4]._id+''] = 'phone';
myForm.plugins.oscarhost.settings.fieldMap = myFieldMap;
myForm.save(function(err, form){
if(err) done(err);
// var submission_fields = _.cloneDeep(form.toObject().form_fields);
// var submission_fields = [
// {'fieldType':'textfield', 'title':'What\'s your first name', 'fieldValue': ''},
// {'fieldType':'textfield', 'title':'And your last name', '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':'number', 'title':'What\'s your phone #?', 'fieldValue': ''}
// ];
submission_fields[0].fieldValue = 'David';
submission_fields[1].fieldValue = 'Baldwynn'+Date.now();
submission_fields[2].fieldValue = 'M';
submission_fields[3].fieldValue = Date.now();
submission_fields[4].fieldValue = 6043158008;
mySubmission = new FormSubmission({
admin: user,
form: form,
timeElapsed: 17.55
});
// for(var i=0; i