From 943c0c8188cb25752a4357df94d0a51d9d846431 Mon Sep 17 00:00:00 2001 From: David Baldwynn Date: Sat, 12 Sep 2015 13:19:21 -0700 Subject: [PATCH 1/4] fixed css bugs --- app/models/form.server.model.js | 18 ++++++++-------- app/models/logic_jump.server.model.js | 11 ++++------ docs/testing_feedback_Sep12.md | 31 +++++++++++++++++++++++++++ public/modules/core/css/core.css | 4 ++++ 4 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 docs/testing_feedback_Sep12.md diff --git a/app/models/form.server.model.js b/app/models/form.server.model.js index 00c21aa6..20bcd89e 100644 --- a/app/models/form.server.model.js +++ b/app/models/form.server.model.js @@ -17,7 +17,7 @@ var mongoose = require('mongoose'), var FieldSchema = require('./form_field.server.model.js'), FormSubmissionSchema = require('./form_submission.server.model.js'), Field = mongoose.model('Field', FieldSchema), - FormSubmission = mongoose.model('FormSubmission', FormSubmissionSchema) + FormSubmission = mongoose.model('FormSubmission', FormSubmissionSchema); var ButtonSchema = new Schema({ url: { @@ -41,7 +41,7 @@ var ButtonSchema = new Schema({ /** * Form Schema */ -var LogicJumpSchema = new Schema({ +var FormSchema = new Schema({ created: { type: Date, default: Date.now @@ -144,7 +144,7 @@ var LogicJumpSchema = new Schema({ //Delete template PDF of current Form -LogicJumpSchema.pre('remove', function (next) { +FormSchema.pre('remove', function (next) { if(this.pdf && process.env.NODE_ENV === 'development'){ //Delete template form fs.unlink(this.pdf.path, function(err){ @@ -157,7 +157,7 @@ LogicJumpSchema.pre('remove', function (next) { var _original; //Set _original -LogicJumpSchema.pre('save', function (next) { +FormSchema.pre('save', function (next) { // console.log(this.constructor.model); // console.log(FormModel); this.constructor // ≈ mongoose.model('…', FieldSchema).findById @@ -175,7 +175,7 @@ LogicJumpSchema.pre('save', function (next) { }); //Update lastModified and created everytime we save -LogicJumpSchema.pre('save', function (next) { +FormSchema.pre('save', function (next) { var now = new Date(); this.lastModified = now; if( !this.created ){ @@ -198,7 +198,7 @@ function getDeletedIndexes(needle, haystack){ } //Move PDF to permanent location after new template is uploaded -LogicJumpSchema.pre('save', function (next) { +FormSchema.pre('save', function (next) { if(this.pdf){ var that = this; async.series([ @@ -311,7 +311,7 @@ LogicJumpSchema.pre('save', function (next) { next(); }); -LogicJumpSchema.pre('save', function (next) { +FormSchema.pre('save', function (next) { // var _original = this._original; // console.log('_original\n------------'); // console.log(_original); @@ -445,7 +445,7 @@ LogicJumpSchema.pre('save', function (next) { } }); -// LogicJumpSchema.methods.generateFDFTemplate = function() { +// FormSchema.methods.generateFDFTemplate = function() { // var _keys = _.pluck(this.form_fields, 'title'), // _values = _.pluck(this.form_fields, 'fieldValue'); @@ -462,4 +462,4 @@ LogicJumpSchema.pre('save', function (next) { // return jsonObj; // }; - mongoose.model('LogicJump', LogicJumpSchema); + mongoose.model('Form', FormSchema); diff --git a/app/models/logic_jump.server.model.js b/app/models/logic_jump.server.model.js index 0c35a8d8..598b658c 100644 --- a/app/models/logic_jump.server.model.js +++ b/app/models/logic_jump.server.model.js @@ -6,9 +6,7 @@ var mongoose = require('mongoose'), Schema = mongoose.Schema, _ = require('lodash'), - tree = require('mongoose-tree'), - math = require('math'), - deasync = require('fibers'); + math = require('math'); var BooleanExpresssionSchema = new Schema({ @@ -40,7 +38,6 @@ BooleanExpresssionSchema.methods.evaluate = function(){ headNode.traverse(function (node, path, parent) { if(node.type === 'SymbolNode'){ - Fiber() mongoose.model('Field') .findOne({_id: node.name}).exec(function(err, field){ if(err) { @@ -59,14 +56,14 @@ BooleanExpresssionSchema.methods.evaluate = function(){ } }); - var code = node.compile(); + var code = headNode.compile(); var result = code.eval(expressionScope); this.result = result; return result; -}); +}; -mongoose.model('BooleanStatement', BooleanStatementSchema); +mongoose.model('BooleanExpresssion', BooleanExpresssionSchema); /** * Form Schema diff --git a/docs/testing_feedback_Sep12.md b/docs/testing_feedback_Sep12.md new file mode 100644 index 00000000..f001d0ff --- /dev/null +++ b/docs/testing_feedback_Sep12.md @@ -0,0 +1,31 @@ +##Tester 1: Justin Crosby + Browser: Chrome + Resolution: 1920x1080 + OS: Windows 10 + + +Landing Page: + Horizontal Scroll Bar Bug +create new form view (in listForms): + name field input is outside the red box + languages aren't capitalized + name field should be right next to label to be consistent + +Admin Form View + it says drag and drop fields but there's no drag and drop, have to click + DropdownList Rendering Problems (see justin_testing2.jpg) + + +##Tester2: Evan Moore + Browser: FB Messenger Browser (Webkit) + Phone: iPhone 5 + + Well first thing I see is that some of the fields are compressed kinda weird on my iPhone (see evan_testing1.jpg) + + And the settings button at the top right is a little hard to make out any of the detail, but that's a pretty minor fix + + When I try to change the title of one of the fields, it bugs out quite a bit too + + Like it seems to be trying to update the info before I've finished typing + + diff --git a/public/modules/core/css/core.css b/public/modules/core/css/core.css index bd98ab4a..f45cfa81 100755 --- a/public/modules/core/css/core.css +++ b/public/modules/core/css/core.css @@ -1,3 +1,7 @@ +body { + overflow-x: hidden; +} + /*Navbar Custom CSS*/ .navbar-inverse { background-color:#fafafa; From 8baf9296a20d5f8fdff32eb71ed6c5a108156209 Mon Sep 17 00:00:00 2001 From: David Baldwynn Date: Sat, 12 Sep 2015 13:23:34 -0700 Subject: [PATCH 2/4] fixed node --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 0aebcc0d..cbe567cc 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "lodash": "~2.4.1", "mailosaur": "^1.0.1", "main-bower-files": "~2.8.2", + "math": "0.0.3", "method-override": "~2.3.0", "mocha": ">=1.20.0", "mongoose": "~3.8.8", From dee6945d88f4d802edfa985af4ec7f644de67bcf Mon Sep 17 00:00:00 2001 From: David Baldwynn Date: Sat, 12 Sep 2015 13:37:41 -0700 Subject: [PATCH 3/4] removed node-rules --- app/controllers/core.server.controller.js | 4 +- app/tests/rules.server.test.js | 324 ---------------------- 2 files changed, 2 insertions(+), 326 deletions(-) delete mode 100644 app/tests/rules.server.test.js diff --git a/app/controllers/core.server.controller.js b/app/controllers/core.server.controller.js index 6ce80a78..650cfc8a 100755 --- a/app/controllers/core.server.controller.js +++ b/app/controllers/core.server.controller.js @@ -1,8 +1,8 @@ 'use strict'; -var raven = require('raven'); +// var raven = require('raven'); var config = require('../../config/config'); -var client = new raven.Client(config.DSN); +// var client = new raven.Client(config.DSN); /** diff --git a/app/tests/rules.server.test.js b/app/tests/rules.server.test.js deleted file mode 100644 index 60b06054..00000000 --- a/app/tests/rules.server.test.js +++ /dev/null @@ -1,324 +0,0 @@ -var RuleEngine = require('node-rules'), - should = require('should'), - rules = require('../../docs/Node-Rules/rules.logic-jump'); - -describe('Logic-Jump Rules Tests', function() { - - - describe('StringRules', function(){ - describe('Contains Rule', function(){ - it('should be TRUTHY if right IS a substring of left', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.StringRules.Contains); - - //sample fact to run the rules on - var fact = { - left:"userblahblahnamenaoeuaoe", - right:"user", - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(true); - done(); - }); - }); - it('should be FALSEY if right IS NOT a substring of left', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.StringRules.Contains); - - //sample fact to run the rules on - var fact = { - left:"userblahblahnamenaoeuaoe", - right:"user1", - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(false); - done(); - }); - }); - }); - - describe('NotContains Rule', function(){ - it('should be TRUTHY if right IS NOT a substring of left', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.StringRules.NotContains); - - //sample fact to run the rules on - var fact = { - "left":"userblahblahnamenaoeuaoe", - "right":"user1oe", - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(true); - done(); - }); - }); - it('should be FALSEY if right IS a substring of left', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.StringRules.NotContains); - - //sample fact to run the rules on - var fact = { - "left":"userblahblahnamenaoeuaoe", - "right":"user", - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(false); - done(); - }); - }); - }); - - describe('BeginsWith Rule', function(){ - it('should be TRUTHY if Left string DOES begin with Right', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.StringRules.BeginsWith); - - //sample fact to run the rules on - var fact = { - "left":"userblahblahnamenaoeuaoe", - "right":"user", - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(true); - done(); - }); - }); - it('should be FALSEY if left DOES NOT begin with right', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.StringRules.BeginsWith); - - //sample fact to run the rules on - var fact = { - "left":"userblahblahnamenaoeuaoe", - "right":"euaoe", - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(false); - done(); - }); - }); - }); - - describe('EndsWith Rule', function(){ - it('should be TRUTHY if Left string DOES end with Right', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.StringRules.EndsWith); - - //sample fact to run the rules on - var fact = { - "left":"userblahblahnamenaoeuaoe", - "right":"euaoe", - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(true); - done(); - }); - }); - it('should be FALSEY if left DOES NOT end with right', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.StringRules.EndsWith); - - //sample fact to run the rules on - var fact = { - "left":"userblahblahnamenaoeuaoe", - "right":"userb", - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(false); - done(); - }); - }); - }); - }); - - describe('NumberRules', function(){ - describe('GreaterThan Rule', function(){ - it('NumberRules.GreaterThan rule should be TRUTHY if left > right', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.NumberRules.GreaterThan); - - //sample fact to run the rules on - var fact = { - left:100, - right:5, - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(true); - done(); - }); - }); - it('NumberRules.GreaterThan rule should be FALSEY if left < right', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.NumberRules.GreaterThan); - - //sample fact to run the rules on - var fact = { - left:100, - right:1000, - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(false); - done(); - }); - }); - }); - - describe('SmallerThan Rule', function(){ - it('should be TRUTHY if left < right', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.NumberRules.SmallerThan); - - //sample fact to run the rules on - var fact = { - left:100, - right:1000, - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(true); - done(); - }); - }); - it('should be FALSEY if left > right', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.NumberRules.SmallerThan); - - //sample fact to run the rules on - var fact = { - left:100, - right:5, - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(false); - done(); - }); - }); - }); - - describe('GreaterThanOrEqual Rule', function(){ - it('should be TRUTHY if left == right', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.NumberRules.GreaterThanOrEqual); - - //sample fact to run the rules on - var fact = { - left:100, - right:100, - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(true); - done(); - }); - }); - it('should be TRUTHY if left > right', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.NumberRules.GreaterThanOrEqual); - - //sample fact to run the rules on - var fact = { - left:100, - right:5, - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(true); - done(); - }); - }); - it('should be FALSEY if left < right', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.NumberRules.GreaterThanOrEqual); - - //sample fact to run the rules on - var fact = { - left:100, - right:1000, - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(false); - done(); - }); - }); - }); - - describe('SmallerThanOrEqual Rule', function(){ - it('should be TRUTHY if left === right', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.NumberRules.SmallerThanOrEqual); - - //sample fact to run the rules on - var fact = { - left:100, - right:100, - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(true); - done(); - }); - }); - it('should be FALSEY if left > right', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.NumberRules.SmallerThanOrEqual); - - //sample fact to run the rules on - var fact = { - left:100, - right:5, - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(false); - done(); - }); - }); - it('should be TRUTHY if left < right', function(done){ - //initialize the rule engine - R = new RuleEngine(rules.NumberRules.SmallerThanOrEqual); - - //sample fact to run the rules on - var fact = { - left:100, - right:1000, - }; - - //Now pass the fact on to the rule engine for results - R.execute(fact,function(result){ - result.result.should.equal(true); - done(); - }); - }); - }); - - }); -}); \ No newline at end of file From 8b8aed337e128b245ac7c2fe04299df4c605c994 Mon Sep 17 00:00:00 2001 From: David Baldwynn Date: Tue, 15 Sep 2015 15:21:49 -0700 Subject: [PATCH 4/4] fixed login/signup bug --- app/controllers/forms.server.controller.js | 41 ++-- .../users.authentication.server.controller.js | 47 ++-- app/models/form_submission.server.model.js | 4 - app/tests/user.server.routes.test.js | 202 ++++++++++-------- .../forms/config/forms.client.routes.js | 17 +- .../admin-form.client.controller.js | 12 +- .../edit-submissions-form.client.directive.js | 7 +- .../directives/entry_page.client.directive.js | 47 ++++ .../directives/field.client.directive.js | 2 + .../submit-form.client.directive.js | 8 +- .../admin-form.client.controller.test.js | 3 +- .../entry-page.client.directive.test.js | 94 ++++++++ .../forms/views/admin-form.client.view.html | 8 +- .../directiveViews/entryPage/startPage.html | 24 +++ .../form/edit-form.client.view.html | 11 +- .../form/submit-form.client.view.html | 20 +- .../authentication.client.controller.js | 2 + 17 files changed, 385 insertions(+), 164 deletions(-) create mode 100644 public/modules/forms/directives/entry_page.client.directive.js create mode 100644 public/modules/forms/tests/unit/directives/entry-page.client.directive.test.js create mode 100644 public/modules/forms/views/directiveViews/entryPage/startPage.html diff --git a/app/controllers/forms.server.controller.js b/app/controllers/forms.server.controller.js index 16cfe929..30293541 100644 --- a/app/controllers/forms.server.controller.js +++ b/app/controllers/forms.server.controller.js @@ -275,31 +275,32 @@ exports.list = function(req, res) { exports.formByID = function(req, res, next, id) { if (!mongoose.Types.ObjectId.isValid(id)) { - res.status(400).send({ + return res.status(400).send({ message: 'Form is invalid' }); } + else { + Form.findById(id).populate('admin').exec(function(err, form) { + if (err) { + return next(err); + } else if (form === undefined || form === null) { + res.status(400).send({ + message: 'Form not found' + }); + } + else { + // console.log(form.admin); - Form.findById(id).populate('admin').exec(function(err, form) { - if (err) { - return next(err); - } else if (form === undefined || form === null) { - res.status(400).send({ - message: 'Form not found' - }); - } - else { - // console.log(form.admin); + //Remove sensitive information from User object + form.admin.password = undefined; + form.admin.salt = undefined; + form.provider = undefined; - //Remove sensitive information from User object - form.admin.password = undefined; - form.admin.salt = undefined; - form.provider = undefined; - - req.form = form; - next(); - } - }); + req.form = form; + next(); + } + }); + } }; /** diff --git a/app/controllers/users/users.authentication.server.controller.js b/app/controllers/users/users.authentication.server.controller.js index ae16c8cb..45e24676 100755 --- a/app/controllers/users/users.authentication.server.controller.js +++ b/app/controllers/users/users.authentication.server.controller.js @@ -56,20 +56,35 @@ exports.signup = function(req, res) { user.username = user.email; // Then save the temporary user - nev.createTempUser(user, function(newTempUser) { - // new user created - if (newTempUser) { - 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 { - return res.status(400).send('Error: Temp user could NOT be created!'); - } + nev.createTempUser(user, function(err, newTempUser) { + + if (err) { + console.log('Error: '); + console.log(err); + res.status(400).send({ + message: errorHandler.getErrorMessage(err) + }); + }else { + console.log('new tmpuser created'); + // new user created + if (newTempUser) { + nev.registerTempUser(newTempUser, function (err) { + if (err) { + console.log('Error: '); + console.log(err); + res.status(400).send({ + message: errorHandler.getErrorMessage(err) + }); + }else { + console.log('new tmpuser registered'); + res.status(200).send('An email has been sent to you. Please check it to verify your account.'); + } + }); + } else { + console.log('Error: Temp user already exists!'); + res.status(400).send('Error: Temp user already exists!'); + } + } }); }; @@ -104,8 +119,8 @@ exports.signin = function(req, res, next) { */ exports.signout = function(req, res) { req.logout(); - res.status(200).send('Successfully logged out'); - // res.redirect('/'); + // res.status(200).send('Successfully logged out'); + res.redirect('/'); }; /** diff --git a/app/models/form_submission.server.model.js b/app/models/form_submission.server.model.js index d8f59c64..b9c64862 100644 --- a/app/models/form_submission.server.model.js +++ b/app/models/form_submission.server.model.js @@ -63,10 +63,6 @@ var FormSubmissionSchema = new Schema({ }); -//Mongoose Relationship initialization -// FormSubmissionSchema.plugin(relationship, { relationshipPathName:'form' }); - - //Check for IP Address of submitting person FormSubmissionSchema.pre('save', function (next){ if(this.ipAddr){ diff --git a/app/tests/user.server.routes.test.js b/app/tests/user.server.routes.test.js index 58670f56..6316414c 100644 --- a/app/tests/user.server.routes.test.js +++ b/app/tests/user.server.routes.test.js @@ -8,11 +8,12 @@ var should = require('should'), app: app }), mongoose = require('mongoose'), - User = mongoose.model('User'), + url = require('url'), config = require('../../config/config'), + User = mongoose.model('User'), tmpUser = mongoose.model(config.tempUserCollection), - agent = request.agent(app), - url = require('url'); + agent = request.agent(app); + var mailosaur = require('mailosaur')(config.mailosaur.key), mailbox = new mailosaur.Mailbox(config.mailosaur.mailbox_id); @@ -23,12 +24,26 @@ var mandrill = require('node-mandrill')(config.mailer.options.auth.pass); * Globals */ var credentials, _User, _Session; +// 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, +}; /** * Form routes tests */ describe('User CRUD tests', function() { - this.timeout(15000); + this.timeout(100000); var userSession; beforeEach(function() { @@ -51,98 +66,115 @@ describe('User CRUD tests', function() { }; }); - // describe('Create, Verify and Activate a User', function() { - var username = 'testActiveAccount.be1e58fb@mailosaur.in'; + describe('Create, Verify and Activate a User', function() { + _User.email = _User.username = 'testActiveAccount5.be1e58fb@mailosaur.in'; var link, _tmpUser, activateToken = ''; - it('should be able to create a temporary (non-activated) User', function(done) { - _User.email = _User.username = username; - request(app).post('/auth/signup') + before(function(done){ + tmpUser.findOne({username: _User.username}, function (err, user) { + console.log(user); + if(user){ + tmpUser.remove({username: _User.username}, function(err){ + if(err) done(err) + done(); + }); + }else {done();} + }); + }); + + it('should be able to query /signup', function(done) { + + userSession.post('/auth/signup') .send(_User) .expect(200, 'An email has been sent to you. Please check it to verify your account.') .end(function(FormSaveErr, FormSaveRes) { - // (FormSaveRes.text).should.equal('An email has been sent to you. Please check it to verify your account.'); + should.not.exist(FormSaveErr); done(); - // tmpUser.findOne({username: _User.username}, function (err, user) { - // should.not.exist(err); - // should.exist(user); - // _tmpUser = user; - - // _User.username.should.equal(user.username); - // _User.firstName.should.equal(user.firstName); - // _User.lastName.should.equal(user.lastName); - - // // mandrill('/messages/search', { - // // query: "subject:Confirm", - // // senders: [ - // // "test@forms.polydaic.com" - // // ], - // // limit: 1 - // // }, function(error, emails) { - // // if (error) console.log( JSON.stringify(error) ); - - // // var confirmation_email = emails[0]; - - // // mandrill('/messages/content', { - // // id: confirmation_email._id - // // }, function(error, email) { - // // if (error) console.log( JSON.stringify(error) ); - - // // // console.log(email); - // // var link = _(email.text.split('\n')).reverse().value()[1]; - // // console.log(link); - // // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0]; - // // console.log('actual activateToken: '+ activateToken); - // // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL); - - // // done(); - - // // }); - // // }); - - - // // 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; - // // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0]; - // // console.log('actual activateToken: '+ activateToken); - // // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL); - // // (activateToken).should.equal(user.GENERATED_VERIFYING_URL); - - // // done(); - // // }); - // }); }); }); - // it('should be able to verify a User Account', function(done) { - // userSession.get('/auth/verify/'+activateToken) - // .expect(200) - // .end(function(VerifyErr, VerifyRes) { - // should.not.exist(VerifyErr); - // (VerifyRes.text).should.equal('User successfully verified'); - // done(); - // }); - // }); + it('should have created a temporary user', function(done){ + tmpUser.findOne({username: _User.username}).exec(function (err, user) { + should.not.exist(err); + should.exist(user); + _tmpUser = user; - // it('should receive confirmation email after verifying a User Account', function(done) { - // mailbox.getEmails(function(err, _emails) { - // if(err) throw err; - // var email = _emails[0]; + _User.username.should.equal(user.username); + _User.firstName.should.equal(user.firstName); + _User.lastName.should.equal(user.lastName); + done(); - // // console.log('mailbox.getEmails:'); - // console.log(email); - // (email.subject).should.equal('Account successfully verified!'); - // done(); - // }); - // }); - // }); + // mandrill('/messages/search', { + // query: "subject:Confirm", + // senders: [ + // "test@forms.polydaic.com" + // ], + // limit: 1 + // }, function(error, emails) { + // if (error) console.log( JSON.stringify(error) ); + + // var confirmation_email = emails[0]; + + // mandrill('/messages/content', { + // id: confirmation_email._id + // }, function(error, email) { + // if (error) console.log( JSON.stringify(error) ); + + // // console.log(email); + // var link = _(email.text.split('\n')).reverse().value()[1]; + // console.log(link); + // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0]; + // console.log('actual activateToken: '+ activateToken); + // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL); + + // done(); + + // }); + // }); + }); + }); + + it('should have sent a verification email', function(done){ + + 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; + activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0]; + console.log('actual activateToken: '+ activateToken); + console.log('expected activateToken: ' + _tmpUser.GENERATED_VERIFYING_URL); + (activateToken).should.equal(_tmpUser.GENERATED_VERIFYING_URL); + + done(); + }); + }); + + it('should be able to verify a User Account', function(done) { + userSession.get('/auth/verify/'+activateToken) + .expect(200) + .end(function(VerifyErr, VerifyRes) { + should.not.exist(VerifyErr); + (VerifyRes.text).should.equal('User successfully verified'); + done(); + }); + }); + + it('should receive confirmation email after verifying a User Account', function(done) { + mailbox.getEmails(function(err, _emails) { + if(err) throw err; + var email = _emails[0]; + + console.log(email); + (email.subject).should.equal('Account successfully verified!'); + done(); + }); + }); + }); // it('should be able to login and logout a User', function (done) { // var username = 'testActiveAccount.be1e58fb@mailosaur.in'; diff --git a/public/modules/forms/config/forms.client.routes.js b/public/modules/forms/config/forms.client.routes.js index 87f062bf..a04f4c41 100644 --- a/public/modules/forms/config/forms.client.routes.js +++ b/public/modules/forms/config/forms.client.routes.js @@ -13,19 +13,20 @@ angular.module('forms').config(['$stateProvider', permissions: [ 'editForm' ] } }). + state('submitForm', { + url: '/forms/:formId', + templateUrl: 'modules/forms/views/submit-form.client.view.html', + data: { + hideNav: true, + }, + }). state('viewForm', { url: '/forms/:formId/admin', templateUrl: 'modules/forms/views/admin-form.client.view.html', data: { permissions: [ 'editForm' ] } - }). - state('viewPublicForm', { - url: '/forms/:formId', - templateUrl: 'modules/forms/views/view-public-form.client.view.html', - data: { - hideNav: true, - }, - }); + }); + } ]); \ No newline at end of file diff --git a/public/modules/forms/controllers/admin-form.client.controller.js b/public/modules/forms/controllers/admin-form.client.controller.js index 39fbed6c..b3f85146 100644 --- a/public/modules/forms/controllers/admin-form.client.controller.js +++ b/public/modules/forms/controllers/admin-form.client.controller.js @@ -7,15 +7,23 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$scope $scope = $rootScope; $scope.myform = CurrentForm.getForm(); + $scope.myform._id = $stateParams.formId; $rootScope.saveInProgress = false; // Find a specific Form $scope.findOne = function(){ - $scope.myform = Forms.get({ + Forms.get({ formId: $stateParams.formId + }, function(form){ + CurrentForm.setForm(form); + $scope.myform = form; + $scope.myform._id = $stateParams.formId; + }, function(err){ + console.error('Could not fetch form'); + console.error(err); }); - CurrentForm.setForm($scope.myform); }; + $scope.setForm = function(form){ $scope.myform = form; }; diff --git a/public/modules/forms/directives/edit-submissions-form.client.directive.js b/public/modules/forms/directives/edit-submissions-form.client.directive.js index 3fee0f57..fa067843 100644 --- a/public/modules/forms/directives/edit-submissions-form.client.directive.js +++ b/public/modules/forms/directives/edit-submissions-form.client.directive.js @@ -15,7 +15,6 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', rows: [] }; - /* ** Table Functions */ @@ -46,8 +45,6 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', $http.get('/forms/'+$scope.myform._id+'/submissions') .success(function(data, status, headers){ - console.log(data[0].form_fields); - var _tmpSubFormFields, defaultFormFields = _.cloneDeep($scope.myform.form_fields); @@ -68,7 +65,9 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', .error(function(err){ console.error('Could not fetch form submissions.\nError: '+err); }); - }; + + }; + //Delete selected submissions of Form $scope.deleteSelectedSubmissions = function(){ diff --git a/public/modules/forms/directives/entry_page.client.directive.js b/public/modules/forms/directives/entry_page.client.directive.js new file mode 100644 index 00000000..fbbf80ce --- /dev/null +++ b/public/modules/forms/directives/entry_page.client.directive.js @@ -0,0 +1,47 @@ +// 'use strict'; + +// angular.module('forms').directive('entryPage', ['$templateCache', '$http', '$compile', '$rootScope', +// function($templateCache, $http, $compile, $rootScope) { +// var getTemplateUrl = function(type) { + +// var templateUrl = 'modules/forms/views/directiveViews/entryPage/'; +// var supported_pages = [ +// 'welcome', +// 'thankyou' +// ]; +// if (__indexOf.call(supported_pages, type) >= 0) { +// templateUrl += type + '.html'; +// } +// var template = $templateCache.get(templateUrl); +// return template; +// }; +// return { +// restrict: 'E', +// template: '
Start Page
', +// scope: { +// 'pageData': '=', +// 'pageType': '&' +// }, +// link: function(scope, element) { + +// // console.log(attrs); +// console.log('scope.pageData'); +// // console.log(scope); +// scope.exitStartPage = function() { +// // console.log(scope.pageData); +// // if(attrs.pageData.showStart) attrs.pageData.showStart = false; +// }; + +// var template = getTemplateUrl(scope.pageType); +// element.html(template); +// $compile(element.contents())(scope); +// }, +// controller: function($scope){ +// console.log('entryPage Controller'); +// console.log($scope.pageData); +// // $scope.exitStartPage = function() { +// // if($scope.pageData.showStart) scope.pageData.showStart = false; +// // }; +// } +// }; +// }]); \ No newline at end of file diff --git a/public/modules/forms/directives/field.client.directive.js b/public/modules/forms/directives/field.client.directive.js index f05330fa..829ddaf9 100644 --- a/public/modules/forms/directives/field.client.directive.js +++ b/public/modules/forms/directives/field.client.directive.js @@ -18,6 +18,7 @@ angular.module('forms').directive('fieldDirective', ['$templateCache', '$http', var templateUrl = 'modules/forms/views/directiveViews/field/'; var supported_fields = [ 'textfield', + 'welcome_page', 'email', 'textarea', 'checkbox', @@ -65,6 +66,7 @@ angular.module('forms').directive('fieldDirective', ['$templateCache', '$http', // } // GET template content from path + console.log(scope.field); var template = getTemplateUrl(scope.field); // $http.get(templateUrl).success(function(data) { element.html(template); diff --git a/public/modules/forms/directives/submit-form.client.directive.js b/public/modules/forms/directives/submit-form.client.directive.js index 8ae98097..6e1da767 100644 --- a/public/modules/forms/directives/submit-form.client.directive.js +++ b/public/modules/forms/directives/submit-form.client.directive.js @@ -16,6 +16,9 @@ angular.module('forms').directive('submitFormDirective', ['$http', '$timeout', ' TimeCounter.startClock() + $scope.exitStartPage = function(){ + $scope.myform.startPage.showStart = false; + } $rootScope.setActiveField = function (field_id) { $scope.selected = field_id; }; @@ -47,11 +50,6 @@ angular.module('forms').directive('submitFormDirective', ['$http', '$timeout', ' }); }; - - $scope.exitStartPage = function () { - $scope.myform.startPage.showStart = false; - }; - $scope.reloadForm = function(){ //Reset Timer TimeCounter.stopClock(); diff --git a/public/modules/forms/tests/unit/controllers/admin-form.client.controller.test.js b/public/modules/forms/tests/unit/controllers/admin-form.client.controller.test.js index 9ef77e7a..13e40a9a 100644 --- a/public/modules/forms/tests/unit/controllers/admin-form.client.controller.test.js +++ b/public/modules/forms/tests/unit/controllers/admin-form.client.controller.test.js @@ -154,7 +154,6 @@ }); })); - beforeEach(inject(function($modal) { spyOn($modal, 'open').and.returnValue(new fakeModal()); })); @@ -210,7 +209,7 @@ $httpBackend.flush(); // Test scope value - expect( scope.myform.toJSON() ).toEqualData(expectedFormObj.toJSON()); + expect( scope.myform.toJSON() ).toEqualData(expectedFormObj); })); it('$scope.removeCurrentForm() with valid form data should send a DELETE request with the id of form', function() { diff --git a/public/modules/forms/tests/unit/directives/entry-page.client.directive.test.js b/public/modules/forms/tests/unit/directives/entry-page.client.directive.test.js new file mode 100644 index 00000000..a28d70b0 --- /dev/null +++ b/public/modules/forms/tests/unit/directives/entry-page.client.directive.test.js @@ -0,0 +1,94 @@ +// 'use strict'; + +// (function() { +// // Forms Controller Spec +// describe('entryPage Directive Tests', function() { +// // Initialize global variables +// var scope, +// $templateCache, +// $httpBackend, +// $compile; + +// var sampleStartPage = { +// showStart: true, +// introTitle: 'Welcome to Form', +// introParagraph: 'Sample intro paragraph', +// buttons:[ +// { +// url: 'http://google.com', +// action: '', +// text: 'Google', +// bgColor: '#ffffff', +// color: '#000000', +// }, +// { +// url: 'http://facebook.com', +// action: '', +// text: 'Facebook', +// bgColor: '#0000ff', +// color: '#000000', +// } +// ] +// }; + + +// // The $resource service augments the response object with methods for updating and deleting the resource. +// // If we were to use the standard toEqual matcher, our tests would fail because the test values would not match +// // the responses exactly. To solve the problem, we define a new toEqualData Jasmine matcher. +// // When the toEqualData matcher compares two objects, it takes only object properties into +// // account and ignores methods. +// beforeEach(function() { +// jasmine.addMatchers({ +// toEqualData: function(util, customEqualityTesters) { +// return { +// compare: function(actual, expected) { +// return { +// pass: angular.equals(actual, expected) +// }; +// } +// }; +// } +// }); +// }); + +// // Load the main application module +// beforeEach(module(ApplicationConfiguration.applicationModuleName)); +// beforeEach(module('module-templates')); + +// beforeEach(inject(function($rootScope, _$compile_, _$httpBackend_) { +// scope = $rootScope.$new(); +// $compile = _$compile_; + +// // Point global variables to injected services +// $httpBackend = _$httpBackend_; +// })); + + +// it('should be able to render entryPage in html', function() { +// scope.myStartPage = _.cloneDeep(sampleStartPage); +// console.log(scope.myStartPage); +// var element = angular.element(''); +// $compile(element)(scope); +// scope.$digest(); + +// // console.log(element.html()); +// expect(element.html()).not.toEqual('
Start Page
'); +// }); + +// // it('exitStartPage should work for "startPage" type of entryPage', inject(function($rootScope) { +// // scope.myPage = _.cloneDeep(sampleStartPage); +// // var el = angular.element(''); +// // $compile(el)(scope); +// // scope.$digest(); + +// // $httpBackend.whenGET(/.+\.html$/).respond(''); +// // $httpBackend.whenGET('/users/me/').respond(''); + +// // scope = el.isolateScope() || el.scope(); + +// // scope.exitStartPage(); +// // // expect(scope.myStartPage.showStart).toBe(false); +// // expect(el.html()).not.toEqual('
Start Page
'); +// // })); +// }); +// }()); \ No newline at end of file diff --git a/public/modules/forms/views/admin-form.client.view.html b/public/modules/forms/views/admin-form.client.view.html index ff76d4f9..dd2dd0e8 100644 --- a/public/modules/forms/views/admin-form.client.view.html +++ b/public/modules/forms/views/admin-form.client.view.html @@ -90,9 +90,9 @@ - - - -
-

{{myform.startPage.introTitle}}

+

{{pageData.introTitle}}

-

{{myform.startPage.introParagraph}}

+

{{pageData.introParagraph}}

-
-

+

diff --git a/public/modules/forms/views/directiveViews/form/submit-form.client.view.html b/public/modules/forms/views/directiveViews/form/submit-form.client.view.html index 49f76d37..6202c816 100755 --- a/public/modules/forms/views/directiveViews/form/submit-form.client.view.html +++ b/public/modules/forms/views/directiveViews/form/submit-form.client.view.html @@ -5,23 +5,25 @@