diff --git a/Gruntfile.js b/Gruntfile.js index 27a6269..70bff42 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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'] diff --git a/app/scripts/services/cmsauthservice.coffee b/app/scripts/services/cmsauthservice.coffee index 954d182..29d2851 100644 --- a/app/scripts/services/cmsauthservice.coffee +++ b/app/scripts/services/cmsauthservice.coffee @@ -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. diff --git a/gulpfile.js b/gulpfile.js index eea6692..556643e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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'] ) } ); diff --git a/package.json b/package.json index 2edb42a..2686c2b 100755 --- a/package.json +++ b/package.json @@ -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", diff --git a/protractor.conf.js b/protractor.conf.js index 0872e12..25dee63 100644 --- a/protractor.conf.js +++ b/protractor.conf.js @@ -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. diff --git a/routes/cms-auth.js b/routes/cms-auth.js index 183dc95..06ae36b 100644 --- a/routes/cms-auth.js +++ b/routes/cms-auth.js @@ -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 @@ -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}); } }; @@ -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 ); }; diff --git a/test/protractor/App.js b/test/protractor/App.js deleted file mode 100644 index 2233513..0000000 --- a/test/protractor/App.js +++ /dev/null @@ -1,54 +0,0 @@ -/** - * This is the protractor spec that will test the different areas of the application. - */ - -/** - * UsersPage - This page object controls actions on the /users page. - * @constructor - */ -var UsersPage = function () { - this.newUserBtn = element( by.buttonText( 'New User' ) ); - this.submitBtn = element( by.buttonText( 'Submit' ) ); - - this.inputs = { - email: element( protractor.By.model( 'user.email' ) ), - username: element( protractor.By.model( 'user.username' ) ), - password: element( protractor.By.model( 'user.password' ) ), - name: element( protractor.By.model( 'user.meta.name' ) ), - summary: element( protractor.By.model( 'user.meta.summary' ) ) - }; - - this.get = function () { - browser.get( 'http://localhost:9000/#/users' ); - }; - - this.setForm = function (email, username, password, name, summary) { - this.newUserBtn.click(); - browser.sleep( 500 ); - this.inputs.username.sendKeys( username ); - this.inputs.email.sendKeys( email ); - this.inputs.password.sendKeys( password ); - this.inputs.name.sendKeys( name ); - this.inputs.summary.sendKeys( summary ); - - this.submitBtn.click(); - browser.sleep( 1000 ); - }; - -}; - -describe( 'Angular-CMS', function () { - var usersPage = null; - - describe( 'Users Page:', function () { - beforeEach( function () { - usersPage = new UsersPage(); - usersPage.get(); - } ); - - it( 'should be able to create a new user', function () { - var username = 'protractor' + Date.now(); - usersPage.setForm( username + '@test.com', username, 'test', 'John Doe', 'This is an example user.' ); - } ); - } ); -} ); diff --git a/test/protractor/app-spec.coffee b/test/protractor/app-spec.coffee deleted file mode 100644 index 64340fa..0000000 --- a/test/protractor/app-spec.coffee +++ /dev/null @@ -1,110 +0,0 @@ -AppPage = require('./app-page') -UsersPage = require('./users-page') -LoginPage = require('./login-page') -RegisterPage = require('./register-page') - -App = null -usersPage = null -registerPage = null -loginPage = null - -###* -Protractor e2e Tests -### -describe "Angular-CMS App", -> - beforeEach -> - App = new AppPage() - App.get() - #Welome Story: the initial page - describe 'Index:', -> - it "should display the main index view as default", -> - expect(browser.getCurrentUrl()).toEqual '/' - - it 'should have a .navbar-brand on the page', -> - expect(j$.element('.navbar-brand', 'Site title').count()).toEqual 1 - - it 'should have a .login-btn element with a link to the login page', -> - expect(j$.element('a[href="#/login"]', 'the Login link').count()).toEqual 1 - - it 'should have a .media element for a feature', -> - browser.sleep 1 - expect(j$.element('.media').count()).toBeGreaterThan 1 - - it 'should have a jumbrotron element for feature title and body', -> - browser.sleep 1 - expect(j$.element('.jumbotron').count()).toEqual 1 - - - ###* - 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(driver.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 - - ###* - Login - The user login implementation - ### - describe 'Login:', -> - - #Click the login button each time - beforeEach -> - loginPage = new LoginPage() - element('a[href="#/login"]', 'Login button').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().location().path()).toEqual '/login' - expect(element('form', 'Login form').count()).toEqual 1 - expect(element('input[name="username"]', 'Username input').count()).toEqual 1 - expect(element('input[name="password"]', 'Password input').count()).toEqual 1 - expect(element('button[type="submit"]', 'Submit button').count()).toEqual 1 - - #Login to the page - loginPage.login() - - #Wait for the api call to go thru - sleep 1 - #We should end up at the dashboard page. - expect(browser().location().path()).toEqual '/dashboard' - - #The dashboard implementation - describe 'Dashboard: viewing the dashboard...', -> - beforeEach -> - loginPage = new LoginPage() - loginPage.login('test@gmail.com', 'test') - browser.sleep 1 - it 'should have a link to the profile page', -> - expect(j$.element('.widget', 'Widget Panel').count()).toEqual 2 - expect(j$.element('a[ng-href="#/profile"]', 'the Profile link').count()).toEqual 1 - expect(j$.element('.cms-sidebar-nav', 'Sidebar nav').count()).toEqual 1 - - describe "Users Page:", -> - beforeEach -> - usersPage = new UsersPage() - usersPage.get() - it "should be able to create a new user", -> - username = "protractor" + Date.now() - usersPage.setForm username + "@test.com", username, "test", "John Doe", "This is an example user." - -#The user registration implementation - - -#The user forgot password implementation - - -# The CRUD operations on DB implementation - - -# User table - - -#User form diff --git a/test/protractor/app-page.coffee b/test/protractor/pages/app-page.coffee similarity index 100% rename from test/protractor/app-page.coffee rename to test/protractor/pages/app-page.coffee diff --git a/test/protractor/login-page.coffee b/test/protractor/pages/login-page.coffee similarity index 100% rename from test/protractor/login-page.coffee rename to test/protractor/pages/login-page.coffee diff --git a/test/protractor/register-page.coffee b/test/protractor/pages/register-page.coffee similarity index 100% rename from test/protractor/register-page.coffee rename to test/protractor/pages/register-page.coffee diff --git a/test/protractor/users-page.coffee b/test/protractor/pages/users-page.coffee similarity index 100% rename from test/protractor/users-page.coffee rename to test/protractor/pages/users-page.coffee diff --git a/test/protractor/spec/app-spec.coffee b/test/protractor/spec/app-spec.coffee new file mode 100644 index 0000000..48c0234 --- /dev/null +++ b/test/protractor/spec/app-spec.coffee @@ -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 '/' diff --git a/test/protractor/spec/login-spec.coffee b/test/protractor/spec/login-spec.coffee new file mode 100644 index 0000000..fb20fc5 --- /dev/null +++ b/test/protractor/spec/login-spec.coffee @@ -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('test@email.com', 'test') + + #Wait for the api call to go thru + sleep 1 + + #We should end up at the dashboard page. + expect(browser.getLocationAbsUrl()).toEqual '/dashboard' diff --git a/test/protractor/spec/register-spec.coffee b/test/protractor/spec/register-spec.coffee new file mode 100644 index 0000000..f4a6692 --- /dev/null +++ b/test/protractor/spec/register-spec.coffee @@ -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 diff --git a/test/protractor/spec/users-spec.coffee b/test/protractor/spec/users-spec.coffee new file mode 100644 index 0000000..e69de29 diff --git a/test/routes/rest-spec.js b/test/routes/rest-spec.js index 5e617c0..5b2eba0 100644 --- a/test/routes/rest-spec.js +++ b/test/routes/rest-spec.js @@ -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); @@ -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); @@ -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);