diff --git a/app/tests/form.server.routes.test.js b/app/tests/form.server.routes.test.js index 2560132f..8c31212e 100644 --- a/app/tests/form.server.routes.test.js +++ b/app/tests/form.server.routes.test.js @@ -62,86 +62,86 @@ describe('Form Routes Unit tests', function() { }); }); - // describe(' > Login and Save a new Form >', function() { - // var lodashuser, lodashform; - // before(function(done){ - // userSession.post('/auth/signin') - // .send(credentials) - // .expect('Content-Type', /json/) - // .expect(200, 'Could not login user') - // .end(function(signinErr, signinRes) { + describe(' > Login and Save a new Form >', function() { + var lodashuser, lodashform; + before(function(done){ + userSession.post('/auth/signin') + .send(credentials) + .expect('Content-Type', /json/) + .expect(200, 'Could not login user') + .end(function(signinErr, signinRes) { - // // Handle signin error - // if (signinErr) return done(signinErr); + // Handle signin error + if (signinErr) return done(signinErr); - // lodashuser = signinRes.body; - // done(); - // }); - // }); - // it(' > should be able to save a Form as a user', function(done){ - // // Save a new Form - // userSession.post('/forms') - // .send({form: myForm}) - // .expect('Content-Type', /json/) - // .expect(200, 'Could not save new Form') - // .end(function(FormSaveErr, FormSaveRes) { - // // Handle Form save error - // if (FormSaveErr) return done(FormSaveErr); - // lodashform = FormSaveRes.body; - // done(); - // }); - // }); - // it(' > should be able to fetch newly created form', function(done){ + lodashuser = signinRes.body; + done(); + }); + }); + it(' > should be able to save a Form as a user', function(done){ + // Save a new Form + userSession.post('/forms') + .send({form: myForm}) + .expect('Content-Type', /json/) + .expect(200, 'Could not save new Form') + .end(function(FormSaveErr, FormSaveRes) { + // Handle Form save error + if (FormSaveErr) return done(FormSaveErr); + lodashform = FormSaveRes.body; + done(); + }); + }); + it(' > should be able to fetch newly created form', function(done){ - // // Get a list of Forms - // userSession.get('/forms/'+lodashform.lodashid) - // .expect('Content-Type', /json/) - // .expect(200) - // .end(function(FormsGetErr, FormsGetRes) { - // // Handle Form save error - // if (FormsGetErr) return done(FormsGetErr); + // Get a list of Forms + userSession.get('/forms/'+lodashform.lodashid) + .expect('Content-Type', /json/) + .expect(200) + .end(function(FormsGetErr, FormsGetRes) { + // Handle Form save error + if (FormsGetErr) return done(FormsGetErr); - // var fetchedForm = FormsGetRes.body; - // // Set assertions - // (fetchedForm.admin).should.equal(lodashuser.lodashid); - // (fetchedForm.title).should.match(lodashform.title); + var fetchedForm = FormsGetRes.body; + // Set assertions + (fetchedForm.admin).should.equal(lodashuser.lodashid); + (fetchedForm.title).should.match(lodashform.title); - // // Call the assertion callback - // done(); - // }); - // }); - // after(function(done){ - // userSession.get('/auth/signout') - // .end(function(signoutErr, signoutRes) { + // Call the assertion callback + done(); + }); + }); + after(function(done){ + userSession.get('/auth/signout') + .end(function(signoutErr, signoutRes) { - // // Handle signout error - // if (signoutErr) return done(signoutErr); - // userSession.destroy(); - // done(); - // }); - // }); - // }); + // Handle signout error + if (signoutErr) return done(signoutErr); + userSession.destroy(); + done(); + }); + }); + }); - // it(' > should not be able to create a Form if not logged in', function(done) { - // agent.post('/forms') - // .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); - // }); - // }); + it(' > should not be able to create a Form if not logged in', function(done) { + agent.post('/forms') + .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); + }); + }); - // it(' > should not be able to get list of users\' Forms if not logged in', function(done) { - // agent.get('/forms') - // .expect(401) - // .end(function(FormSaveErr, FormSaveRes) { - // (FormSaveRes.body.message).should.equal('User is not logged in'); - // // Call the assertion callback - // done(FormSaveErr); - // }); - // }); + it(' > should not be able to get list of users\' Forms if not logged in', function(done) { + agent.get('/forms') + .expect(401) + .end(function(FormSaveErr, FormSaveRes) { + (FormSaveRes.body.message).should.equal('User is not logged in'); + // Call the assertion callback + done(FormSaveErr); + }); + }); it(' > should not be able to save a Form if no title is provided', function(done) { // Set Form with a invalid title field @@ -173,178 +173,178 @@ describe('Form Routes Unit tests', function() { }); }); - // it(' > should be able to update a Form if signed in', function(done) { - // userSession.post('/auth/signin') - // .send(credentials) - // .expect('Content-Type', /json/) - // .expect(200) - // .end(function(signinErr, signinRes) { - // // Handle signin error - // if (signinErr) return done(signinErr); + it(' > should be able to update a Form if signed in', function(done) { + userSession.post('/auth/signin') + .send(credentials) + .expect('Content-Type', /json/) + .expect(200) + .end(function(signinErr, signinRes) { + // Handle signin error + if (signinErr) return done(signinErr); - // // Save a new Form - // userSession.post('/forms') - // .send({form: myForm}) - // .expect('Content-Type', /json/) - // .expect(200) - // .end(function(FormSaveErr, FormSaveRes) { - // // Handle Form save error - // if (FormSaveErr) return done(FormSaveErr); + // Save a new Form + userSession.post('/forms') + .send({form: myForm}) + .expect('Content-Type', /json/) + .expect(200) + .end(function(FormSaveErr, FormSaveRes) { + // Handle Form save error + if (FormSaveErr) return done(FormSaveErr); - // // Update Form title - // myForm.title = 'WHY YOU GOTTA BE SO MEAN?'; + // Update Form title + myForm.title = 'WHY YOU GOTTA BE SO MEAN?'; - // // Update an existing Form - // userSession.put('/forms/' + FormSaveRes.body.lodashid) - // .send({form: myForm}) - // .expect('Content-Type', /json/) - // .expect(200) - // .end(function(FormUpdateErr, FormUpdateRes) { - // // Handle Form update error - // if (FormUpdateErr) done(FormUpdateErr); + // Update an existing Form + userSession.put('/forms/' + FormSaveRes.body.lodashid) + .send({form: myForm}) + .expect('Content-Type', /json/) + .expect(200) + .end(function(FormUpdateErr, FormUpdateRes) { + // Handle Form update error + if (FormUpdateErr) done(FormUpdateErr); - // // Set assertions - // (FormUpdateRes.body.lodashid).should.equal(FormSaveRes.body.lodashid); - // (FormUpdateRes.body.title).should.match('WHY YOU GOTTA BE SO MEAN?'); + // Set assertions + (FormUpdateRes.body.lodashid).should.equal(FormSaveRes.body.lodashid); + (FormUpdateRes.body.title).should.match('WHY YOU GOTTA BE SO MEAN?'); - // // Call the assertion callback - // done(); - // }); - // }); - // }); - // }); + // Call the assertion callback + done(); + }); + }); + }); + }); - // it(' > should be able to read/get a Form if not signed in', function(done) { - // // Create new Form model instance - // var FormObj = new Form(myForm); + it(' > should be able to read/get a Form if not signed in', function(done) { + // Create new Form model instance + var FormObj = new Form(myForm); - // // Save the Form - // FormObj.save(function(err, form) { - // if(err) return done(err); + // Save the Form + FormObj.save(function(err, form) { + if(err) return done(err); - // agent.get('/forms/' + form.lodashid) - // .expect('Content-Type', /json/) - // .expect(200) - // .end(function(err, res) { - // if(err) return done(err) + agent.get('/forms/' + form.lodashid) + .expect('Content-Type', /json/) + .expect(200) + .end(function(err, res) { + if(err) return done(err) - // // Set assertion - // (res.body).should.be.an.Object.with.property('title', myForm.title); + // Set assertion + (res.body).should.be.an.Object.with.property('title', myForm.title); - // // Call the assertion callback - // done(); - // }); - // }); - // }); + // Call the assertion callback + done(); + }); + }); + }); - // it(' > should be able to delete a Form if signed in', function(done) { + it(' > should be able to delete a Form if signed in', function(done) { - // userSession.post('/auth/signin') - // .send(credentials) - // .expect('Content-Type', /json/) - // .expect(200) - // .end(function(signinErr, signinRes) { - // // Handle signin error - // if (signinErr) return done(signinErr); + userSession.post('/auth/signin') + .send(credentials) + .expect('Content-Type', /json/) + .expect(200) + .end(function(signinErr, signinRes) { + // Handle signin error + if (signinErr) return done(signinErr); - // // Save a new Form - // userSession.post('/forms') - // .send({form: myForm}) - // .expect('Content-Type', /json/) - // .expect(200) - // .end(function(FormSaveErr, FormSaveRes) { - // // Handle Form save error - // if (FormSaveErr) return done(FormSaveErr); + // Save a new Form + userSession.post('/forms') + .send({form: myForm}) + .expect('Content-Type', /json/) + .expect(200) + .end(function(FormSaveErr, FormSaveRes) { + // Handle Form save error + if (FormSaveErr) return done(FormSaveErr); - // // Delete an existing Form - // userSession.delete('/forms/' + FormSaveRes.body.lodashid) - // .send(myForm) - // .expect('Content-Type', /json/) - // .expect(200) - // .end(function(FormDeleteErr, FormDeleteRes) { - // // Handle Form error error - // if (FormDeleteErr) return done(FormDeleteErr); + // Delete an existing Form + userSession.delete('/forms/' + FormSaveRes.body.lodashid) + .send(myForm) + .expect('Content-Type', /json/) + .expect(200) + .end(function(FormDeleteErr, FormDeleteRes) { + // Handle Form error error + if (FormDeleteErr) return done(FormDeleteErr); - // // Set assertions - // (FormDeleteRes.body).should.exist(); - // // (FormDeleteRes.body.lodashid).should.equal(FormSaveRes.body.lodashid); + // Set assertions + (FormDeleteRes.body).should.exist(); + // (FormDeleteRes.body.lodashid).should.equal(FormSaveRes.body.lodashid); - // // Call the assertion callback - // done(); - // }); - // }); + // Call the assertion callback + done(); + }); + }); - // }); - // }); + }); + }); - // it(' > should not be able to delete an Form if not signed in', function(done) { - // // Set Form user - // myForm.admin = user; + it(' > should not be able to delete an Form if not signed in', function(done) { + // Set Form user + myForm.admin = user; - // // Create new Form model instance - // var FormObj = new Form(myForm); + // Create new Form model instance + var FormObj = new Form(myForm); - // // Save the Form - // FormObj.save(function() { - // // Try deleting Form - // agent.delete('/forms/' + FormObj.lodashid) - // .expect(401) - // .end(function(FormDeleteErr, FormDeleteRes) { - // // Set message assertion - // (FormDeleteRes.body.message).should.match('User is not logged in'); + // Save the Form + FormObj.save(function() { + // Try deleting Form + agent.delete('/forms/' + FormObj.lodashid) + .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); - // }); + // Handle Form error error + done(FormDeleteErr); + }); - // }); - // }); + }); + }); - // it(' > should be able to upload a PDF an Form if logged in', function(done) { - // userSession.post('/auth/signin') - // .send(credentials) - // .expect('Content-Type', /json/) - // .expect(200) - // .end(function(signinErr, signinRes) { + it(' > should be able to upload a PDF an Form if logged in', function(done) { + userSession.post('/auth/signin') + .send(credentials) + .expect('Content-Type', /json/) + .expect(200) + .end(function(signinErr, signinRes) { - // // Handle signin error - // if (signinErr) return done(signinErr); + // Handle signin error + if (signinErr) return done(signinErr); - // var user = signinRes.body; - // var userId = user.lodashid; + var user = signinRes.body; + var userId = user.lodashid; - // // Save a new Form - // userSession.post('/forms') - // .send({form: myForm}) - // .expect('Content-Type', /json/) - // .expect(200) - // .end(function(FormSaveErr, FormSaveRes) { - // // Handle Form save error - // if (FormSaveErr) return done(FormSaveErr); + // Save a new Form + userSession.post('/forms') + .send({form: myForm}) + .expect('Content-Type', /json/) + .expect(200) + .end(function(FormSaveErr, FormSaveRes) { + // Handle Form save error + if (FormSaveErr) return done(FormSaveErr); - // // Get a list of Forms - // userSession.get('/forms') - // .expect('Content-Type', /json/) - // .expect(200) - // .end(function(FormsGetErr, FormsGetRes) { - // // Handle Form save error - // if (FormsGetErr) return done(FormsGetErr); + // Get a list of Forms + userSession.get('/forms') + .expect('Content-Type', /json/) + .expect(200) + .end(function(FormsGetErr, FormsGetRes) { + // Handle Form save error + if (FormsGetErr) return done(FormsGetErr); - // // Get Forms list - // var Forms = FormsGetRes.body; + // Get Forms list + var Forms = FormsGetRes.body; - // // Set assertions - // (Forms[0].admin).should.equal(userId); - // (Forms[0].title).should.match('Form Title'); + // Set assertions + (Forms[0].admin).should.equal(userId); + (Forms[0].title).should.match('Form Title'); - // // Call the assertion callback - // done(); - // }); + // Call the assertion callback + done(); + }); - // }); + }); - // }); - // }); + }); + }); afterEach(function(done) { Form.remove({}).exec(function() { diff --git a/app/tests/form_submission.model.test.js b/app/tests/form_submission.model.test.js index 78f8cc37..50d60452 100644 --- a/app/tests/form_submission.model.test.js +++ b/app/tests/form_submission.model.test.js @@ -1,314 +1,314 @@ -// 'use strict'; +'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'), -// async = require('async'), -// soap = require('soap'), -// config = require('../../config/config'), -// OscarSecurity = require('../../scripts/oscarhost/OscarSecurity'), -// FormSubmission = mongoose.model('FormSubmission'); +/** + * Module dependencies. + */ +var should = require('should'), + mongoose = require('mongoose'), + User = mongoose.model('User'), + Form = mongoose.model('Form'), + Field = mongoose.model('Field'), + _ = require('lodash'), + async = require('async'), + soap = require('soap'), + config = require('../../config/config'), + OscarSecurity = require('../../scripts/oscarhost/OscarSecurity'), + FormSubmission = mongoose.model('FormSubmission'); -// var exampleDemo = { -// address: '880-9650 Velit. St.', -// city: '', -// dateOfBirth: '10', -// displayName: 'Test User', -// email: 'polydaic@gmail.com', -// firstName: 'Test User', -// hin: '', -// lastName: 'AddDemographic', -// lastUpdateDate: '2014-10-01 00:00:00', -// monthOfBirth: '05', -// officialLanguage: 'English', -// phone: '250-222-2222', -// phone2: '', -// postal: 'S4M 7T8', -// province: 'BC', -// sex: 'F', -// sexDesc: 'Female', -// sin: '', -// spokenLanguage: 'English', -// title: 'MS.', -// yearOfBirth: '2015' -// }; +var exampleDemo = { + address: '880-9650 Velit. St.', + city: '', + dateOfBirth: '10', + displayName: 'Test User', + email: 'polydaic@gmail.com', + firstName: 'Test User', + hin: '', + lastName: 'AddDemographic', + lastUpdateDate: '2014-10-01 00:00:00', + monthOfBirth: '05', + officialLanguage: 'English', + phone: '250-222-2222', + phone2: '', + postal: 'S4M 7T8', + province: 'BC', + sex: 'F', + sexDesc: 'Female', + sin: '', + spokenLanguage: 'English', + title: 'MS.', + yearOfBirth: '2015' +}; -// var sampleFormFields = [ -// {'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': ''} -// ]; +var sampleFormFields = [ + {'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': ''} +]; -// var sampleSubmission = [ -// {'fieldType':'textfield', 'title':'What\'s your first name', 'fieldValue': 'David'}, -// {'fieldType':'textfield', 'title':'And your last name', 'fieldValue': 'Baldwynn'}, -// {'fieldType':'radio', 'title':'And your sex', 'fieldValue': 'M', 'fieldOptions': [{ 'option_id': 0, 'option_title': 'Male', 'option_value': 'M' }, { 'option_id': 1, 'option_title': 'Female', 'option_value': 'F' }]}, -// {'fieldType':'date', 'title':'When were you born?', 'fieldValue': 'Tue Oct 06 2015 15:17:48 GMT-0700 (PDT)'}, -// {'fieldType':'number', 'title':'What\'s your phone #?', 'fieldValue': '6043158008'} -// ]; +var sampleSubmission = [ + {'fieldType':'textfield', 'title':'What\'s your first name', 'fieldValue': 'David'}, + {'fieldType':'textfield', 'title':'And your last name', 'fieldValue': 'Baldwynn'}, + {'fieldType':'radio', 'title':'And your sex', 'fieldValue': 'M', 'fieldOptions': [{ 'option_id': 0, 'option_title': 'Male', 'option_value': 'M' }, { 'option_id': 1, 'option_title': 'Female', 'option_value': 'F' }]}, + {'fieldType':'date', 'title':'When were you born?', 'fieldValue': 'Tue Oct 06 2015 15:17:48 GMT-0700 (PDT)'}, + {'fieldType':'number', 'title':'What\'s your phone #?', 'fieldValue': '6043158008'} +]; -// /** -// * Globals -// */ -// var user, myForm, mySubmission; +/** + * Globals + */ +var user, myForm, mySubmission; -// /** -// * Unit tests -// */ -// describe('FormSubmission Model Unit Tests:', function() { -// this.timeout(15000); -// beforeEach(function(done) { -// user = new User({ -// firstName: 'Full', -// lastName: 'Name', -// displayName: 'Full Name', -// email: 'test1@test.com'+Date.now(), -// username: 'test1@test.com'+Date.now(), -// password: 'password', -// provider: 'local' -// }); +/** + * Unit tests + */ +describe('FormSubmission Model Unit Tests:', function() { + this.timeout(15000); + beforeEach(function(done) { + user = new User({ + firstName: 'Full', + lastName: 'Name', + displayName: 'Full Name', + email: 'test1@test.com'+Date.now(), + username: 'test1@test.com'+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', -// 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: { -// updateType: 'force_add', -// }, -// auth: config.oscarhost.auth, -// } -// } -// }); + user.save(function(err) { + if(err){ + console.log(err.errors); + done(err); + return; + } + myForm = new Form({ + title: 'Form Title1', + admin: user._id, + 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: { + updateType: 'force_add', + }, + auth: config.oscarhost.auth, + } + } + }); -// myForm.save(function(err, form){ -// if(err){ -// console.log(err.errors); -// done(err); -// return; -// } + myForm.save(function(err, form){ + if(err){ + console.log(err.errors); + done(err); + return; + } -// var submissionFields = _.clone(myForm.form_fields); -// for(var z=0; z should be able to create a Form Submission without signing in', function(done) { + it(' > should be able to create a Form Submission without signing in', function(done) { -// //Create Submission -// submissionSession.post('/forms/' + FormObj._id) -// .send(_Submission) -// .expect(200) -// .end(function(err, res) { + //Create Submission + submissionSession.post('/forms/' + FormObj._id) + .send(_Submission) + .expect(200) + .end(function(err, res) { -// should.not.exist(err); + should.not.exist(err); -// done(); -// }); -// }); + done(); + }); + }); -// it(' > should be able to get Form Submissions if signed in', function(done) { -// submissionSession.post('/auth/signin') -// .send(credentials) -// .expect('Content-Type', /json/) -// .expect(200) -// .end(function(signinErr, signinRes) { + it(' > should be able to get Form Submissions if signed in', function(done) { + submissionSession.post('/auth/signin') + .send(credentials) + .expect('Content-Type', /json/) + .expect(200) + .end(function(signinErr, signinRes) { -// should.not.exist(signinErr); + should.not.exist(signinErr); -// //Create Submission -// submissionSession.post('/forms/' + FormObj._id) -// .send(_Submission) -// .expect(200) -// .end(function(err, res) { + //Create Submission + submissionSession.post('/forms/' + FormObj._id) + .send(_Submission) + .expect(200) + .end(function(err, res) { -// should.not.exist(err); + should.not.exist(err); -// submissionSession.get('/forms/' + FormObj._id + '/submissions') -// .expect('Content-Type', /json/) -// .expect(200) -// .end(function(err, res) { + submissionSession.get('/forms/' + FormObj._id + '/submissions') + .expect('Content-Type', /json/) + .expect(200) + .end(function(err, res) { -// // Set assertion -// should.not.exist(err); + // Set assertion + should.not.exist(err); -// // Call the assertion callback -// done(); -// }); -// }); -// }); -// }); + // Call the assertion callback + done(); + }); + }); + }); + }); -// it(' > should not be able to get Form Submissions if not signed in', function(done) { -// // Attempt to fetch form submissions -// submissionSession.get('/forms/' + FormObj._id + '/submissions') -// .expect(401) -// .end(function(err, res) { + it(' > should not be able to get Form Submissions if not signed in', function(done) { + // Attempt to fetch form submissions + submissionSession.get('/forms/' + FormObj._id + '/submissions') + .expect(401) + .end(function(err, res) { -// // Set assertions -// (res.body.message).should.equal('User is not logged in'); + // Set assertions + (res.body.message).should.equal('User is not logged in'); -// // Call the assertion callback -// done(); -// }); -// }); + // Call the assertion callback + done(); + }); + }); -// it(' > should not be able to delete Form Submission if not signed in', function(done) { -// var SubmissionObj = new FormSubmission(_Submission); + it(' > should not be able to delete Form Submission if not signed in', function(done) { + var SubmissionObj = new FormSubmission(_Submission); -// SubmissionObj.save(function (err, submission) { -// should.not.exist(err); + SubmissionObj.save(function (err, submission) { + should.not.exist(err); -// var submission_ids = _.pluck([submission], '_id'); + var submission_ids = _.pluck([submission], '_id'); -// // Attempt to delete form submissions -// submissionSession.delete('/forms/' + FormObj._id + '/submissions') -// .send({deleted_submissions: submission_ids}) -// .expect(401) -// .end(function(err, res) { - -// // Set assertions -// should.not.exist(err); -// (res.body.message).should.equal('User is not logged in'); + // Attempt to delete form submissions + submissionSession.delete('/forms/' + FormObj._id + '/submissions') + .send({deleted_submissions: submission_ids}) + .expect(401) + .end(function(err, res) { -// // Call the assertion callback -// done(); -// }); -// }); -// }); + // Set assertions + should.not.exist(err); + (res.body.message).should.equal('User is not logged in'); -// it(' > should be able to delete Form Submission if signed in', function(done) { -// // Create new FormSubmission model instance -// var SubmissionObj = new FormSubmission(_Submission); + // Call the assertion callback + done(); + }); + }); + }); -// SubmissionObj.save(function (err, submission) { -// should.not.exist(err); + it(' > should be able to delete Form Submission if signed in', function(done) { + // Create new FormSubmission model instance + var SubmissionObj = new FormSubmission(_Submission); -// // Signin as user -// submissionSession.post('/auth/signin') -// .send(credentials) -// .expect('Content-Type', /json/) -// .expect(200) -// .end(function(signinErr, signinRes) { -// // Handle signin error -// if (signinErr) return done(signinErr); + SubmissionObj.save(function (err, submission) { + should.not.exist(err); -// var submission_ids = _.pluck([submission], '_id'); + // Signin as user + submissionSession.post('/auth/signin') + .send(credentials) + .expect('Content-Type', /json/) + .expect(200) + .end(function(signinErr, signinRes) { + // Handle signin error + if (signinErr) return done(signinErr); -// //Delete form submissions -// submissionSession.delete('/forms/' + FormObj._id + '/submissions') -// .send({deleted_submissions: submission_ids}) -// .expect(200) -// .end(function(err, res) { + var submission_ids = _.pluck([submission], '_id'); -// // Set assertions -// should.not.exist(err); -// (res.text).should.equal('Form submissions successfully deleted'); + //Delete form submissions + submissionSession.delete('/forms/' + FormObj._id + '/submissions') + .send({deleted_submissions: submission_ids}) + .expect(200) + .end(function(err, res) { -// // Call the assertion callback -// done(); -// }); -// }); -// }); -// }); + // Set assertions + should.not.exist(err); + (res.text).should.equal('Form submissions successfully deleted'); -// afterEach(function(done) {//logout current user if there is one -// FormSubmission.remove().exec(function() { -// Form.remove().exec(function (err) { -// User.remove({}).exec(function() { -// submissionSession.destroy(); -// done(); -// }); -// }); -// }); -// }); + // Call the assertion callback + done(); + }); + }); + }); + }); + + afterEach(function(done) {//logout current user if there is one + FormSubmission.remove().exec(function() { + Form.remove().exec(function (err) { + User.remove({}).exec(function() { + submissionSession.destroy(); + done(); + }); + }); + }); + }); -// }); \ No newline at end of file +}); diff --git a/app/tests/user.server.model.test.js b/app/tests/user.server.model.test.js index 56d709a4..e58744d8 100755 --- a/app/tests/user.server.model.test.js +++ b/app/tests/user.server.model.test.js @@ -1,90 +1,90 @@ -// 'use strict'; +'use strict'; -// /** -// * Module dependencies. -// */ -// var should = require('should'), -// mongoose = require('mongoose'), -// User = mongoose.model('User'); +/** + * Module dependencies. + */ +var should = require('should'), + mongoose = require('mongoose'), + User = mongoose.model('User'); -// /** -// * Globals -// */ -// var user, user2; +/** + * Globals + */ +var user, user2; -// /** -// * Unit tests -// */ -// describe('User Model Unit Tests:', function() { -// beforeEach(function(done) { -// user = new User({ -// firstName: 'Full', -// lastName: 'Name', -// email: 'test@test.com', -// username: 'test@test.com', -// password: 'password', -// provider: 'local' -// }); -// user2 = new User({ -// firstName: 'Full', -// lastName: 'Name', -// email: 'test@test.com', -// username: 'test@test.com', -// password: 'password', -// provider: 'local' -// }); +/** + * Unit tests + */ +describe('User Model Unit Tests:', function() { + beforeEach(function(done) { + user = new User({ + firstName: 'Full', + lastName: 'Name', + email: 'test@test.com', + username: 'test@test.com', + password: 'password', + provider: 'local' + }); + user2 = new User({ + firstName: 'Full', + lastName: 'Name', + email: 'test@test.com', + username: 'test@test.com', + password: 'password', + provider: 'local' + }); -// done(); -// }); + done(); + }); -// describe('Method Save', function() { -// it('should begin with no users', function(done) { -// User.find({}, function(err, users) { -// users.should.have.length(0); -// done(); -// }); -// }); + describe('Method Save', function() { + it('should begin with no users', function(done) { + User.find({}, function(err, users) { + users.should.have.length(0); + done(); + }); + }); -// it('should be able to save without problems', function(done) { -// user.save(done); -// }); + it('should be able to save without problems', function(done) { + user.save(done); + }); -// it('should fail to save an existing user again', function(done) { -// user.save(function() { -// user2.save(function(err) { -// should.exist(err); -// done(); -// }); -// }); -// }); + it('should fail to save an existing user again', function(done) { + user.save(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) { -// 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) { + should.exist(err); + done(); + }); + }); + }); -// describe('Method findUniqueUsername', function() { -// beforeEach(function(done) { -// User.find({}, function(err, users) { -// users.should.have.length(0); -// user.save(done); -// }); -// }); + describe('Method findUniqueUsername', function() { + beforeEach(function(done) { + User.find({}, function(err, users) { + users.should.have.length(0); + user.save(done); + }); + }); -// it('should be able to find unique version of existing username without problems', function(done) { -// User.findUniqueUsername(user.username, null, function (availableUsername) { -// availableUsername.should.not.equal(user.username); -// done(); -// }); -// }); + it('should be able to find unique version of existing username without problems', function(done) { + User.findUniqueUsername(user.username, null, function (availableUsername) { + availableUsername.should.not.equal(user.username); + done(); + }); + }); -// }); + }); -// afterEach(function(done) { -// User.remove().exec(done); -// }); -// }); + afterEach(function(done) { + User.remove().exec(done); + }); +}); diff --git a/app/tests/user.server.routes.test.js b/app/tests/user.server.routes.test.js index e659ee30..2108edc7 100644 --- a/app/tests/user.server.routes.test.js +++ b/app/tests/user.server.routes.test.js @@ -1,184 +1,182 @@ -// 'use strict'; +'use strict'; -// var should = require('should'), -// _ = require('lodash'), -// app = require('../../server'), -// request = require('supertest'), -// Session = require('supertest-session')({ -// app: app -// }), -// mongoose = require('mongoose'), -// User = mongoose.model('User'), -// config = require('../../config/config'), -// tmpUser = mongoose.model(config.tempUserCollection), -// agent = request.agent(app), -// url = require('url'); +var should = require('should'), + _ = require('lodash'), + app = require('../../server'), + request = require('supertest'), + Session = require('supertest-session'), + mongoose = require('mongoose'), + User = mongoose.model('User'), + config = require('../../config/config'), + tmpUser = mongoose.model(config.tempUserCollection), + agent = request.agent(app), + url = require('url'); -// var mailosaur = require('mailosaur')(config.mailosaur.key), -// mailbox = new mailosaur.Mailbox(config.mailosaur.mailbox_id); +var mailosaur = require('mailosaur')(config.mailosaur.key), + mailbox = new mailosaur.Mailbox(config.mailosaur.mailbox_id); -// var mandrill = require('node-mandrill')(config.mailer.options.auth.pass); +var mandrill = require('node-mandrill')(config.mailer.options.auth.pass); -// /** -// * Globals -// */ -// var credentials, _User, _Session; +/** + * Globals + */ +var credentials, _User, _Session; -// /** -// * Form routes tests -// */ -// describe('User CRUD tests', function() { -// this.timeout(15000); -// var userSession; +/** + * Form routes tests + */ +describe('User CRUD tests', function() { + this.timeout(15000); + var userSession; -// beforeEach(function() { -// //Initialize Session -// userSession = new Session(); + beforeEach(function() { + //Initialize Session + userSession = new Session(); -// // Create user credentials -// credentials = { -// username: 'be1e58fb@mailosaur.in', -// password: 'password' -// }; + // Create user credentials + credentials = { + username: 'be1e58fb@mailosaur.in', + password: 'password' + }; -// //Create a new user -// _User = { -// firstName: 'Full', -// lastName: 'Name', -// email: credentials.username, -// username: credentials.username, -// password: credentials.password, -// provider: 'local' -// }; -// }); + //Create a new user + _User = { + firstName: 'Full', + lastName: 'Name', + email: credentials.username, + username: credentials.username, + password: credentials.password, + provider: 'local' + }; + }); -// describe(' > Create, Verify and Activate a User > ', function() { -// var username = 'testActiveAccount1.be1e58fb@mailosaur.in'; -// var link, _tmpUser, activateToken; -// this.timeout(15000); + describe(' > Create, Verify and Activate a User > ', function() { + var username = 'testActiveAccount1.be1e58fb@mailosaur.in'; + var link, _tmpUser, activateToken; + this.timeout(15000); -// it('should be able to create a temporary (non-activated) User', function(done) { -// _User.email = _User.username = username; -// userSession.post('/auth/signup') -// .send(_User) -// .expect(200, 'An email has been sent to you. Please check it to verify your account.') -// .end(function(FormSaveErr, FormSaveRes) { -// // Handle error -// if (FormSaveErr) return done(FormSaveErr); + it('should be able to create a temporary (non-activated) User', function(done) { + _User.email = _User.username = username; + userSession.post('/auth/signup') + .send(_User) + .expect(200, 'An email has been sent to you. Please check it to verify your account.') + .end(function(FormSaveErr, FormSaveRes) { + // Handle error + if (FormSaveErr) return done(FormSaveErr); -// tmpUser.findOne({username: _User.username}, function (err, user) { -// should.not.exist(err); -// should.exist(user); -// _tmpUser = user; + tmpUser.findOne({username: _User.username}, function (err, user) { + should.not.exist(err); + should.exist(user); + _tmpUser = user; -// _User.username.should.equal(user.username); -// _User.firstName.should.equal(user.firstName); -// _User.lastName.should.equal(user.lastName); -// activateToken = user.GENERATED_VERIFYING_URL; + _User.username.should.equal(user.username); + _User.firstName.should.equal(user.firstName); + _User.lastName.should.equal(user.lastName); + activateToken = user.GENERATED_VERIFYING_URL; -// done(); -// }); + done(); + }); -// // // mandrill('/messages/search', { -// // // query: "subject:Confirm", -// // // senders: [ -// // // "test@forms.polydaic.com" -// // // ], -// // // limit: 1 -// // // }, function(error, emails) { -// // // if (error) console.log( JSON.stringify(error) ); + // // mandrill('/messages/search', { + // // query: "subject:Confirm", + // // senders: [ + // // "test@forms.polydaic.com" + // // ], + // // limit: 1 + // // }, function(error, emails) { + // // if (error) console.log( JSON.stringify(error) ); -// // // var confirmation_email = emails[0]; + // // var confirmation_email = emails[0]; -// // // mandrill('/messages/content', { -// // // id: confirmation_email._id -// // // }, function(error, email) { -// // // if (error) console.log( JSON.stringify(error) ); + // // mandrill('/messages/content', { + // // id: confirmation_email._id + // // }, function(error, email) { + // // if (error) console.log( JSON.stringify(error) ); -// // // // console.log(email); -// // // var link = _(email.text.split('\n')).reverse().value()[1]; -// // // console.log(link); -// // // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0]; -// // // console.log('actual activateToken: '+ activateToken); -// // // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL); + // // // console.log(email); + // // var link = _(email.text.split('\n')).reverse().value()[1]; + // // console.log(link); + // // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0]; + // // console.log('actual activateToken: '+ activateToken); + // // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL); -// // // done(); + // // done(); -// // // }); -// // // }); + // // }); + // // }); -// // // mailbox.getEmails(function(err, _emails) { -// // // if(err) done(err); + // // mailbox.getEmails(function(err, _emails) { + // // if(err) done(err); -// // // var emails = _emails; + // // var emails = _emails; -// // // console.log('mailbox.getEmails:'); -// // // console.log(emails[0].text.links); + // // console.log('mailbox.getEmails:'); + // // console.log(emails[0].text.links); -// // // var link = emails[0].text.links[0].href; -// // // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0]; -// // // console.log('actual activateToken: '+ activateToken); -// // // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL); -// // // (activateToken).should.equal(user.GENERATED_VERIFYING_URL); + // // var link = emails[0].text.links[0].href; + // // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0]; + // // console.log('actual activateToken: '+ activateToken); + // // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL); + // // (activateToken).should.equal(user.GENERATED_VERIFYING_URL); -// // // done(); -// // // }); -// // }); -// }); -// }); - -// it('should be able to verify a User Account', function(done) { -// 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'); -// done(); -// }); -// }); + // // done(); + // // }); + // }); + }); + }); -// it('should be able to login and logout a verified User Account', function(done) { -// userSession.post('/auth/signin') -// .send(credentials) -// .expect('Content-Type', /json/) -// .expect(200) -// .end(function(signinErr, signinRes) { -// // Handle signin error -// if (signinErr) return done(signinErr); + it('should be able to verify a User Account', function(done) { + 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'); + done(); + }); + }); -// var user = signinRes.body; -// (user.username).should.equal(credentials.username); + it('should be able to login and logout a verified User Account', function(done) { + userSession.post('/auth/signin') + .send(credentials) + .expect('Content-Type', /json/) + .expect(200) + .end(function(signinErr, signinRes) { + // Handle signin error + if (signinErr) return done(signinErr); -// userSession.get('/auth/signout') -// .expect(200) -// .end(function(signoutErr, signoutRes) { + var user = signinRes.body; + (user.username).should.equal(credentials.username); -// // Handle signout error -// if (signoutErr) return done(signoutErr); + userSession.get('/auth/signout') + .expect(200) + .end(function(signoutErr, signoutRes) { -// (signoutRes.text).should.equal('Successfully logged out'); + // Handle signout error + if (signoutErr) return done(signoutErr); -// done(); -// }); -// }); -// }); -// }); + (signoutRes.text).should.equal('Successfully logged out'); -// it(' > should be able to reset a User\'s password'); + done(); + }); + }); + }); + }); -// it(' > should be able to delete a User account without any problems'); + it(' > should be able to reset a User\'s password'); -// afterEach(function(done) { -// User.remove().exec(function () { -// tmpUser.remove().exec(function(){ -// // mailbox.deleteAllEmail(function (err, body) { -// // if(err) throw err; -// userSession.destroy(); -// done(); -// // }); -// }); -// }); -// }); -// }); + it(' > should be able to delete a User account without any problems'); + + afterEach(function(done) { + User.remove().exec(function () { + tmpUser.remove().exec(function(){ + // mailbox.deleteAllEmail(function (err, body) { + // if(err) throw err; + userSession.destroy(); + done(); + // }); + }); + }); + }); +});