Skip to content

Commit

Permalink
updating protractor test
Browse files Browse the repository at this point in the history
  • Loading branch information
jonniespratley committed Dec 7, 2014
1 parent d9f1441 commit 75ef339
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 202 deletions.
20 changes: 12 additions & 8 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = function (grunt) {
},
coffeeTest: {
files: ['test/{,**/}*.{coffee,litcoffee,coffee.md}'],
tasks: ['coffee:test', 'newer:coffee:test', 'karma']
tasks: ['coffee:test', 'newer:coffee:test', 'karma:unit', 'protractor']
},
compass: {
files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
Expand Down Expand Up @@ -553,12 +553,12 @@ module.exports = function (grunt) {
}
},

//Protractor webdriver & protractor
protractor_webdriver: {
options: {
// Task-specific options go here.
},
test: {
// Target-specific file lists and/or options go here.
options: {
command: 'webdriver-manager start'
}
}
},
protractor: {
Expand All @@ -575,6 +575,9 @@ module.exports = function (grunt) {
}
}
},


//Coveralls code coverage
coveralls: {
options: {
debug: true,
Expand Down Expand Up @@ -616,13 +619,14 @@ module.exports = function (grunt) {
grunt.registerTask('test', function (target) {
grunt.task.run(['clean:server', 'concurrent:test', 'autoprefixer', 'connect:test']);
if (target === 'e2e') {
return grunt.task.run(['karma']);
return grunt.task.run(['karma', 'protractor_webdriver', 'protractor', 'coveralls']);
} else if(target === 'server'){
return grunt.task.run(['coffee:test', 'mochaTest']);
} else {
return grunt.task.run(['karma:unit', 'coveralls']);
}
});
grunt.registerTask('test:server', 'coffee:test', 'mochaTest');
grunt.registerTask('test:protractor', 'coffee:test', 'protractor')


grunt.registerTask('build-docs', [ 'useminPrepare', 'autoprefixer', 'concat', 'ngmin']);
grunt.registerTask('build', ['clean:dist', 'useminPrepare', 'concurrent:dist', 'autoprefixer', 'concat', 'ngmin', 'copy:dist', /*'cdnify',*/ 'cssmin', 'uglify', 'rev', 'usemin']);
Expand Down
12 changes: 6 additions & 6 deletions app/views/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@

</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Email" ng-model="user.email" required/>
<input name="email" type="email" class="form-control" placeholder="Email" ng-model="user.email" required/>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Username" ng-model="user.username" required/>
<input name="username" type="text" class="form-control" placeholder="Username" ng-model="user.username" required/>
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="Password" ng-model="user.password" required/>
<input name="password" type="password" class="form-control" placeholder="Password" ng-model="user.password" required/>
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="Confirm Password" ng-model="user.password2"
<input name="password2" type="password" class="form-control" placeholder="Confirm Password" ng-model="user.password2"
required/>
</div>
<div class="form-group">
<label>
<input class="inline-checkbox" type="checkbox" ng-model="user.agree" required>
<input name="agree" class="inline-checkbox" type="checkbox" ng-model="user.agree" required>
Agree to Terms of Use
</label>
</div>
Expand All @@ -36,4 +36,4 @@
<span class="pull-left"> Back to <a href="#/login">Login</a> </span>

</div>
</div>
</div>
3 changes: 1 addition & 2 deletions karma-e2e.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = function(config) {
],

preprocessors: {
'test/e2e/*.coffee': ['coffee'],
'test/e2e/**/*.coffee': ['coffee']
},

Expand Down Expand Up @@ -47,7 +46,7 @@ module.exports = function(config) {
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['Chrome'],
browsers: ['PhantomJS'],


// Continuous Integration mode
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@
"passport": "^0.2.1",
"passport-facebook": "^1.0.3",
"passport-google": "^0.3.0",
"passport-http": "^0.2.2",
"passport-local": "^1.0.0",
"passport-twitter": "^1.0.2",
"promised-io": "~0.3.4",
"q": "^1.1.2",
"request": "~2.34.0",
"socket.io": "~0.9.16"
},
Expand Down
13 changes: 10 additions & 3 deletions protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@ exports.config = {
'browserName': 'chrome'
},

params: {
baseUrl: 'http://localhost:9000'
},

// Spec patterns are relative to the current working directly when
// protractor is called.
specs: [
'.tmp/protractor/*.js',
'test/protractor/*.js'
'.tmp/protractor/*-spec.js',
'test/protractor/*-spec.js'
],

// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
}
},
onPrepare: function(){
browser.driver.get(browser.params.baseUrl);
}
};
120 changes: 43 additions & 77 deletions routes/cms-auth.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
var passport = require('passport'),
express = require('express'),
BasicStrategy = require('passport-http').Strategy,
LocalStrategy = require('passport-local').Strategy,
GoogleStrategy = require('passport-google').Strategy,
log = require('npmlog'),
path = require('path'),
q = require('q'),
flash = require('express-flash'),
DS = require('jps-ds').DS;

Expand All @@ -16,13 +18,9 @@ var users = [
{id: 1, username: 'admin', password: 'admin', email: '[email protected]'},
{id: 2, username: 'test', password: 'test', email: '[email protected]'},
{id: 3, username: 'jonniespratley', password: 'fred', email: '[email protected]'}

];


var User = function(){

};
var User = function(){};

User.findOrCreate = function(profile, fn){
console.warn('findOrCreate', profile);
Expand All @@ -38,19 +36,20 @@ User.findById = function(id, fn) {
} else {
fn(new Error('User ' + id + ' does not exist'));
}
}

};
User.findByUsername = function(username, fn) {
var defer = q.defer();
console.warn('findByUsername', username);
for (var i = 0, len = users.length; i < len; i++) {
var user = users[i];
if (user.username === username) {
return fn(null, user);
defer.resolve(user);
} else {
console.warn('user not found', username);
}
}
return fn(null, null);
}

return defer.promise;
};
User.findByEmail = function(email, fn) {
console.warn('findByEmail', email);
for (var i = 0, len = users.length; i < len; i++) {
Expand All @@ -60,31 +59,15 @@ User.findByEmail = function(email, fn) {
}
}
return fn(null, null);
}



};

function cmsAuth(options, app) {
var self = this;
var baseUrl = options.host + ':' + options.port;
if (!app) {
throw new Error('Must provide express application!');
}

console.warn('cmsAuth', options);

self._ds = DS;

var baseUrl = options.host + ':' + options.port;










// Simple route middleware to ensure user is authenticated.
// Use this route middleware on any resource that needs to be protected. If
Expand All @@ -105,44 +88,37 @@ function cmsAuth(options, app) {
// the user by ID when deserializing.

passport.serializeUser(function(user, done) {
done(null, user.id);
});
done(null, user.id);
});

passport.deserializeUser(function(id, done) {
User.findById(id, function(err, user) {
done(err, user);
});
});


/* */

passport.deserializeUser(function(id, done) {
User.findById(id, function(err, user) {
done(err, user);
});
});
/*
// Use the LocalStrategy within Passport.
// Strategies in passport require a `verify` function, which accept
// credentials (in this case, a username and password), and invoke a callback
// with a user object. In the real world, this would query a database;
// however, in this example we are using a baked-in set of users.
passport.use(new LocalStrategy(function (username, password, done) {
// asynchronous verification, for effect...
passport.use(new LocalStrategy({
usernameField: 'email',
passwordField: 'password'
}, function (username, password, done) {
process.nextTick(function () {
// Find the user by username. If there is no user with the given
// username, or the password is not correct, set the user to `false` to
// indicate failure and set a flash message. Otherwise, return the
// authenticated `user`.
findByUsername(username, function (err, user) {
if (err) {
return done(err);
}
if (!user) {
return done(null, false, {message: 'Unknown user ' + username});
}
if (user.password != password) {
return done(null, false, {message: 'Invalid password'});
}
console.warn('find by username');
User.findByUsername(username).then(function(user){
return done(null, user);
})
}, function(err){
return done(null, false);
});
});
}
));
*/

/**/
passport.use(new GoogleStrategy({
returnURL: 'http://localhost:8181/auth/google/return', realm: 'http://localhost:8181/'
Expand All @@ -157,6 +133,7 @@ passport.deserializeUser(function(id, done) {
));



//Setup
app.configure(function () {
app.use(express.logger());
Expand All @@ -177,14 +154,15 @@ passport.deserializeUser(function(id, done) {
}));
app.use(passport.initialize());
app.use(passport.session());

app.use(app.router);


});



app.get('/api/me', passport.authenticate('basic', { session: false }), function(req, res) {
res.json(req.user);
});

app.all('*', function (req, res, next) {
console.warn('cmsAuth', req.params);
next();
Expand All @@ -202,24 +180,12 @@ passport.deserializeUser(function(id, done) {
res.render('login', { user: req.user, message: 'Please login', status: 'warning' });
});

app.post('/login', function(req, res, next) {
passport.authenticate('local', function(err, user, info) {
if (err) {
return next(err)
}
if (!user) {
//req.flash('error', info.message);
return res.redirect('/login')
}
req.logIn(user, function(err) {
if (err) {
return next(err);
}
return res.redirect('/users/' + user.username);
});
})(req, res, next);
});

app.post('/login',
passport.authenticate('local', { successRedirect: '/',
failureRedirect: '/login',
failureFlash: false })
);

app.get('/auth/user', ensureAuthenticated, function (req, res) {
res.json(200, req.user);
Expand Down
Loading

0 comments on commit 75ef339

Please sign in to comment.