diff --git a/bower.json b/bower.json index 4232b9f..104e7f7 100644 --- a/bower.json +++ b/bower.json @@ -1,5 +1,5 @@ { - "name": "warehost client", + "name": "warehost-webclient", "authors": [ "Martin Geno " ], diff --git a/package.json b/package.json index 74117dc..c7598ab 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "freifunkmanager", + "name": "warehost-webclient", "version": "1.0.0", "description": "Eventmanager for respond-collector", "main": "Gruntfile.js", @@ -27,9 +27,14 @@ "grunt-wiredep": "^2.0.0", "jit-grunt": "^0.9.1", "jshint-stylish": "^2.1.0", - "time-grunt": "^1.2.2" + "coffee-script": "^1.9.3", + "time-grunt": "^1.2.2", + "chai": "^3.2.0", + "mocha": "^2.3.2", + "request": "*" }, "scripts": { - "start": "grunt serve" + "start": "grunt serve", + "test": "mocha --compilers coffee:coffee-script/register tests" } } diff --git a/public/app/settings.js b/public/app/settings.js index 8889239..9f9d041 100644 --- a/public/app/settings.js +++ b/public/app/settings.js @@ -10,10 +10,10 @@ angular.module('warehost') }); }; $scope.delete = function(){ - if(confirm("realy delete your login and everything else on warehost?")){ + if(window.confirm('realy delete your login and everything else on warehost?')){ $http.get(config.api+'/delete').then(function(res){ session.set(res); }); } - } + }; }); diff --git a/tests/config.json b/tests/config.json new file mode 100644 index 0000000..9ad6245 --- /dev/null +++ b/tests/config.json @@ -0,0 +1,7 @@ +{ + "ADDRESS":"http://[::1]:8080", + "testdata":{ + "username":"root", + "password":"root" + } +} diff --git a/tests/index.coffee b/tests/index.coffee index e69de29..46d8549 100644 --- a/tests/index.coffee +++ b/tests/index.coffee @@ -0,0 +1,167 @@ +expect = require("chai").expect +request = require('request') + +lib = require('./lib') + +config = require('./config') + +describe('API',-> + it('status',(done)-> + request({method: 'GET',uri:config.ADDRESS+"/status"},(err,res,body)-> + expect(err).to.be.null + expect(res.statusCode).to.be.equal(200) + x = JSON.parse(body) + expect(x.data).to.be.true + done() + ) + ) + describe('login',-> + it('-> wrong username',(done)-> + request({method: 'POST',uri: config.ADDRESS+"/login",json:{ + username: config.testdata.username+"f", + password: config.testdata.password + }},(err,res,body)-> + expect(err).to.be.null + expect(res.statusCode).to.be.equal(200) + expect(body.data).to.be.false + done() + ) + ) + it('-> wrong password',(done)-> + request({method: 'POST',uri: config.ADDRESS+"/login",json:{ + username: config.testdata.username, + password: config.testdata.password+"f" + }},(err,res,body)-> + expect(err).to.be.null + expect(res.statusCode).to.be.equal(200) + expect(body.data).to.be.false + done() + ) + ) + it('-> validate',(done)-> + request({method: 'POST',uri: config.ADDRESS+"/login",json:{ + username: config.testdata.username, + password: config.testdata.password + }},(err,res,body)-> + expect(err).to.be.null + expect(res.statusCode).to.be.equal(200) + expect(body.data).to.be.true + expect(body.session.login.active).to.be.true + done() + ) + ) + ) + describe('logout',-> + it('-> without login',(done)-> + request({method: 'GET',uri:config.ADDRESS+"/logout"},(err,res,body)-> + expect(err).to.be.null + expect(res.statusCode).to.be.equal(200) + x = JSON.parse(body) + expect(x.data).to.be.true + expect(x.session.login).to.be.null + done() + ) + ) + it('-> validate',(done)-> + lib.login((j)-> + request({method: 'GET',uri:config.ADDRESS+"/logout",jar:j},(err,res,body)-> + expect(err).to.be.null + expect(res.statusCode).to.be.equal(200) + x = JSON.parse(body) + expect(x.data).to.be.true + expect(x.session.login).to.be.null + done() + ) + ) + ) + ) + describe('password',-> + it('-> without login',(done)-> + request({method: 'POST',uri: config.ADDRESS+"/password",json:{ + username: config.testdata.username, + password: config.testdata.password + }},(err,res,body)-> + expect(err).to.be.null + expect(res.statusCode).to.be.equal(200) + x = JSON.parse(body) + expect(x.data).to.be.true + expect(x.session.login).to.be.null + done() + ) + ) + it('-> wrong current password',(done)-> + lib.login((j)-> + request({method: 'POST',uri: config.ADDRESS+"/password",json:{ + currentpassword: config.testdata.password+"f", + newpassword: config.testdata.password+"ff", + },jar:j},(err,res,body)-> + expect(err).to.be.null + expect(res.statusCode).to.be.equal(200) + x = JSON.parse(body) + expect(x.data).to.be.false + expect(x.session.login).to.be.null + done() + ) + ) + ) + it('-> wrong new password',(done)-> + lib.login((j)-> + request({method: 'POST',uri: config.ADDRESS+"/password",json:{ + currentpassword: config.testdata.password, + newpassword: "", + },jar:j},(err,res,body)-> + expect(err).to.be.null + expect(res.statusCode).to.be.equal(200) + x = JSON.parse(body) + expect(x.data).to.be.false + expect(x.session.login).to.be.null + done() + ) + ) + ) + it('-> validate',(done)-> + lib.login((j)-> + request({method: 'POST',uri: config.ADDRESS+"/password",json:{ + currentpassword: config.testdata.password, + newpassword: config.testdata.password+"f", + },jar:j},(err,res,body)-> + expect(err).to.be.null + expect(res.statusCode).to.be.equal(200) + x = JSON.parse(body) + expect(x.data).to.be.true + expect(x.session.login).to.be.null + request({method: 'POST',uri: config.ADDRESS+"/password",json:{ + currentpassword: config.testdata.password+"f", + newpassword: config.testdata.password, + },jar:j},(err,res,body)-> + done() + ) + ) + ) + ) + ) + describe('delete',-> + it('-> without login',(done)-> + request({method: 'GET',uri:config.ADDRESS+"/delete"},(err,res,body)-> + expect(err).to.be.null + expect(res.statusCode).to.be.equal(200) + x = JSON.parse(body) + expect(x.data).to.be.true + expect(x.session.login).to.be.null + done() + ) + ) + it('-> validate',(done)-> + lib.login((j)-> + request({method: 'GET',uri:config.ADDRESS+"/delete",jar:j},(err,res,body)-> + expect(err).to.be.null + expect(res.statusCode).to.be.equal(200) + x = JSON.parse(body) + expect(x.data).to.be.true + expect(x.session.login).to.be.null + done() + ) + ) + ) + ) +) diff --git a/tests/lib.coffee b/tests/lib.coffee new file mode 100644 index 0000000..411ae58 --- /dev/null +++ b/tests/lib.coffee @@ -0,0 +1,16 @@ +expect = require("chai").expect +request = require('request') + +config = require('./config') + +module.exports.login = (call)-> + j = request.jar() + request({method: 'POST',uri: config.ADDRESS+"/login",json:{ + username: config.testdata.username, + password: config.testdata.password + },jar:j},(err,res,body)-> + expect(err).to.be.null + expect(res.statusCode).to.be.equal(200) + expect(body.data).to.be.true + call(j) + )