added testing

This commit is contained in:
David Baldwynn 2015-08-12 11:38:12 -07:00
parent 0476e51730
commit cee90c9443
9 changed files with 873 additions and 849 deletions

View File

@ -17,33 +17,6 @@ var _ = require('lodash'),
var smtpTransport = nodemailer.createTransport(config.mailer.options); var smtpTransport = nodemailer.createTransport(config.mailer.options);
// // NEV configuration =====================
// nev.configure({
// persistentUserModel: User,
// tempUserCollection: config.tempUserCollection,
// expirationTime: 1800, // 30 minutes
// verificationURL: config.baseUrl+'/#!/verify/${URL}',
// transportOptions: config.mailer.options,
// verifyMailOptions: {
// from: config.mailer.from,
// subject: 'Confirm your account',
// html: '<p>Please verify your account by clicking <a href="${URL}">this link</a>. If you are unable to do so, copy and ' +
// 'paste the following link into your browser:</p><p>${URL}</p>',
// text: 'Please verify your account by clicking the following link, or by copying and pasting it into your browser: ${URL}'
// },
// confirmMailOptions: {
// from: config.mailer.from,
// subject: 'Successfully verified!',
// html: '<p>Your account has been successfully verified.</p>',
// text: 'Your account has been successfully verified.'
// },
// });
// nev.generateTempUserModel(User);
exports.validateVerificationToken = function(req, res, next){ exports.validateVerificationToken = function(req, res, next){
nev.confirmTempUser(req.params.token, function(user) { nev.confirmTempUser(req.params.token, function(user) {
@ -86,8 +59,15 @@ exports.signup = function(req, res) {
nev.createTempUser(user, function(newTempUser) { nev.createTempUser(user, function(newTempUser) {
// new user created // new user created
if (newTempUser) { if (newTempUser) {
nev.registerTempUser(newTempUser); nev.registerTempUser(newTempUser, function (err) {
res.status(200).send('An email has been sent to you. Please check it to verify your account.'); if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
}
res.status(200).send('An email has been sent to you. Please check it to verify your account.');
});
} else { } else {
res.status(400).send('Error: Temp user could NOT be created!'); res.status(400).send('Error: Temp user could NOT be created!');
} }

View File

@ -1,189 +1,189 @@
'use strict'; // 'use strict';
/** // /**
* Module dependencies. // * Module dependencies.
*/ // */
var should = require('should'), // var should = require('should'),
mongoose = require('mongoose'), // mongoose = require('mongoose'),
User = mongoose.model('User'), // User = mongoose.model('User'),
Form = mongoose.model('Form'), // Form = mongoose.model('Form'),
_ = require('lodash'), // _ = require('lodash'),
FormSubmission = mongoose.model('FormSubmission'); // FormSubmission = mongoose.model('FormSubmission');
/** // /**
* Globals // * Globals
*/ // */
var user, myForm, mySubmission; // var user, myForm, mySubmission;
/** // /**
* Unit tests // * Unit tests
*/ // */
describe('Form Model Unit Tests:', function() { // describe('Form Model Unit Tests:', function() {
beforeEach(function(done) { // beforeEach(function(done) {
user = new User({ // user = new User({
firstName: 'Full', // firstName: 'Full',
lastName: 'Name', // lastName: 'Name',
displayName: 'Full Name', // displayName: 'Full Name',
email: 'test@test.com', // email: 'test@test.com',
username: 'username', // username: 'username',
password: 'password' // password: 'password'
}); // });
user.save(function() { // user.save(function() {
myForm = new Form({ // myForm = new Form({
title: 'Form Title', // title: 'Form Title',
admin: user, // admin: user,
language: 'english', // language: 'english',
form_fields: [ // form_fields: [
{'fieldType':'textfield', 'title':'First Name', 'fieldValue': ''}, // {'fieldType':'textfield', 'title':'First Name', 'fieldValue': ''},
{'fieldType':'checkbox', 'title':'nascar', 'fieldValue': ''}, // {'fieldType':'checkbox', 'title':'nascar', 'fieldValue': ''},
{'fieldType':'checkbox', 'title':'hockey', 'fieldValue': ''} // {'fieldType':'checkbox', 'title':'hockey', 'fieldValue': ''}
] // ]
}); // });
done(); // done();
}); // });
}); // });
describe('Method Save', function() { // describe('Method Save', function() {
it('should be able to save without problems', function(done) { // it('should be able to save without problems', function(done) {
return myForm.save(function(err) { // return myForm.save(function(err) {
should.not.exist(err); // should.not.exist(err);
done(); // done();
}); // });
}); // });
it('should be able to show an error when try to save without title', function(done) { // it('should be able to show an error when try to save without title', function(done) {
var _form = myForm; // var _form = myForm;
_form.title = ''; // _form.title = '';
return _form.save(function(err) { // return _form.save(function(err) {
should.exist(err); // should.exist(err);
should.equal(err.errors.title.message, 'Form Title cannot be blank'); // should.equal(err.errors.title.message, 'Form Title cannot be blank');
done(); // done();
}); // });
}); // });
}); // });
describe('Method Find', function(){ // describe('Method Find', function(){
beforeEach(function(done){ // beforeEach(function(done){
myForm.save(function(err) { // myForm.save(function(err) {
done(); // done();
}); // });
}); // });
it('should be able to findOne my form without problems', function(done) { // it('should be able to findOne my form without problems', function(done) {
return Form.findOne({_id: myForm._id}, function(err,form) { // return Form.findOne({_id: myForm._id}, function(err,form) {
should.not.exist(err); // should.not.exist(err);
should.exist(form); // should.exist(form);
should.deepEqual(form.toObject(), myForm.toObject()); // should.deepEqual(form.toObject(), myForm.toObject());
done(); // done();
}); // });
}); // });
}); // });
describe('Test FormField and Submission Logic', function() { // describe('Test FormField and Submission Logic', function() {
var new_form_fields_add1, new_form_fields_del, submission_fields, old_fields, form; // var new_form_fields_add1, new_form_fields_del, submission_fields, old_fields, form;
before(function(){ // before(function(){
new_form_fields_add1 = _.clone(myForm.toObject().form_fields); // new_form_fields_add1 = _.clone(myForm.toObject().form_fields);
new_form_fields_add1.push( // new_form_fields_add1.push(
{'fieldType':'textfield', 'title':'Last Name', 'fieldValue': ''} // {'fieldType':'textfield', 'title':'Last Name', 'fieldValue': ''}
); // );
new_form_fields_del = _.clone(myForm.toObject().form_fields); // new_form_fields_del = _.clone(myForm.toObject().form_fields);
new_form_fields_del.splice(0, 1); // new_form_fields_del.splice(0, 1);
submission_fields = _.clone(myForm.toObject().form_fields); // submission_fields = _.clone(myForm.toObject().form_fields);
submission_fields[0].fieldValue = 'David'; // submission_fields[0].fieldValue = 'David';
submission_fields[1].fieldValue = true; // submission_fields[1].fieldValue = true;
submission_fields[2].fieldValue = true; // submission_fields[2].fieldValue = true;
mySubmission = new FormSubmission({ // mySubmission = new FormSubmission({
form_fields: submission_fields, // form_fields: submission_fields,
admin: user, // admin: user,
form: myForm, // form: myForm,
timeElapsed: 17.55 // timeElapsed: 17.55
}); // });
}); // });
beforeEach(function(done){ // beforeEach(function(done){
myForm.save(function(){ // myForm.save(function(){
mySubmission.save(function(){ // mySubmission.save(function(){
done(); // done();
}); // });
}); // });
}); // });
afterEach(function(done){ // afterEach(function(done){
mySubmission.remove(function(){ // mySubmission.remove(function(){
done(); // done();
}); // });
}); // });
// it('should preserve deleted form_fields that have submissions without any problems', function(done) { // // it('should preserve deleted form_fields that have submissions without any problems', function(done) {
// old_fields = myForm.toObject().form_fields; // // old_fields = myForm.toObject().form_fields;
// // console.log(old_fields); // // // console.log(old_fields);
// // var expected_fields = old_fields.slice(1,3).concat(old_fields.slice(0,1)); // // // var expected_fields = old_fields.slice(1,3).concat(old_fields.slice(0,1));
// myForm.form_fields = new_form_fields_del; // // myForm.form_fields = new_form_fields_del;
// myForm.save(function(err, _form) { // // myForm.save(function(err, _form) {
// should.not.exist(err); // // should.not.exist(err);
// should.exist(_form); // // should.exist(_form);
// // var actual_fields = _.map(_form.toObject().form_fields, function(o){ _.omit(o, '_id')}); // // // var actual_fields = _.map(_form.toObject().form_fields, function(o){ _.omit(o, '_id')});
// // old_fields = _.map(old_fields, function(o){ _.omit(o, '_id')}); // // // old_fields = _.map(old_fields, function(o){ _.omit(o, '_id')});
// // console.log(old_fields); // // // console.log(old_fields);
// should.deepEqual(JSON.stringify(_form.toObject().form_fields), JSON.stringify(old_fields), 'old form_fields not equal to newly saved form_fields'); // // should.deepEqual(JSON.stringify(_form.toObject().form_fields), JSON.stringify(old_fields), 'old form_fields not equal to newly saved form_fields');
// done(); // // done();
// }); // // });
// }); // // });
// it('should delete \'preserved\' form_fields whose submissions have been removed without any problems', function(done) { // // it('should delete \'preserved\' form_fields whose submissions have been removed without any problems', function(done) {
// myForm.form_fields = new_form_fields_del; // // myForm.form_fields = new_form_fields_del;
// myForm.save(function(err, form // // myForm.save(function(err, form
// should.not.exist(err); // // should.not.exist(err);
// (form.form_fields).should.be.eql(old_fields, 'old form_fields not equal to newly saved form_fields'); // // (form.form_fields).should.be.eql(old_fields, 'old form_fields not equal to newly saved form_fields');
// //Remove submission // // //Remove submission
// mySubmission.remove(function(err){ // // mySubmission.remove(function(err){
// myForm.submissions.should.have.length(0); // // myForm.submissions.should.have.length(0);
// myForm.form_fields.should.not.containDeep(old_fields[0]); // // myForm.form_fields.should.not.containDeep(old_fields[0]);
// }); // // });
// }); // // });
// }); // // });
}); // });
// describe('Method generateFDFTemplate', function() { // // describe('Method generateFDFTemplate', function() {
// var FormFDF; // // var FormFDF;
// before(function(done){ // // before(function(done){
// return myForm.save(function(err, form){ // // return myForm.save(function(err, form){
// FormFDF = { // // FormFDF = {
// 'First Name': '', // // 'First Name': '',
// 'nascar': '', // // 'nascar': '',
// 'hockey': '' // // 'hockey': ''
// }; // // };
// done(); // // done();
// }); // // });
// }); // // });
// it('should be able to generate a FDF template without any problems', function() { // // it('should be able to generate a FDF template without any problems', function() {
// var fdfTemplate = myForm.generateFDFTemplate(); // // var fdfTemplate = myForm.generateFDFTemplate();
// (fdfTemplate).should.be.eql(FormFDF); // // (fdfTemplate).should.be.eql(FormFDF);
// }); // // });
// }); // // });
afterEach(function(done) { // afterEach(function(done) {
Form.remove().exec(function() { // Form.remove().exec(function() {
User.remove().exec(done); // User.remove().exec(done);
}); // });
}); // });
}); // });

View File

@ -1,496 +1,496 @@
'use strict'; // 'use strict';
var should = require('should'), // var should = require('should'),
_ = require('lodash'), // _ = require('lodash'),
app = require('../../server'), // app = require('../../server'),
request = require('supertest'), // request = require('supertest'),
Session = require('supertest-session')({ // Session = require('supertest-session')({
app: app // app: app
}), // }),
mongoose = require('mongoose'), // mongoose = require('mongoose'),
User = mongoose.model('User'), // User = mongoose.model('User'),
Form = mongoose.model('Form'), // Form = mongoose.model('Form'),
FormSubmission = mongoose.model('FormSubmission'), // FormSubmission = mongoose.model('FormSubmission'),
agent = request.agent(app); // agent = request.agent(app);
/** // /**
* Globals // * Globals
*/ // */
var credentials, user, _Form; // var credentials, user, _Form;
/** // /**
* Form routes tests // * Form routes tests
*/ // */
describe('Form CRUD tests', function() { // describe('Form CRUD tests', function() {
beforeEach(function(done) { // beforeEach(function(done) {
// Create user credentials // // Create user credentials
credentials = { // credentials = {
username: 'test@test.com', // username: 'test@test.com',
password: 'password' // password: 'password'
}; // };
// Create a new user // // Create a new user
user = new User({ // user = new User({
firstName: 'Full', // firstName: 'Full',
lastName: 'Name', // lastName: 'Name',
email: 'test@test.com', // email: 'test@test.com',
username: credentials.username, // username: credentials.username,
password: credentials.password, // password: credentials.password,
provider: 'local' // provider: 'local'
}); // });
// Save a user to the test db and create new Form // // Save a user to the test db and create new Form
user.save(function(err) { // user.save(function(err) {
if(err) done(err); // if(err) done(err);
_Form = { // _Form = {
title: 'Form Title', // title: 'Form Title',
language: 'english', // language: 'english',
admin: user._id, // admin: user._id,
form_fields: [ // form_fields: [
{'fieldType':'textfield', 'title':'First Name', 'fieldValue': ''}, // {'fieldType':'textfield', 'title':'First Name', 'fieldValue': ''},
{'fieldType':'checkbox', 'title':'nascar', 'fieldValue': ''}, // {'fieldType':'checkbox', 'title':'nascar', 'fieldValue': ''},
{'fieldType':'checkbox', 'title':'hockey', 'fieldValue': ''} // {'fieldType':'checkbox', 'title':'hockey', 'fieldValue': ''}
] // ]
}; // };
done(); // done();
}); // });
}); // });
it('should be able to save a Form if logged in', function(done) { // it('should be able to save a Form if logged in', function(done) {
agent.post('/auth/signin') // agent.post('/auth/signin')
.send(credentials) // .send(credentials)
.expect('Content-Type', /json/) // .expect('Content-Type', /json/)
.expect(200) // .expect(200)
.end(function(signinErr, signinRes) { // .end(function(signinErr, signinRes) {
// Handle signin error // // Handle signin error
if (signinErr) done(signinErr); // if (signinErr) done(signinErr);
var user = signinRes.body; // var user = signinRes.body;
var userId = user._id; // var userId = user._id;
// Save a new Form // // Save a new Form
agent.post('/forms') // agent.post('/forms')
.send({form: _Form}) // .send({form: _Form})
.expect('Content-Type', /json/) // .expect('Content-Type', /json/)
.expect(200) // .expect(200)
.end(function(FormSaveErr, FormSaveRes) { // .end(function(FormSaveErr, FormSaveRes) {
// Handle Form save error // // Handle Form save error
if (FormSaveErr) done(FormSaveErr); // if (FormSaveErr) done(FormSaveErr);
// Get a list of Forms // // Get a list of Forms
agent.get('/forms') // agent.get('/forms')
.expect('Content-Type', /json/) // .expect('Content-Type', /json/)
.expect(200) // .expect(200)
.end(function(FormsGetErr, FormsGetRes) { // .end(function(FormsGetErr, FormsGetRes) {
// Handle Form save error // // Handle Form save error
if (FormsGetErr) done(FormsGetErr); // if (FormsGetErr) done(FormsGetErr);
// Get Forms list // // Get Forms list
var Forms = FormsGetRes.body; // var Forms = FormsGetRes.body;
// Set assertions // // Set assertions
(Forms[0].admin).should.equal(userId); // (Forms[0].admin).should.equal(userId);
(Forms[0].title).should.match('Form Title'); // (Forms[0].title).should.match('Form Title');
// Call the assertion callback // // Call the assertion callback
done(); // done();
}); // });
}); // });
}); // });
}); // });
it('should not be able to create a Form if not logged in', function(done) { // it('should not be able to create a Form if not logged in', function(done) {
agent.post('/forms') // agent.post('/forms')
.send({form: _Form}) // .send({form: _Form})
.expect(401) // .expect(401)
.end(function(FormSaveErr, FormSaveRes) { // .end(function(FormSaveErr, FormSaveRes) {
(FormSaveRes.body.message).should.equal('User is not logged in'); // (FormSaveRes.body.message).should.equal('User is not logged in');
// Call the assertion callback // // Call the assertion callback
done(FormSaveErr); // done(FormSaveErr);
}); // });
}); // });
it('should not be able to get list of users\' Forms if not logged in', function(done) { // it('should not be able to get list of users\' Forms if not logged in', function(done) {
agent.get('/forms') // agent.get('/forms')
.expect(401) // .expect(401)
.end(function(FormSaveErr, FormSaveRes) { // .end(function(FormSaveErr, FormSaveRes) {
(FormSaveRes.body.message).should.equal('User is not logged in'); // (FormSaveRes.body.message).should.equal('User is not logged in');
// Call the assertion callback // // Call the assertion callback
done(FormSaveErr); // done(FormSaveErr);
}); // });
}); // });
it('should not be able to save a Form if no title is provided', function(done) { // it('should not be able to save a Form if no title is provided', function(done) {
// Set Form with a invalid title field // // Set Form with a invalid title field
_Form.title = ''; // _Form.title = '';
agent.post('/auth/signin') // agent.post('/auth/signin')
.send(credentials) // .send(credentials)
.expect('Content-Type', /json/) // .expect('Content-Type', /json/)
.expect(200) // .expect(200)
.end(function(signinErr, signinRes) { // .end(function(signinErr, signinRes) {
// Handle signin error // // Handle signin error
if (signinErr) done(signinErr); // if (signinErr) done(signinErr);
// Save a new Form // // Save a new Form
agent.post('/forms') // agent.post('/forms')
.send({form: _Form}) // .send({form: _Form})
.expect(400) // .expect(400)
.end(function(FormSaveErr, FormSaveRes) { // .end(function(FormSaveErr, FormSaveRes) {
// Set message assertion // // Set message assertion
(FormSaveRes.body.message).should.equal('Form Title cannot be blank'); // (FormSaveRes.body.message).should.equal('Form Title cannot be blank');
// Handle Form save error // // Handle Form save error
done(); // done();
}); // });
}); // });
}); // });
it('should be able to update a Form if signed in', function(done) { // it('should be able to update a Form if signed in', function(done) {
agent.post('/auth/signin') // agent.post('/auth/signin')
.send(credentials) // .send(credentials)
.expect('Content-Type', /json/) // .expect('Content-Type', /json/)
.expect(200) // .expect(200)
.end(function(signinErr, signinRes) { // .end(function(signinErr, signinRes) {
// Handle signin error // // Handle signin error
if (signinErr) done(signinErr); // if (signinErr) done(signinErr);
// Save a new Form // // Save a new Form
agent.post('/forms') // agent.post('/forms')
.send({form: _Form}) // .send({form: _Form})
.expect('Content-Type', /json/) // .expect('Content-Type', /json/)
.expect(200) // .expect(200)
.end(function(FormSaveErr, FormSaveRes) { // .end(function(FormSaveErr, FormSaveRes) {
// Handle Form save error // // Handle Form save error
if (FormSaveErr) done(FormSaveErr); // if (FormSaveErr) done(FormSaveErr);
// Update Form title // // Update Form title
_Form.title = 'WHY YOU GOTTA BE SO MEAN?'; // _Form.title = 'WHY YOU GOTTA BE SO MEAN?';
// Update an existing Form // // Update an existing Form
agent.put('/forms/' + FormSaveRes.body._id) // agent.put('/forms/' + FormSaveRes.body._id)
.send({form: _Form}) // .send({form: _Form})
.expect('Content-Type', /json/) // .expect('Content-Type', /json/)
.expect(200) // .expect(200)
.end(function(FormUpdateErr, FormUpdateRes) { // .end(function(FormUpdateErr, FormUpdateRes) {
// Handle Form update error // // Handle Form update error
if (FormUpdateErr) done(FormUpdateErr); // if (FormUpdateErr) done(FormUpdateErr);
// Set assertions // // Set assertions
(FormUpdateRes.body._id).should.equal(FormSaveRes.body._id); // (FormUpdateRes.body._id).should.equal(FormSaveRes.body._id);
(FormUpdateRes.body.title).should.match('WHY YOU GOTTA BE SO MEAN?'); // (FormUpdateRes.body.title).should.match('WHY YOU GOTTA BE SO MEAN?');
// Call the assertion callback // // Call the assertion callback
done(); // done();
}); // });
}); // });
}); // });
}); // });
it('should be able to read/get a Form if not signed in', function(done) { // it('should be able to read/get a Form if not signed in', function(done) {
// Create new Form model instance // // Create new Form model instance
var FormObj = new Form(_Form); // var FormObj = new Form(_Form);
// Save the Form // // Save the Form
FormObj.save(function(err, form) { // FormObj.save(function(err, form) {
if(err) done(err); // if(err) done(err);
request(app).get('/forms/' + form._id) // request(app).get('/forms/' + form._id)
.expect('Content-Type', /json/) // .expect('Content-Type', /json/)
.expect(200) // .expect(200)
.end(function(err, res) { // .end(function(err, res) {
if(err) done(err) // if(err) done(err)
// Set assertion // // Set assertion
(res.body).should.be.an.Object.with.property('title', _Form.title); // (res.body).should.be.an.Object.with.property('title', _Form.title);
// Call the assertion callback // // Call the assertion callback
done(); // 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) {
agent.post('/auth/signin') // agent.post('/auth/signin')
.send(credentials) // .send(credentials)
.expect('Content-Type', /json/) // .expect('Content-Type', /json/)
.expect(200) // .expect(200)
.end(function(signinErr, signinRes) { // .end(function(signinErr, signinRes) {
// Handle signin error // // Handle signin error
if (signinErr) done(signinErr); // if (signinErr) done(signinErr);
done(); // done();
// Save a new Form // // Save a new Form
// agent.post('/forms') // // agent.post('/forms')
// .send({form: _Form}) // // .send({form: _Form})
// .expect('Content-Type', /json/) // // .expect('Content-Type', /json/)
// .expect(200) // // .expect(200)
// .end(function(FormSaveErr, FormSaveRes) { // // .end(function(FormSaveErr, FormSaveRes) {
// // Handle Form save error // // // Handle Form save error
// if (FormSaveErr) done(FormSaveErr); // // if (FormSaveErr) done(FormSaveErr);
// // Delete an existing Form // // // Delete an existing Form
// agent.delete('/forms/' + FormSaveRes.body._id) // // agent.delete('/forms/' + FormSaveRes.body._id)
// .send(_Form) // // .send(_Form)
// .expect('Content-Type', /json/) // // .expect('Content-Type', /json/)
// .expect(200) // // .expect(200)
// .end(function(FormDeleteErr, FormDeleteRes) { // // .end(function(FormDeleteErr, FormDeleteRes) {
// // Handle Form error error // // // Handle Form error error
// if (FormDeleteErr) done(FormDeleteErr); // // if (FormDeleteErr) done(FormDeleteErr);
// // Set assertions // // // Set assertions
// (FormDeleteRes.body._id).should.equal(FormSaveRes.body._id); // // (FormDeleteRes.body._id).should.equal(FormSaveRes.body._id);
// // Call the assertion callback // // // Call the assertion callback
// done(); // // done();
// }); // // });
// }); // // });
}); // });
}); // });
it('should not be able to delete an Form if not signed in', function(done) { // it('should not be able to delete an Form if not signed in', function(done) {
// Set Form user // // Set Form user
_Form.admin = user; // _Form.admin = user;
// Create new Form model instance // // Create new Form model instance
var FormObj = new Form(_Form); // var FormObj = new Form(_Form);
// Save the Form // // Save the Form
FormObj.save(function() { // FormObj.save(function() {
// Try deleting Form // // Try deleting Form
request(app).delete('/forms/' + FormObj._id) // request(app).delete('/forms/' + FormObj._id)
.expect(401) // .expect(401)
.end(function(FormDeleteErr, FormDeleteRes) { // .end(function(FormDeleteErr, FormDeleteRes) {
// Set message assertion // // Set message assertion
(FormDeleteRes.body.message).should.match('User is not logged in'); // (FormDeleteRes.body.message).should.match('User is not logged in');
// Handle Form error error // // Handle Form error error
done(FormDeleteErr); // done(FormDeleteErr);
}); // });
}); // });
}); // });
it('should be able to upload a PDF an Form if logged in', function(done) { // it('should be able to upload a PDF an Form if logged in', function(done) {
agent.post('/auth/signin') // agent.post('/auth/signin')
.send(credentials) // .send(credentials)
.expect('Content-Type', /json/) // .expect('Content-Type', /json/)
.expect(200) // .expect(200)
.end(function(signinErr, signinRes) { // .end(function(signinErr, signinRes) {
// Handle signin error // // Handle signin error
if (signinErr) done(signinErr); // if (signinErr) done(signinErr);
var user = signinRes.body; // var user = signinRes.body;
var userId = user._id; // var userId = user._id;
// Save a new Form // // Save a new Form
agent.post('/forms') // agent.post('/forms')
.send({form: _Form}) // .send({form: _Form})
.expect('Content-Type', /json/) // .expect('Content-Type', /json/)
.expect(200) // .expect(200)
.end(function(FormSaveErr, FormSaveRes) { // .end(function(FormSaveErr, FormSaveRes) {
// Handle Form save error // // Handle Form save error
if (FormSaveErr) done(FormSaveErr); // if (FormSaveErr) done(FormSaveErr);
// Get a list of Forms // // Get a list of Forms
agent.get('/forms') // agent.get('/forms')
.expect('Content-Type', /json/) // .expect('Content-Type', /json/)
.expect(200) // .expect(200)
.end(function(FormsGetErr, FormsGetRes) { // .end(function(FormsGetErr, FormsGetRes) {
// Handle Form save error // // Handle Form save error
if (FormsGetErr) done(FormsGetErr); // if (FormsGetErr) done(FormsGetErr);
// Get Forms list // // Get Forms list
var Forms = FormsGetRes.body; // var Forms = FormsGetRes.body;
// Set assertions // // Set assertions
(Forms[0].admin).should.equal(userId); // (Forms[0].admin).should.equal(userId);
(Forms[0].title).should.match('Form Title'); // (Forms[0].title).should.match('Form Title');
// Call the assertion callback // // Call the assertion callback
done(); // done();
}); // });
}); // });
}); // });
}); // });
describe('Form Submission tests', function() { // describe('Form Submission tests', function() {
var FormObj, _Submission, submissionSession; // var FormObj, _Submission, submissionSession;
beforeEach(function (done) { // beforeEach(function (done) {
_Form.admin = user; // _Form.admin = user;
FormObj = new Form(_Form); // FormObj = new Form(_Form);
FormObj.save(function(err, form) { // FormObj.save(function(err, form) {
if (err) done(err); // if (err) done(err);
_Submission = { // _Submission = {
form_fields: [ // form_fields: [
{'fieldType':'textfield', 'title':'First Name', 'fieldValue': 'David'}, // {'fieldType':'textfield', 'title':'First Name', 'fieldValue': 'David'},
{'fieldType':'checkbox', 'title':'nascar', 'fieldValue': true}, // {'fieldType':'checkbox', 'title':'nascar', 'fieldValue': true},
{'fieldType':'checkbox', 'title':'hockey', 'fieldValue': false} // {'fieldType':'checkbox', 'title':'hockey', 'fieldValue': false}
], // ],
form: form._id, // form: form._id,
admin: user._id, // admin: user._id,
percentageComplete: 100, // percentageComplete: 100,
timeElapsed: 11.55 // timeElapsed: 11.55
}; // };
FormObj = form; // FormObj = form;
//Setup test session // //Setup test session
submissionSession = new Session(); // submissionSession = new Session();
done(); // done();
}); // });
}); // });
it('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 // //Create Submission
submissionSession.post('/forms/' + FormObj._id) // submissionSession.post('/forms/' + FormObj._id)
.send(_Submission) // .send(_Submission)
.expect(200) // .expect(200)
.end(function(err, res) { // .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) { // it('should be able to get Form Submissions if signed in', function(done) {
submissionSession.post('/auth/signin') // submissionSession.post('/auth/signin')
.send(credentials) // .send(credentials)
.expect('Content-Type', /json/) // .expect('Content-Type', /json/)
.expect(200) // .expect(200)
.end(function(signinErr, signinRes) { // .end(function(signinErr, signinRes) {
should.not.exist(signinErr); // should.not.exist(signinErr);
//Create Submission // //Create Submission
submissionSession.post('/forms/' + FormObj._id) // submissionSession.post('/forms/' + FormObj._id)
.send(_Submission) // .send(_Submission)
.expect(200) // .expect(200)
.end(function(err, res) { // .end(function(err, res) {
should.not.exist(err); // should.not.exist(err);
submissionSession.get('/forms/' + FormObj._id + '/submissions') // submissionSession.get('/forms/' + FormObj._id + '/submissions')
.expect('Content-Type', /json/) // .expect('Content-Type', /json/)
.expect(200) // .expect(200)
.end(function(err, res) { // .end(function(err, res) {
// Set assertion // // Set assertion
should.not.exist(err); // should.not.exist(err);
// Call the assertion callback // // Call the assertion callback
done(); // done();
}); // });
}); // });
}); // });
}); // });
it('should not be able to get Form Submissions if not signed in', function(done) { // it('should not be able to get Form Submissions if not signed in', function(done) {
// Attempt to fetch form submissions // // Attempt to fetch form submissions
submissionSession.get('/forms/' + FormObj._id + '/submissions') // submissionSession.get('/forms/' + FormObj._id + '/submissions')
.expect(401) // .expect(401)
.end(function(err, res) { // .end(function(err, res) {
// Set assertions // // Set assertions
(res.body.message).should.equal('User is not logged in'); // (res.body.message).should.equal('User is not logged in');
// Call the assertion callback // // Call the assertion callback
done(); // done();
}); // });
}); // });
it('should not be able to delete Form Submission if not signed in', function(done) { // it('should not be able to delete Form Submission if not signed in', function(done) {
var SubmissionObj = new FormSubmission(_Submission); // var SubmissionObj = new FormSubmission(_Submission);
SubmissionObj.save(function (err, submission) { // SubmissionObj.save(function (err, submission) {
should.not.exist(err); // should.not.exist(err);
var submission_ids = _.pluck([submission], '_id'); // var submission_ids = _.pluck([submission], '_id');
// Attempt to delete form submissions // // Attempt to delete form submissions
submissionSession.delete('/forms/' + FormObj._id + '/submissions') // submissionSession.delete('/forms/' + FormObj._id + '/submissions')
.send({deleted_submissions: submission_ids}) // .send({deleted_submissions: submission_ids})
.expect(401) // .expect(401)
.end(function(err, res) { // .end(function(err, res) {
// Set assertions // // Set assertions
should.not.exist(err); // should.not.exist(err);
(res.body.message).should.equal('User is not logged in'); // (res.body.message).should.equal('User is not logged in');
// Call the assertion callback // // Call the assertion callback
done(); // done();
}); // });
}); // });
}); // });
it('should be able to delete Form Submission if signed in', function(done) { // it('should be able to delete Form Submission if signed in', function(done) {
// Create new FormSubmission model instance // // Create new FormSubmission model instance
var SubmissionObj = new FormSubmission(_Submission); // var SubmissionObj = new FormSubmission(_Submission);
SubmissionObj.save(function (err, submission) { // SubmissionObj.save(function (err, submission) {
should.not.exist(err); // should.not.exist(err);
// Signin as user // // Signin as user
submissionSession.post('/auth/signin') // submissionSession.post('/auth/signin')
.send(credentials) // .send(credentials)
.expect('Content-Type', /json/) // .expect('Content-Type', /json/)
.expect(200) // .expect(200)
.end(function(signinErr, signinRes) { // .end(function(signinErr, signinRes) {
// Handle signin error // // Handle signin error
if (signinErr) done(signinErr); // if (signinErr) done(signinErr);
var submission_ids = _.pluck([submission], '_id'); // var submission_ids = _.pluck([submission], '_id');
//Delete form submissions // //Delete form submissions
submissionSession.delete('/forms/' + FormObj._id + '/submissions') // submissionSession.delete('/forms/' + FormObj._id + '/submissions')
.send({deleted_submissions: submission_ids}) // .send({deleted_submissions: submission_ids})
.expect(200) // .expect(200)
.end(function(err, res) { // .end(function(err, res) {
// Set assertions // // Set assertions
should.not.exist(err); // should.not.exist(err);
(res.text).should.equal('Form submissions successfully deleted'); // (res.text).should.equal('Form submissions successfully deleted');
// Call the assertion callback // // Call the assertion callback
done(); // done();
}); // });
}); // });
}); // });
}); // });
afterEach(function(done) {//logout current user if there is one // afterEach(function(done) {//logout current user if there is one
FormSubmission.remove().exec(function() { // FormSubmission.remove().exec(function() {
Form.remove().exec(function (err) { // Form.remove().exec(function (err) {
submissionSession.destroy(); // submissionSession.destroy();
done(); // done();
}); // });
}); // });
}); // });
}); // });
afterEach(function(done) { // afterEach(function(done) {
User.remove().exec(function() { // User.remove().exec(function() {
Form.remove().exec(done); // Form.remove().exec(done);
}); // });
}); // });
}); // });

View File

@ -1,90 +1,90 @@
'use strict'; // 'use strict';
/** // /**
* Module dependencies. // * Module dependencies.
*/ // */
var should = require('should'), // var should = require('should'),
mongoose = require('mongoose'), // mongoose = require('mongoose'),
User = mongoose.model('User'); // User = mongoose.model('User');
/** // /**
* Globals // * Globals
*/ // */
var user, user2; // var user, user2;
/** // /**
* Unit tests // * Unit tests
*/ // */
describe('User Model Unit Tests:', function() { // describe('User Model Unit Tests:', function() {
beforeEach(function(done) { // beforeEach(function(done) {
user = new User({ // user = new User({
firstName: 'Full', // firstName: 'Full',
lastName: 'Name', // lastName: 'Name',
email: 'test@test.com', // email: 'test@test.com',
username: 'test@test.com', // username: 'test@test.com',
password: 'password', // password: 'password',
provider: 'local' // provider: 'local'
}); // });
user2 = new User({ // user2 = new User({
firstName: 'Full', // firstName: 'Full',
lastName: 'Name', // lastName: 'Name',
email: 'test@test.com', // email: 'test@test.com',
username: 'test@test.com', // username: 'test@test.com',
password: 'password', // password: 'password',
provider: 'local' // provider: 'local'
}); // });
done(); // done();
}); // });
describe('Method Save', function() { // describe('Method Save', function() {
it('should begin with no users', function(done) { // it('should begin with no users', function(done) {
User.find({}, function(err, users) { // User.find({}, function(err, users) {
users.should.have.length(0); // users.should.have.length(0);
done(); // done();
}); // });
}); // });
it('should be able to save without problems', function(done) { // it('should be able to save without problems', function(done) {
user.save(done); // user.save(done);
}); // });
it('should fail to save an existing user again', function(done) { // it('should fail to save an existing user again', function(done) {
user.save(function() { // user.save(function() {
user2.save(function(err) { // user2.save(function(err) {
should.exist(err); // should.exist(err);
done(); // done();
}); // });
}); // });
}); // });
it('should be able to show an error when try to save without first name', function(done) { // it('should be able to show an error when try to save without first name', function(done) {
user.firstName = ''; // user.firstName = '';
return user.save(function(err) { // return user.save(function(err) {
should.exist(err); // should.exist(err);
done(); // done();
}); // });
}); // });
}); // });
describe('Method findUniqueUsername', function() { // describe('Method findUniqueUsername', function() {
beforeEach(function(done) { // beforeEach(function(done) {
User.find({}, function(err, users) { // User.find({}, function(err, users) {
users.should.have.length(0); // users.should.have.length(0);
user.save(done); // user.save(done);
}); // });
}); // });
it('should be able to find unique version of existing username without problems', function(done) { // it('should be able to find unique version of existing username without problems', function(done) {
User.findUniqueUsername(user.username, null, function (availableUsername) { // User.findUniqueUsername(user.username, null, function (availableUsername) {
availableUsername.should.not.equal(user.username); // availableUsername.should.not.equal(user.username);
done(); // done();
}); // });
}); // });
}); // });
afterEach(function(done) { // afterEach(function(done) {
User.remove().exec(done); // User.remove().exec(done);
}); // });
}); // });

View File

@ -1,118 +1,155 @@
// 'use strict'; 'use strict';
// var should = require('should'), var should = require('should'),
// _ = require('lodash'), _ = require('lodash'),
// app = require('../../server'), app = require('../../server'),
// request = require('supertest'), request = require('supertest'),
// Session = require('supertest-session')({ Session = require('supertest-session')({
// app: app app: app
// }), }),
// mongoose = require('mongoose'), mongoose = require('mongoose'),
// User = mongoose.model('User'), User = mongoose.model('User'),
// config = require('../../config/config'), config = require('../../config/config'),
// tmpUser = mongoose.model(config.tempUserCollection), tmpUser = mongoose.model(config.tempUserCollection),
// agent = request.agent(app), agent = request.agent(app),
// mailosaur = require('mailosaur')(config.mailosaur.key), url = require('url');
// mailbox = new mailosaur.Mailbox(config.mailosaur.mailbox_id);
// /** var mailosaur = require('mailosaur')(config.mailosaur.key),
// * Globals mailbox = new mailosaur.Mailbox(config.mailosaur.mailbox_id);
// */
// var credentials, _User, _Session;
// /** /**
// * Form routes tests * Globals
// */ */
// describe('User CRUD tests', function() { var credentials, _User, _Session;
// var userSession; /**
* Form routes tests
*/
describe('User CRUD tests', function() {
this.timeout(10000);
var userSession;
// beforeEach(function(done) { beforeEach(function(done) {
// //Initialize Session //Initialize Session
// userSession = new Session(); userSession = new Session();
// // Create user credentials // Create user credentials
// credentials = { credentials = {
// username: 'test@test.com', username: 'be1e58fb@mailosaur.in',
// password: 'password' password: 'password'
// }; };
// // Create a new user // Create a new user
// _User = { _User = {
// firstName: 'Full', firstName: 'Full',
// lastName: 'Name', lastName: 'Name',
// email: credentials.username, email: credentials.username,
// username: credentials.username, username: credentials.username,
// password: credentials.password, password: credentials.password,
// }; };
// console.info('config.mailosaur.mailbox_id: '+config.mailosaur.mailbox_id)
// done(); done();
// }); });
// it('should be able to create a temporary (non-activated) User', function(done) {
// userSession.post('/auth/signup')
// .send(_User)
// .expect(200)
// .end(function(FormSaveErr, FormSaveRes) {
// (FormSaveRes.text).should.equal('An email has been sent to you. Please check it to verify your account.');
// tmpUser.findOne({username: _User.username}, function (err, user) {
// should.not.exist(err);
// should.exist(user);
// console.log(user); describe('create, activate and confirm a User Account', function () {
var username = 'testActiveAccount.be1e58fb@mailosaur.in';
var link, activateToken;
// (_User.username).shoud.equal(user.username); it('should be able to create a temporary (non-activated) User', function(done) {
// (_User.firstName).shoud.equal(user.firstName); _User.email = _User.username = username;
// (_User.lastName).shoud.equal(user.lastName); userSession.post('/auth/signup')
.send(_User)
.expect(200)
.end(function(FormSaveErr, FormSaveRes) {
(FormSaveRes.text).should.equal('An email has been sent to you. Please check it to verify your account.');
// setTimeout(function() {
tmpUser.findOne({username: _User.username}, function (err, user) {
should.not.exist(err);
should.exist(user);
// // Call the assertion callback _User.username.should.equal(user.username);
// done(); _User.firstName.should.equal(user.firstName);
// }); _User.lastName.should.equal(user.lastName);
// });
// });
// it('should be able to create and activate/verify a User Account', function(done) { mailbox.getEmails(function(err, _emails) {
// credentials.username = _User.email = _User.username = 'testUserCreation.be1e58fb@mailosaur.in'; if(err) done(err);
var emails = _emails;
// userSession.post('/auth/signup')
// .send(_User)
// .expect(200)
// .end(function(FormSaveErr, FormSaveRes) {
// should.not.exist(FormSaveErr);
// (FormSaveRes.text).should.equal('An email has been sent to you. Please check it to verify your account.');
// mailbox.getEmails(_User.email,
// function(err, emails) {
// should.not.exist(err);
// email = emails[0];
// console.log(email); console.log('mailbox.getEmails:');
// done(); for(var i=0; i<emails.length; i++){
// // userSession.get('/auth/verify/'+token) console.log(emails[i].text.links);
// // .send(_User) }
// // .expect(200, 'User successfully verified')
// // .end(function (VerifyErr, VerifyRes) {
// // should.not.exist(VerifyErr);
// // }); var link = emails[0].text.links[0].href;
// } var activateToken = url.parse(link).hash.split('/').slice(-1)[0];
// );
// }); activateToken.should.equal(user.GENERATED_VERIFYING_URL);
// });
// afterEach(function(done) { done();
// User.remove().exec(function () { });
// tmpUser.remove().exec(function(){ });
// mailbox.deleteAllEmail(function (err, body) { // }, 1000);
// console.log(err); });
// userSession.destroy(); });
// });
// }); // it('should be able to activate/verify a User Account', function(done) {
// }); // _User.email = _User.username = username;
// }); // mailbox.getEmails(function(err, _emails) {
// }); // if(err) done(err);
// var emails = _emails;
// console.log('mailbox.getEmails:');
// console.log(emails[0].text.links);
// link = emails[0].text.links[0].href;
// activateToken = url.parse(link).hash.split('/').slice(-1)[0];
// userSession.get('/auth/verify/'+activateToken)
// .expect(200, 'User successfully verified')
// .end(function(VerifyErr, VerifyRes) {
// should.not.exist(VerifyErr);
// done();
// });
// });
// });
// it('should receive confirmation email after activating a User Account', function(done) {
// _User.email = _User.username = username;
// mailbox.getEmails(function(err, _emails) {
// if(err) done(err);
// var emails = _emails;
// console.log('mailbox.getEmails:');
// console.log(emails[0].text.links);
// var link = emails[0].text.links[0].href;
// var activateToken = url.parse(link).hash.split('/').slice(-1)[0];
// userSession.get('/auth/verify/'+activateToken)
// .expect(200, 'User successfully verified')
// .end(function(VerifyErr, VerifyRes) {
// should.not.exist(VerifyErr);
// done();
// });
// });
// });
});
afterEach(function(done) {
User.remove().exec(function () {
tmpUser.remove().exec(function(){
// mailbox.deleteAllEmail(function (err, body) {
// if(err) done(err);
userSession.destroy();
done();
// });
});
});
});
});

View File

@ -18,10 +18,10 @@ var _ = require('lodash'),
); );
//Load keys from api_keys.js if file exists //Load keys from api_keys.js if file exists
if( fs.existsSync('./env/api_keys.js') ){ if( fs.existsSync('./config/env/api_keys.js') ){
module.exports = _.merge( module.exports = _.extend(
exports, exports,
require('./env/api_keys') || {} require('./env/api_keys')
); );
}else { }else {
module.exports = exports; module.exports = exports;

View File

@ -55,7 +55,7 @@ module.exports = function(grunt) {
}, },
mochaTests: { mochaTests: {
files: watchFiles.mochaTests, files: watchFiles.mochaTests,
tasks: ['newer:test:server'], tasks: ['test:server'],
} }
}, },
jshint: { jshint: {

View File

@ -1,7 +1,7 @@
{ {
"name": "Medform", "name": "Medform",
"description": "PDF generated form builder", "description": "PDF generated form builder",
"version": "0.0.3", "version": "1.0.3",
"homepage": "https://github.com/whitef0x0/medform", "homepage": "https://github.com/whitef0x0/medform",
"authors": [ "authors": [
"David Baldwynn <polydaic@gmail.com>" "David Baldwynn <polydaic@gmail.com>"
@ -65,8 +65,6 @@
"method-override": "~2.3.0", "method-override": "~2.3.0",
"mocha": ">=1.20.0", "mocha": ">=1.20.0",
"mongoose": "~3.8.8", "mongoose": "~3.8.8",
"mongoose-datatable": "^1.0.2",
"mongoose-relationship": "^0.1.4",
"morgan": "~1.4.1", "morgan": "~1.4.1",
"multer": "~0.1.8", "multer": "~0.1.8",
"node-pdffiller": "~0.0.5", "node-pdffiller": "~0.0.5",
@ -82,6 +80,7 @@
"satelize": "~0.1.1", "satelize": "~0.1.1",
"shortid": "^2.2.2", "shortid": "^2.2.2",
"should": "~4.1.0", "should": "~4.1.0",
"soap": "^0.9.1",
"supertest": "~0.14.0", "supertest": "~0.14.0",
"supertest-session": "^1.0.0", "supertest-session": "^1.0.0",
"swig": "~1.4.1", "swig": "~1.4.1",

View File

@ -0,0 +1,8 @@
var soap = require('soap');
var url = 'http://example.com/wsdl?wsdl';
var args = {name: 'value'};
soap.createClient(url, function(err, client) {
client.MyFunction(args, function(err, result) {
console.log(result);
});
});