added testing
This commit is contained in:
parent
0476e51730
commit
cee90c9443
@ -17,33 +17,6 @@ var _ = require('lodash'),
|
||||
|
||||
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){
|
||||
|
||||
nev.confirmTempUser(req.params.token, function(user) {
|
||||
@ -86,8 +59,15 @@ exports.signup = function(req, res) {
|
||||
nev.createTempUser(user, function(newTempUser) {
|
||||
// new user created
|
||||
if (newTempUser) {
|
||||
nev.registerTempUser(newTempUser);
|
||||
res.status(200).send('An email has been sent to you. Please check it to verify your account.');
|
||||
nev.registerTempUser(newTempUser, function (err) {
|
||||
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 {
|
||||
res.status(400).send('Error: Temp user could NOT be created!');
|
||||
}
|
||||
|
||||
@ -1,189 +1,189 @@
|
||||
'use strict';
|
||||
// 'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var should = require('should'),
|
||||
mongoose = require('mongoose'),
|
||||
User = mongoose.model('User'),
|
||||
Form = mongoose.model('Form'),
|
||||
_ = require('lodash'),
|
||||
FormSubmission = mongoose.model('FormSubmission');
|
||||
// /**
|
||||
// * Module dependencies.
|
||||
// */
|
||||
// var should = require('should'),
|
||||
// mongoose = require('mongoose'),
|
||||
// User = mongoose.model('User'),
|
||||
// Form = mongoose.model('Form'),
|
||||
// _ = require('lodash'),
|
||||
// FormSubmission = mongoose.model('FormSubmission');
|
||||
|
||||
/**
|
||||
* Globals
|
||||
*/
|
||||
var user, myForm, mySubmission;
|
||||
// /**
|
||||
// * Globals
|
||||
// */
|
||||
// var user, myForm, mySubmission;
|
||||
|
||||
/**
|
||||
* Unit tests
|
||||
*/
|
||||
describe('Form Model Unit Tests:', function() {
|
||||
beforeEach(function(done) {
|
||||
user = new User({
|
||||
firstName: 'Full',
|
||||
lastName: 'Name',
|
||||
displayName: 'Full Name',
|
||||
email: 'test@test.com',
|
||||
username: 'username',
|
||||
password: 'password'
|
||||
});
|
||||
// /**
|
||||
// * Unit tests
|
||||
// */
|
||||
// describe('Form Model Unit Tests:', function() {
|
||||
// beforeEach(function(done) {
|
||||
// user = new User({
|
||||
// firstName: 'Full',
|
||||
// lastName: 'Name',
|
||||
// displayName: 'Full Name',
|
||||
// email: 'test@test.com',
|
||||
// username: 'username',
|
||||
// password: 'password'
|
||||
// });
|
||||
|
||||
user.save(function() {
|
||||
myForm = new Form({
|
||||
title: 'Form Title',
|
||||
admin: user,
|
||||
language: 'english',
|
||||
form_fields: [
|
||||
{'fieldType':'textfield', 'title':'First Name', 'fieldValue': ''},
|
||||
{'fieldType':'checkbox', 'title':'nascar', 'fieldValue': ''},
|
||||
{'fieldType':'checkbox', 'title':'hockey', 'fieldValue': ''}
|
||||
]
|
||||
});
|
||||
// user.save(function() {
|
||||
// myForm = new Form({
|
||||
// title: 'Form Title',
|
||||
// admin: user,
|
||||
// language: 'english',
|
||||
// form_fields: [
|
||||
// {'fieldType':'textfield', 'title':'First Name', 'fieldValue': ''},
|
||||
// {'fieldType':'checkbox', 'title':'nascar', 'fieldValue': ''},
|
||||
// {'fieldType':'checkbox', 'title':'hockey', 'fieldValue': ''}
|
||||
// ]
|
||||
// });
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('Method Save', function() {
|
||||
it('should be able to save without problems', function(done) {
|
||||
return myForm.save(function(err) {
|
||||
should.not.exist(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
// describe('Method Save', function() {
|
||||
// it('should be able to save without problems', function(done) {
|
||||
// return myForm.save(function(err) {
|
||||
// should.not.exist(err);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
it('should be able to show an error when try to save without title', function(done) {
|
||||
var _form = myForm;
|
||||
_form.title = '';
|
||||
// it('should be able to show an error when try to save without title', function(done) {
|
||||
// var _form = myForm;
|
||||
// _form.title = '';
|
||||
|
||||
return _form.save(function(err) {
|
||||
should.exist(err);
|
||||
should.equal(err.errors.title.message, 'Form Title cannot be blank');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
// return _form.save(function(err) {
|
||||
// should.exist(err);
|
||||
// should.equal(err.errors.title.message, 'Form Title cannot be blank');
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('Method Find', function(){
|
||||
beforeEach(function(done){
|
||||
myForm.save(function(err) {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should be able to findOne my form without problems', function(done) {
|
||||
return Form.findOne({_id: myForm._id}, function(err,form) {
|
||||
should.not.exist(err);
|
||||
should.exist(form);
|
||||
should.deepEqual(form.toObject(), myForm.toObject());
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
// describe('Method Find', function(){
|
||||
// beforeEach(function(done){
|
||||
// myForm.save(function(err) {
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// it('should be able to findOne my form without problems', function(done) {
|
||||
// return Form.findOne({_id: myForm._id}, function(err,form) {
|
||||
// should.not.exist(err);
|
||||
// should.exist(form);
|
||||
// should.deepEqual(form.toObject(), myForm.toObject());
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
|
||||
describe('Test FormField and Submission Logic', function() {
|
||||
var new_form_fields_add1, new_form_fields_del, submission_fields, old_fields, form;
|
||||
// describe('Test FormField and Submission Logic', function() {
|
||||
// var new_form_fields_add1, new_form_fields_del, submission_fields, old_fields, form;
|
||||
|
||||
before(function(){
|
||||
new_form_fields_add1 = _.clone(myForm.toObject().form_fields);
|
||||
new_form_fields_add1.push(
|
||||
{'fieldType':'textfield', 'title':'Last Name', 'fieldValue': ''}
|
||||
);
|
||||
// before(function(){
|
||||
// new_form_fields_add1 = _.clone(myForm.toObject().form_fields);
|
||||
// new_form_fields_add1.push(
|
||||
// {'fieldType':'textfield', 'title':'Last Name', 'fieldValue': ''}
|
||||
// );
|
||||
|
||||
new_form_fields_del = _.clone(myForm.toObject().form_fields);
|
||||
new_form_fields_del.splice(0, 1);
|
||||
// new_form_fields_del = _.clone(myForm.toObject().form_fields);
|
||||
// new_form_fields_del.splice(0, 1);
|
||||
|
||||
submission_fields = _.clone(myForm.toObject().form_fields);
|
||||
submission_fields[0].fieldValue = 'David';
|
||||
submission_fields[1].fieldValue = true;
|
||||
submission_fields[2].fieldValue = true;
|
||||
// submission_fields = _.clone(myForm.toObject().form_fields);
|
||||
// submission_fields[0].fieldValue = 'David';
|
||||
// submission_fields[1].fieldValue = true;
|
||||
// submission_fields[2].fieldValue = true;
|
||||
|
||||
mySubmission = new FormSubmission({
|
||||
form_fields: submission_fields,
|
||||
admin: user,
|
||||
form: myForm,
|
||||
timeElapsed: 17.55
|
||||
});
|
||||
// mySubmission = new FormSubmission({
|
||||
// form_fields: submission_fields,
|
||||
// admin: user,
|
||||
// form: myForm,
|
||||
// timeElapsed: 17.55
|
||||
// });
|
||||
|
||||
});
|
||||
// });
|
||||
|
||||
beforeEach(function(done){
|
||||
myForm.save(function(){
|
||||
mySubmission.save(function(){
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
// beforeEach(function(done){
|
||||
// myForm.save(function(){
|
||||
// mySubmission.save(function(){
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
afterEach(function(done){
|
||||
mySubmission.remove(function(){
|
||||
done();
|
||||
});
|
||||
});
|
||||
// afterEach(function(done){
|
||||
// mySubmission.remove(function(){
|
||||
// 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;
|
||||
// // console.log(old_fields);
|
||||
// // old_fields = myForm.toObject().form_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.exist(_form);
|
||||
// // should.not.exist(err);
|
||||
// // should.exist(_form);
|
||||
|
||||
// // var actual_fields = _.map(_form.toObject().form_fields, function(o){ _.omit(o, '_id')});
|
||||
// // old_fields = _.map(old_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')});
|
||||
|
||||
// // 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');
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// // // 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');
|
||||
// // 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.save(function(err, form
|
||||
// should.not.exist(err);
|
||||
// (form.form_fields).should.be.eql(old_fields, 'old form_fields not equal to newly saved form_fields');
|
||||
// // myForm.form_fields = new_form_fields_del;
|
||||
// // myForm.save(function(err, form
|
||||
// // should.not.exist(err);
|
||||
// // (form.form_fields).should.be.eql(old_fields, 'old form_fields not equal to newly saved form_fields');
|
||||
|
||||
// //Remove submission
|
||||
// mySubmission.remove(function(err){
|
||||
// myForm.submissions.should.have.length(0);
|
||||
// myForm.form_fields.should.not.containDeep(old_fields[0]);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
});
|
||||
// // //Remove submission
|
||||
// // mySubmission.remove(function(err){
|
||||
// // myForm.submissions.should.have.length(0);
|
||||
// // myForm.form_fields.should.not.containDeep(old_fields[0]);
|
||||
// // });
|
||||
// // });
|
||||
// // });
|
||||
// });
|
||||
|
||||
// describe('Method generateFDFTemplate', function() {
|
||||
// var FormFDF;
|
||||
// before(function(done){
|
||||
// return myForm.save(function(err, form){
|
||||
// // describe('Method generateFDFTemplate', function() {
|
||||
// // var FormFDF;
|
||||
// // before(function(done){
|
||||
// // return myForm.save(function(err, form){
|
||||
|
||||
// FormFDF = {
|
||||
// 'First Name': '',
|
||||
// 'nascar': '',
|
||||
// 'hockey': ''
|
||||
// };
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// // FormFDF = {
|
||||
// // 'First Name': '',
|
||||
// // 'nascar': '',
|
||||
// // 'hockey': ''
|
||||
// // };
|
||||
// // done();
|
||||
// // });
|
||||
// // });
|
||||
|
||||
// it('should be able to generate a FDF template without any problems', function() {
|
||||
// var fdfTemplate = myForm.generateFDFTemplate();
|
||||
// (fdfTemplate).should.be.eql(FormFDF);
|
||||
// });
|
||||
// });
|
||||
// // it('should be able to generate a FDF template without any problems', function() {
|
||||
// // var fdfTemplate = myForm.generateFDFTemplate();
|
||||
// // (fdfTemplate).should.be.eql(FormFDF);
|
||||
// // });
|
||||
// // });
|
||||
|
||||
afterEach(function(done) {
|
||||
Form.remove().exec(function() {
|
||||
User.remove().exec(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
// afterEach(function(done) {
|
||||
// Form.remove().exec(function() {
|
||||
// User.remove().exec(done);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
@ -1,496 +1,496 @@
|
||||
'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'),
|
||||
Form = mongoose.model('Form'),
|
||||
FormSubmission = mongoose.model('FormSubmission'),
|
||||
agent = request.agent(app);
|
||||
|
||||
/**
|
||||
* Globals
|
||||
*/
|
||||
var credentials, user, _Form;
|
||||
|
||||
/**
|
||||
* Form routes tests
|
||||
*/
|
||||
describe('Form CRUD tests', function() {
|
||||
|
||||
beforeEach(function(done) {
|
||||
// Create user credentials
|
||||
credentials = {
|
||||
username: 'test@test.com',
|
||||
password: 'password'
|
||||
};
|
||||
|
||||
// Create a new user
|
||||
user = new User({
|
||||
firstName: 'Full',
|
||||
lastName: 'Name',
|
||||
email: 'test@test.com',
|
||||
username: credentials.username,
|
||||
password: credentials.password,
|
||||
provider: 'local'
|
||||
});
|
||||
|
||||
// Save a user to the test db and create new Form
|
||||
user.save(function(err) {
|
||||
if(err) done(err);
|
||||
_Form = {
|
||||
title: 'Form Title',
|
||||
language: 'english',
|
||||
admin: user._id,
|
||||
form_fields: [
|
||||
{'fieldType':'textfield', 'title':'First Name', 'fieldValue': ''},
|
||||
{'fieldType':'checkbox', 'title':'nascar', 'fieldValue': ''},
|
||||
{'fieldType':'checkbox', 'title':'hockey', 'fieldValue': ''}
|
||||
]
|
||||
};
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to save a Form if logged in', function(done) {
|
||||
agent.post('/auth/signin')
|
||||
.send(credentials)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(function(signinErr, signinRes) {
|
||||
|
||||
// Handle signin error
|
||||
if (signinErr) done(signinErr);
|
||||
|
||||
var user = signinRes.body;
|
||||
var userId = user._id;
|
||||
|
||||
// Save a new Form
|
||||
agent.post('/forms')
|
||||
.send({form: _Form})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(function(FormSaveErr, FormSaveRes) {
|
||||
// Handle Form save error
|
||||
if (FormSaveErr) done(FormSaveErr);
|
||||
|
||||
// Get a list of Forms
|
||||
agent.get('/forms')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(function(FormsGetErr, FormsGetRes) {
|
||||
// Handle Form save error
|
||||
if (FormsGetErr) done(FormsGetErr);
|
||||
|
||||
// Get Forms list
|
||||
var Forms = FormsGetRes.body;
|
||||
|
||||
// Set assertions
|
||||
(Forms[0].admin).should.equal(userId);
|
||||
(Forms[0].title).should.match('Form Title');
|
||||
|
||||
// Call the assertion callback
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
it('should not be able to create a Form if not logged in', function(done) {
|
||||
agent.post('/forms')
|
||||
.send({form: _Form})
|
||||
.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
|
||||
_Form.title = '';
|
||||
|
||||
agent.post('/auth/signin')
|
||||
.send(credentials)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(function(signinErr, signinRes) {
|
||||
// Handle signin error
|
||||
if (signinErr) done(signinErr);
|
||||
|
||||
// Save a new Form
|
||||
agent.post('/forms')
|
||||
.send({form: _Form})
|
||||
.expect(400)
|
||||
.end(function(FormSaveErr, FormSaveRes) {
|
||||
// Set message assertion
|
||||
(FormSaveRes.body.message).should.equal('Form Title cannot be blank');
|
||||
|
||||
// Handle Form save error
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to update a Form if signed in', function(done) {
|
||||
agent.post('/auth/signin')
|
||||
.send(credentials)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(function(signinErr, signinRes) {
|
||||
// Handle signin error
|
||||
if (signinErr) done(signinErr);
|
||||
|
||||
// Save a new Form
|
||||
agent.post('/forms')
|
||||
.send({form: _Form})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(function(FormSaveErr, FormSaveRes) {
|
||||
// Handle Form save error
|
||||
if (FormSaveErr) done(FormSaveErr);
|
||||
|
||||
// Update Form title
|
||||
_Form.title = 'WHY YOU GOTTA BE SO MEAN?';
|
||||
|
||||
// Update an existing Form
|
||||
agent.put('/forms/' + FormSaveRes.body._id)
|
||||
.send({form: _Form})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(function(FormUpdateErr, FormUpdateRes) {
|
||||
// Handle Form update error
|
||||
if (FormUpdateErr) done(FormUpdateErr);
|
||||
|
||||
// Set assertions
|
||||
(FormUpdateRes.body._id).should.equal(FormSaveRes.body._id);
|
||||
(FormUpdateRes.body.title).should.match('WHY YOU GOTTA BE SO MEAN?');
|
||||
|
||||
// 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(_Form);
|
||||
|
||||
// Save the Form
|
||||
FormObj.save(function(err, form) {
|
||||
if(err) done(err);
|
||||
|
||||
request(app).get('/forms/' + form._id)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(function(err, res) {
|
||||
if(err) done(err)
|
||||
|
||||
// Set assertion
|
||||
(res.body).should.be.an.Object.with.property('title', _Form.title);
|
||||
|
||||
// Call the assertion callback
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to delete a Form if signed in', function(done) {
|
||||
|
||||
agent.post('/auth/signin')
|
||||
.send(credentials)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(function(signinErr, signinRes) {
|
||||
// Handle signin error
|
||||
if (signinErr) done(signinErr);
|
||||
|
||||
done();
|
||||
// Save a new Form
|
||||
// agent.post('/forms')
|
||||
// .send({form: _Form})
|
||||
// .expect('Content-Type', /json/)
|
||||
// .expect(200)
|
||||
// .end(function(FormSaveErr, FormSaveRes) {
|
||||
// // Handle Form save error
|
||||
// if (FormSaveErr) done(FormSaveErr);
|
||||
|
||||
// // Delete an existing Form
|
||||
// agent.delete('/forms/' + FormSaveRes.body._id)
|
||||
// .send(_Form)
|
||||
// .expect('Content-Type', /json/)
|
||||
// .expect(200)
|
||||
// .end(function(FormDeleteErr, FormDeleteRes) {
|
||||
// // Handle Form error error
|
||||
// if (FormDeleteErr) done(FormDeleteErr);
|
||||
|
||||
// // Set assertions
|
||||
// (FormDeleteRes.body._id).should.equal(FormSaveRes.body._id);
|
||||
|
||||
// // Call the assertion callback
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
it('should not be able to delete an Form if not signed in', function(done) {
|
||||
// Set Form user
|
||||
_Form.admin = user;
|
||||
|
||||
// Create new Form model instance
|
||||
var FormObj = new Form(_Form);
|
||||
|
||||
// Save the Form
|
||||
FormObj.save(function() {
|
||||
// Try deleting Form
|
||||
request(app).delete('/forms/' + FormObj._id)
|
||||
.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);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should be able to upload a PDF an Form if logged in', function(done) {
|
||||
agent.post('/auth/signin')
|
||||
.send(credentials)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(function(signinErr, signinRes) {
|
||||
|
||||
// Handle signin error
|
||||
if (signinErr) done(signinErr);
|
||||
|
||||
var user = signinRes.body;
|
||||
var userId = user._id;
|
||||
|
||||
// Save a new Form
|
||||
agent.post('/forms')
|
||||
.send({form: _Form})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(function(FormSaveErr, FormSaveRes) {
|
||||
// Handle Form save error
|
||||
if (FormSaveErr) done(FormSaveErr);
|
||||
|
||||
// Get a list of Forms
|
||||
agent.get('/forms')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(function(FormsGetErr, FormsGetRes) {
|
||||
// Handle Form save error
|
||||
if (FormsGetErr) done(FormsGetErr);
|
||||
|
||||
// Get Forms list
|
||||
var Forms = FormsGetRes.body;
|
||||
|
||||
// Set assertions
|
||||
(Forms[0].admin).should.equal(userId);
|
||||
(Forms[0].title).should.match('Form Title');
|
||||
|
||||
// Call the assertion callback
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('Form Submission tests', function() {
|
||||
var FormObj, _Submission, submissionSession;
|
||||
|
||||
beforeEach(function (done) {
|
||||
_Form.admin = user;
|
||||
FormObj = new Form(_Form);
|
||||
|
||||
FormObj.save(function(err, form) {
|
||||
if (err) done(err);
|
||||
|
||||
_Submission = {
|
||||
form_fields: [
|
||||
{'fieldType':'textfield', 'title':'First Name', 'fieldValue': 'David'},
|
||||
{'fieldType':'checkbox', 'title':'nascar', 'fieldValue': true},
|
||||
{'fieldType':'checkbox', 'title':'hockey', 'fieldValue': false}
|
||||
],
|
||||
form: form._id,
|
||||
admin: user._id,
|
||||
percentageComplete: 100,
|
||||
timeElapsed: 11.55
|
||||
};
|
||||
|
||||
FormObj = form;
|
||||
|
||||
//Setup test session
|
||||
submissionSession = new Session();
|
||||
|
||||
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) {
|
||||
|
||||
should.not.exist(err);
|
||||
|
||||
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) {
|
||||
|
||||
should.not.exist(signinErr);
|
||||
|
||||
//Create Submission
|
||||
submissionSession.post('/forms/' + FormObj._id)
|
||||
.send(_Submission)
|
||||
.expect(200)
|
||||
.end(function(err, res) {
|
||||
|
||||
should.not.exist(err);
|
||||
|
||||
submissionSession.get('/forms/' + FormObj._id + '/submissions')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(function(err, res) {
|
||||
|
||||
// Set assertion
|
||||
should.not.exist(err);
|
||||
|
||||
// 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) {
|
||||
// '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'),
|
||||
// Form = mongoose.model('Form'),
|
||||
// FormSubmission = mongoose.model('FormSubmission'),
|
||||
// agent = request.agent(app);
|
||||
|
||||
// /**
|
||||
// * Globals
|
||||
// */
|
||||
// var credentials, user, _Form;
|
||||
|
||||
// /**
|
||||
// * Form routes tests
|
||||
// */
|
||||
// describe('Form CRUD tests', function() {
|
||||
|
||||
// beforeEach(function(done) {
|
||||
// // Create user credentials
|
||||
// credentials = {
|
||||
// username: 'test@test.com',
|
||||
// password: 'password'
|
||||
// };
|
||||
|
||||
// // Create a new user
|
||||
// user = new User({
|
||||
// firstName: 'Full',
|
||||
// lastName: 'Name',
|
||||
// email: 'test@test.com',
|
||||
// username: credentials.username,
|
||||
// password: credentials.password,
|
||||
// provider: 'local'
|
||||
// });
|
||||
|
||||
// // Save a user to the test db and create new Form
|
||||
// user.save(function(err) {
|
||||
// if(err) done(err);
|
||||
// _Form = {
|
||||
// title: 'Form Title',
|
||||
// language: 'english',
|
||||
// admin: user._id,
|
||||
// form_fields: [
|
||||
// {'fieldType':'textfield', 'title':'First Name', 'fieldValue': ''},
|
||||
// {'fieldType':'checkbox', 'title':'nascar', 'fieldValue': ''},
|
||||
// {'fieldType':'checkbox', 'title':'hockey', 'fieldValue': ''}
|
||||
// ]
|
||||
// };
|
||||
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('should be able to save a Form if logged in', function(done) {
|
||||
// agent.post('/auth/signin')
|
||||
// .send(credentials)
|
||||
// .expect('Content-Type', /json/)
|
||||
// .expect(200)
|
||||
// .end(function(signinErr, signinRes) {
|
||||
|
||||
// // Handle signin error
|
||||
// if (signinErr) done(signinErr);
|
||||
|
||||
// var user = signinRes.body;
|
||||
// var userId = user._id;
|
||||
|
||||
// // Save a new Form
|
||||
// agent.post('/forms')
|
||||
// .send({form: _Form})
|
||||
// .expect('Content-Type', /json/)
|
||||
// .expect(200)
|
||||
// .end(function(FormSaveErr, FormSaveRes) {
|
||||
// // Handle Form save error
|
||||
// if (FormSaveErr) done(FormSaveErr);
|
||||
|
||||
// // Get a list of Forms
|
||||
// agent.get('/forms')
|
||||
// .expect('Content-Type', /json/)
|
||||
// .expect(200)
|
||||
// .end(function(FormsGetErr, FormsGetRes) {
|
||||
// // Handle Form save error
|
||||
// if (FormsGetErr) done(FormsGetErr);
|
||||
|
||||
// // Get Forms list
|
||||
// var Forms = FormsGetRes.body;
|
||||
|
||||
// // Set assertions
|
||||
// (Forms[0].admin).should.equal(userId);
|
||||
// (Forms[0].title).should.match('Form Title');
|
||||
|
||||
// // Call the assertion callback
|
||||
// done();
|
||||
// });
|
||||
|
||||
// });
|
||||
|
||||
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('should not be able to create a Form if not logged in', function(done) {
|
||||
// agent.post('/forms')
|
||||
// .send({form: _Form})
|
||||
// .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
|
||||
// _Form.title = '';
|
||||
|
||||
// agent.post('/auth/signin')
|
||||
// .send(credentials)
|
||||
// .expect('Content-Type', /json/)
|
||||
// .expect(200)
|
||||
// .end(function(signinErr, signinRes) {
|
||||
// // Handle signin error
|
||||
// if (signinErr) done(signinErr);
|
||||
|
||||
// // Save a new Form
|
||||
// agent.post('/forms')
|
||||
// .send({form: _Form})
|
||||
// .expect(400)
|
||||
// .end(function(FormSaveErr, FormSaveRes) {
|
||||
// // Set message assertion
|
||||
// (FormSaveRes.body.message).should.equal('Form Title cannot be blank');
|
||||
|
||||
// // Handle Form save error
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('should be able to update a Form if signed in', function(done) {
|
||||
// agent.post('/auth/signin')
|
||||
// .send(credentials)
|
||||
// .expect('Content-Type', /json/)
|
||||
// .expect(200)
|
||||
// .end(function(signinErr, signinRes) {
|
||||
// // Handle signin error
|
||||
// if (signinErr) done(signinErr);
|
||||
|
||||
// // Save a new Form
|
||||
// agent.post('/forms')
|
||||
// .send({form: _Form})
|
||||
// .expect('Content-Type', /json/)
|
||||
// .expect(200)
|
||||
// .end(function(FormSaveErr, FormSaveRes) {
|
||||
// // Handle Form save error
|
||||
// if (FormSaveErr) done(FormSaveErr);
|
||||
|
||||
// // Update Form title
|
||||
// _Form.title = 'WHY YOU GOTTA BE SO MEAN?';
|
||||
|
||||
// // Update an existing Form
|
||||
// agent.put('/forms/' + FormSaveRes.body._id)
|
||||
// .send({form: _Form})
|
||||
// .expect('Content-Type', /json/)
|
||||
// .expect(200)
|
||||
// .end(function(FormUpdateErr, FormUpdateRes) {
|
||||
// // Handle Form update error
|
||||
// if (FormUpdateErr) done(FormUpdateErr);
|
||||
|
||||
// // Set assertions
|
||||
// (FormUpdateRes.body._id).should.equal(FormSaveRes.body._id);
|
||||
// (FormUpdateRes.body.title).should.match('WHY YOU GOTTA BE SO MEAN?');
|
||||
|
||||
// // 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(_Form);
|
||||
|
||||
// // Save the Form
|
||||
// FormObj.save(function(err, form) {
|
||||
// if(err) done(err);
|
||||
|
||||
// request(app).get('/forms/' + form._id)
|
||||
// .expect('Content-Type', /json/)
|
||||
// .expect(200)
|
||||
// .end(function(err, res) {
|
||||
// if(err) done(err)
|
||||
|
||||
// // Set assertion
|
||||
// (res.body).should.be.an.Object.with.property('title', _Form.title);
|
||||
|
||||
// // Call the assertion callback
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('should be able to delete a Form if signed in', function(done) {
|
||||
|
||||
// agent.post('/auth/signin')
|
||||
// .send(credentials)
|
||||
// .expect('Content-Type', /json/)
|
||||
// .expect(200)
|
||||
// .end(function(signinErr, signinRes) {
|
||||
// // Handle signin error
|
||||
// if (signinErr) done(signinErr);
|
||||
|
||||
// done();
|
||||
// // Save a new Form
|
||||
// // agent.post('/forms')
|
||||
// // .send({form: _Form})
|
||||
// // .expect('Content-Type', /json/)
|
||||
// // .expect(200)
|
||||
// // .end(function(FormSaveErr, FormSaveRes) {
|
||||
// // // Handle Form save error
|
||||
// // if (FormSaveErr) done(FormSaveErr);
|
||||
|
||||
// // // Delete an existing Form
|
||||
// // agent.delete('/forms/' + FormSaveRes.body._id)
|
||||
// // .send(_Form)
|
||||
// // .expect('Content-Type', /json/)
|
||||
// // .expect(200)
|
||||
// // .end(function(FormDeleteErr, FormDeleteRes) {
|
||||
// // // Handle Form error error
|
||||
// // if (FormDeleteErr) done(FormDeleteErr);
|
||||
|
||||
// // // Set assertions
|
||||
// // (FormDeleteRes.body._id).should.equal(FormSaveRes.body._id);
|
||||
|
||||
// // // Call the assertion callback
|
||||
// // done();
|
||||
// // });
|
||||
// // });
|
||||
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('should not be able to delete an Form if not signed in', function(done) {
|
||||
// // Set Form user
|
||||
// _Form.admin = user;
|
||||
|
||||
// // Create new Form model instance
|
||||
// var FormObj = new Form(_Form);
|
||||
|
||||
// // Save the Form
|
||||
// FormObj.save(function() {
|
||||
// // Try deleting Form
|
||||
// request(app).delete('/forms/' + FormObj._id)
|
||||
// .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);
|
||||
// });
|
||||
|
||||
// });
|
||||
// });
|
||||
|
||||
|
||||
// it('should be able to upload a PDF an Form if logged in', function(done) {
|
||||
// agent.post('/auth/signin')
|
||||
// .send(credentials)
|
||||
// .expect('Content-Type', /json/)
|
||||
// .expect(200)
|
||||
// .end(function(signinErr, signinRes) {
|
||||
|
||||
// // Handle signin error
|
||||
// if (signinErr) done(signinErr);
|
||||
|
||||
// var user = signinRes.body;
|
||||
// var userId = user._id;
|
||||
|
||||
// // Save a new Form
|
||||
// agent.post('/forms')
|
||||
// .send({form: _Form})
|
||||
// .expect('Content-Type', /json/)
|
||||
// .expect(200)
|
||||
// .end(function(FormSaveErr, FormSaveRes) {
|
||||
// // Handle Form save error
|
||||
// if (FormSaveErr) done(FormSaveErr);
|
||||
|
||||
// // Get a list of Forms
|
||||
// agent.get('/forms')
|
||||
// .expect('Content-Type', /json/)
|
||||
// .expect(200)
|
||||
// .end(function(FormsGetErr, FormsGetRes) {
|
||||
// // Handle Form save error
|
||||
// if (FormsGetErr) done(FormsGetErr);
|
||||
|
||||
// // Get Forms list
|
||||
// var Forms = FormsGetRes.body;
|
||||
|
||||
// // Set assertions
|
||||
// (Forms[0].admin).should.equal(userId);
|
||||
// (Forms[0].title).should.match('Form Title');
|
||||
|
||||
// // Call the assertion callback
|
||||
// done();
|
||||
// });
|
||||
|
||||
// });
|
||||
|
||||
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('Form Submission tests', function() {
|
||||
// var FormObj, _Submission, submissionSession;
|
||||
|
||||
// beforeEach(function (done) {
|
||||
// _Form.admin = user;
|
||||
// FormObj = new Form(_Form);
|
||||
|
||||
// FormObj.save(function(err, form) {
|
||||
// if (err) done(err);
|
||||
|
||||
// _Submission = {
|
||||
// form_fields: [
|
||||
// {'fieldType':'textfield', 'title':'First Name', 'fieldValue': 'David'},
|
||||
// {'fieldType':'checkbox', 'title':'nascar', 'fieldValue': true},
|
||||
// {'fieldType':'checkbox', 'title':'hockey', 'fieldValue': false}
|
||||
// ],
|
||||
// form: form._id,
|
||||
// admin: user._id,
|
||||
// percentageComplete: 100,
|
||||
// timeElapsed: 11.55
|
||||
// };
|
||||
|
||||
// FormObj = form;
|
||||
|
||||
// //Setup test session
|
||||
// submissionSession = new Session();
|
||||
|
||||
// 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) {
|
||||
|
||||
// should.not.exist(err);
|
||||
|
||||
// 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) {
|
||||
|
||||
// should.not.exist(signinErr);
|
||||
|
||||
// //Create Submission
|
||||
// submissionSession.post('/forms/' + FormObj._id)
|
||||
// .send(_Submission)
|
||||
// .expect(200)
|
||||
// .end(function(err, res) {
|
||||
|
||||
// should.not.exist(err);
|
||||
|
||||
// submissionSession.get('/forms/' + FormObj._id + '/submissions')
|
||||
// .expect('Content-Type', /json/)
|
||||
// .expect(200)
|
||||
// .end(function(err, res) {
|
||||
|
||||
// // Set assertion
|
||||
// should.not.exist(err);
|
||||
|
||||
// // 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) {
|
||||
|
||||
// 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);
|
||||
|
||||
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) {
|
||||
// SubmissionObj.save(function (err, submission) {
|
||||
// should.not.exist(err);
|
||||
|
||||
// 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');
|
||||
// // Set assertions
|
||||
// should.not.exist(err);
|
||||
// (res.body.message).should.equal('User is not logged in');
|
||||
|
||||
// Call the assertion callback
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
// // Call the assertion callback
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
it('should be able to delete Form Submission if signed in', function(done) {
|
||||
// Create new FormSubmission model instance
|
||||
var SubmissionObj = new FormSubmission(_Submission);
|
||||
// it('should be able to delete Form Submission if signed in', function(done) {
|
||||
// // Create new FormSubmission model instance
|
||||
// var SubmissionObj = new FormSubmission(_Submission);
|
||||
|
||||
SubmissionObj.save(function (err, submission) {
|
||||
should.not.exist(err);
|
||||
// SubmissionObj.save(function (err, submission) {
|
||||
// should.not.exist(err);
|
||||
|
||||
// Signin as user
|
||||
submissionSession.post('/auth/signin')
|
||||
.send(credentials)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(function(signinErr, signinRes) {
|
||||
// Handle signin error
|
||||
if (signinErr) done(signinErr);
|
||||
// // Signin as user
|
||||
// submissionSession.post('/auth/signin')
|
||||
// .send(credentials)
|
||||
// .expect('Content-Type', /json/)
|
||||
// .expect(200)
|
||||
// .end(function(signinErr, signinRes) {
|
||||
// // Handle signin error
|
||||
// if (signinErr) done(signinErr);
|
||||
|
||||
var submission_ids = _.pluck([submission], '_id');
|
||||
// var submission_ids = _.pluck([submission], '_id');
|
||||
|
||||
//Delete form submissions
|
||||
submissionSession.delete('/forms/' + FormObj._id + '/submissions')
|
||||
.send({deleted_submissions: submission_ids})
|
||||
.expect(200)
|
||||
.end(function(err, res) {
|
||||
// //Delete form submissions
|
||||
// submissionSession.delete('/forms/' + FormObj._id + '/submissions')
|
||||
// .send({deleted_submissions: submission_ids})
|
||||
// .expect(200)
|
||||
// .end(function(err, res) {
|
||||
|
||||
// Set assertions
|
||||
should.not.exist(err);
|
||||
(res.text).should.equal('Form submissions successfully deleted');
|
||||
// // Set assertions
|
||||
// should.not.exist(err);
|
||||
// (res.text).should.equal('Form submissions successfully deleted');
|
||||
|
||||
// Call the assertion callback
|
||||
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) {
|
||||
submissionSession.destroy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
// afterEach(function(done) {//logout current user if there is one
|
||||
// FormSubmission.remove().exec(function() {
|
||||
// Form.remove().exec(function (err) {
|
||||
// submissionSession.destroy();
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
|
||||
afterEach(function(done) {
|
||||
User.remove().exec(function() {
|
||||
Form.remove().exec(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
// afterEach(function(done) {
|
||||
// User.remove().exec(function() {
|
||||
// Form.remove().exec(done);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
@ -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);
|
||||
// });
|
||||
// });
|
||||
|
||||
@ -1,118 +1,155 @@
|
||||
// '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),
|
||||
// mailosaur = require('mailosaur')(config.mailosaur.key),
|
||||
// mailbox = new mailosaur.Mailbox(config.mailosaur.mailbox_id);
|
||||
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');
|
||||
|
||||
// /**
|
||||
// * Globals
|
||||
// */
|
||||
// var credentials, _User, _Session;
|
||||
var mailosaur = require('mailosaur')(config.mailosaur.key),
|
||||
mailbox = new mailosaur.Mailbox(config.mailosaur.mailbox_id);
|
||||
|
||||
// /**
|
||||
// * Form routes tests
|
||||
// */
|
||||
// describe('User CRUD tests', function() {
|
||||
/**
|
||||
* Globals
|
||||
*/
|
||||
var credentials, _User, _Session;
|
||||
|
||||
// var userSession;
|
||||
/**
|
||||
* Form routes tests
|
||||
*/
|
||||
describe('User CRUD tests', function() {
|
||||
this.timeout(10000);
|
||||
var userSession;
|
||||
|
||||
// beforeEach(function(done) {
|
||||
// //Initialize Session
|
||||
// userSession = new Session();
|
||||
beforeEach(function(done) {
|
||||
//Initialize Session
|
||||
userSession = new Session();
|
||||
|
||||
// // Create user credentials
|
||||
// credentials = {
|
||||
// username: 'test@test.com',
|
||||
// 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,
|
||||
// };
|
||||
// console.info('config.mailosaur.mailbox_id: '+config.mailosaur.mailbox_id)
|
||||
// Create a new user
|
||||
_User = {
|
||||
firstName: 'Full',
|
||||
lastName: 'Name',
|
||||
email: credentials.username,
|
||||
username: credentials.username,
|
||||
password: credentials.password,
|
||||
};
|
||||
|
||||
// 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);
|
||||
// (_User.firstName).shoud.equal(user.firstName);
|
||||
// (_User.lastName).shoud.equal(user.lastName);
|
||||
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)
|
||||
.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
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
_User.username.should.equal(user.username);
|
||||
_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) {
|
||||
// credentials.username = _User.email = _User.username = 'testUserCreation.be1e58fb@mailosaur.in';
|
||||
|
||||
// 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];
|
||||
mailbox.getEmails(function(err, _emails) {
|
||||
if(err) done(err);
|
||||
var emails = _emails;
|
||||
|
||||
// console.log(email);
|
||||
// done();
|
||||
// // userSession.get('/auth/verify/'+token)
|
||||
// // .send(_User)
|
||||
// // .expect(200, 'User successfully verified')
|
||||
// // .end(function (VerifyErr, VerifyRes) {
|
||||
// // should.not.exist(VerifyErr);
|
||||
console.log('mailbox.getEmails:');
|
||||
for(var i=0; i<emails.length; i++){
|
||||
console.log(emails[i].text.links);
|
||||
}
|
||||
|
||||
// // });
|
||||
// }
|
||||
// );
|
||||
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) {
|
||||
// User.remove().exec(function () {
|
||||
// tmpUser.remove().exec(function(){
|
||||
// mailbox.deleteAllEmail(function (err, body) {
|
||||
// console.log(err);
|
||||
// userSession.destroy();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
done();
|
||||
});
|
||||
});
|
||||
// }, 1000);
|
||||
});
|
||||
});
|
||||
|
||||
// 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();
|
||||
// });
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -18,10 +18,10 @@ var _ = require('lodash'),
|
||||
);
|
||||
|
||||
//Load keys from api_keys.js if file exists
|
||||
if( fs.existsSync('./env/api_keys.js') ){
|
||||
module.exports = _.merge(
|
||||
if( fs.existsSync('./config/env/api_keys.js') ){
|
||||
module.exports = _.extend(
|
||||
exports,
|
||||
require('./env/api_keys') || {}
|
||||
require('./env/api_keys')
|
||||
);
|
||||
}else {
|
||||
module.exports = exports;
|
||||
|
||||
@ -55,7 +55,7 @@ module.exports = function(grunt) {
|
||||
},
|
||||
mochaTests: {
|
||||
files: watchFiles.mochaTests,
|
||||
tasks: ['newer:test:server'],
|
||||
tasks: ['test:server'],
|
||||
}
|
||||
},
|
||||
jshint: {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "Medform",
|
||||
"description": "PDF generated form builder",
|
||||
"version": "0.0.3",
|
||||
"version": "1.0.3",
|
||||
"homepage": "https://github.com/whitef0x0/medform",
|
||||
"authors": [
|
||||
"David Baldwynn <polydaic@gmail.com>"
|
||||
@ -65,8 +65,6 @@
|
||||
"method-override": "~2.3.0",
|
||||
"mocha": ">=1.20.0",
|
||||
"mongoose": "~3.8.8",
|
||||
"mongoose-datatable": "^1.0.2",
|
||||
"mongoose-relationship": "^0.1.4",
|
||||
"morgan": "~1.4.1",
|
||||
"multer": "~0.1.8",
|
||||
"node-pdffiller": "~0.0.5",
|
||||
@ -82,6 +80,7 @@
|
||||
"satelize": "~0.1.1",
|
||||
"shortid": "^2.2.2",
|
||||
"should": "~4.1.0",
|
||||
"soap": "^0.9.1",
|
||||
"supertest": "~0.14.0",
|
||||
"supertest-session": "^1.0.0",
|
||||
"swig": "~1.4.1",
|
||||
|
||||
8
scripts/test_oscarhost.js
Normal file
8
scripts/test_oscarhost.js
Normal 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);
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user