Skip to content

Commit

Permalink
Added gulp + routes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonniespratley committed Dec 9, 2014
1 parent 6aff011 commit c620d9c
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 186 deletions.
5 changes: 1 addition & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ module.exports = function (grunt) {
files: ['test/spec/{,**/}*.{coffee,litcoffee,coffee.md}'],
tasks: ['coffee:test', 'newer:coffee:test', 'karma:unit']
},
coffeeProtractorTest: {
files: ['test/protractor/{,**/}*.{coffee,litcoffee,coffee.md}'],
tasks: ['coffee:test', 'newer:coffee:test', 'protractor']
},

compass: {
files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
tasks: ['compass:server', 'autoprefixer']
Expand Down
10 changes: 8 additions & 2 deletions app/scripts/services/cmsauthservice.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ angular.module('angularCmsApp').service 'cmsAuthService', ($q, $http, $log, $roo
authorize - I handle authorizing a user.
###
authorize: (user) ->
return $http.post( @endpoint+"/users/login", user )
return $http.post( @endpoint+"/login", user )

###*
session - I handle getting a session.
###
session: () ->
return $http.get( @endpoint+"/session" )

###*
register - I handle register a user.
###
register: (user) ->
return $http.post( @endpoint+"/users/register", user )
return $http.post( @endpoint+"/register", user )

###*
Logout method to clear the session.
Expand Down
13 changes: 10 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ coffee = require( 'gulp-coffee' );
uglify = require( 'gulp-uglify' );

gulp.task( 'js', function () {
return gulp
gulp
.src( './app/scripts/**/*.coffee' )
.pipe( coffee() )
.pipe( uglify() )
.pipe( gulp.dest( './.tmp/scripts' ) );
} );
gulp.task( 'js:test', function () {
gulp
.src( './test/**/*.coffee' )
.pipe( coffee() )
.pipe( uglify() )
.pipe( gulp.dest( './.tmp' ) );
} );

gulp.task( 'watch', function () {
return gulp
.watch( './app/scripts/**/*.coffee', ['js'] );
gulp.watch( './app/scripts/**/*.coffee', ['js'] );
gulp.watch( './test/**/*.coffee', ['js:test'] )
} );
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"grunt-svgmin": "~0.2.0",
"grunt-usemin": "~2.0.2",
"gulp-ngmin": "^0.3.0",
"gulp-uglify": "^1.0.2",
"jasmine-core": "^2.1.2",
"jasmine-node": "~1.11.0",
"jasmine-reporters": "^1.0.1",
Expand Down
4 changes: 2 additions & 2 deletions protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ exports.config = {
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: [
'.tmp/protractor/*-spec.js',
'test/protractor/*-spec.js'
'.tmp/protractor/**/*-spec.js',
'test/protractor/**/*-spec.js'
],

// Options to be passed to Jasmine-node.
Expand Down
28 changes: 20 additions & 8 deletions routes/cms-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@ module.exports = function (config, app) {
if (err) {
res.jsonp( 400, err );
}
if (data && bcrypt.compareSync(req.body.password, data.password)) {
res.jsonp( 200, data );
} else {
res.jsonp( 404, {message: 'Wrong username/password!'} );

try {
if (data && bcrypt.compareSync(req.body.password, data.password)) {
req.session.user = data;
res.jsonp( 200, data );
} else {
res.jsonp( 404, {message: 'Wrong username/password!'} );
}
} catch (error) {
res.jsonp( 404, {message: error} );
}
} );

},
/**
* Handle registering a new user
Expand Down Expand Up @@ -99,6 +104,12 @@ module.exports = function (config, app) {
} );
},
session: function (req, res, next) {
var user = req.session;
if(req.session && req.session.user){
user = req.session.user
}
console.warn(util.inspect(user, {colors: true}));
res.send({message: 'Your session', data: user});
}
};

Expand All @@ -108,7 +119,8 @@ module.exports = function (config, app) {
resave: true,
saveUninitialized: true
} ) );
app.post( config.apiBase + '/users/login', bodyParser.json(), cmsAuth.login );
app.post( config.apiBase + '/users/register', bodyParser.json(), cmsAuth.register );
app.post( config.apiBase + '/users/session', bodyParser.json(), cmsAuth.session );
app.get( config.apiBase + '/login', bodyParser.json(), cmsAuth.login );
app.post( config.apiBase + '/login', bodyParser.json(), cmsAuth.login );
app.post( config.apiBase + '/register', bodyParser.json(), cmsAuth.register );
app.get( config.apiBase + '/session', bodyParser.json(), cmsAuth.session );
};
54 changes: 0 additions & 54 deletions test/protractor/App.js

This file was deleted.

110 changes: 0 additions & 110 deletions test/protractor/app-spec.coffee

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions test/protractor/spec/app-spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
AppPage = require('../pages/app-page')


###*
Protractor e2e Tests
###
App = new AppPage()
describe "Angular-CMS App", ->
beforeEach ->
App.get()

#Welome Story: the initial page
describe 'Index:', ->
it "should display the main index view as default", ->
expect(browser.getLocationAbsUrl()).toEqual '/'
24 changes: 24 additions & 0 deletions test/protractor/spec/login-spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
LoginPage = require('../pages/login-page')
loginPage = new LoginPage()
###*
Login - The user login implementation
###
describe 'Login:', ->

#Click the login button each time
beforeEach ->
$('a[href="#/login"]').click()

#Make sure we end up at the login page to enter our credentials
#Make sure there is a username and password input with button
it 'should have Username and password inputs with a button to submit the form', ->
expect(browser.getLocationAbsUrl()).toEqual '/login'

#Login to the page
loginPage.login('[email protected]', 'test')

#Wait for the api call to go thru
sleep 1

#We should end up at the dashboard page.
expect(browser.getLocationAbsUrl()).toEqual '/dashboard'
16 changes: 16 additions & 0 deletions test/protractor/spec/register-spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
RegisterPage = require('../pages/register-page')
j$ = require('../j$')

###*
Register - The user registration implementation
###
describe 'Register: ', ->
it 'should have email and password inputs with a button to submit the form', ->
registerPage = new RegisterPage()
registerPage.get()
expect(browser.getCurrentUrl()).toContain 'register'
expect(j$.element('form', 'Login form').count()).toEqual 1
expect(j$.element('input[name="email"]', 'Email input').count()).toEqual 1
expect(j$.element('input[name="username"]', 'Username input').count()).toEqual 1
expect(j$.element('input[name="password"]', 'Password input').count()).toEqual 2
expect(j$.element('button[type="submit"]', 'Submit button').count()).toEqual 1
Empty file.
6 changes: 3 additions & 3 deletions test/routes/rest-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Testing: API Server', function () {

it('POST - /api/v2/users/register - should return user on successful registation', function (done) {
request(app)
.post('/api/v2/users/register')
.post('/api/v2/register')
.send(postData)
.expect("Content-Type", /json/)
.expect(201, done);
Expand All @@ -47,7 +47,7 @@ describe('Testing: API Server', function () {
password: 'test'
};
request(app)
.post('/api/v2/users/login')
.post('/api/v2/login')
.send(validUser)
.expect("Content-Type", /json/)
.expect(200, done);
Expand All @@ -58,7 +58,7 @@ describe('Testing: API Server', function () {
password: 'wrongpassword'
};
request(app)
.post('/api/v2/users/login')
.post('/api/v2/login')
.send(invalidUser)
.expect("Content-Type", /json/)
.expect(404, done);
Expand Down

0 comments on commit c620d9c

Please sign in to comment.