sum7/warehost-frontend
sum7
/
warehost-frontend
Archived
1
0
Fork 0

add Tests

This commit is contained in:
Martin Geno 2016-08-14 14:22:11 +02:00
parent 669faeae87
commit ef659724c7
6 changed files with 201 additions and 6 deletions

View File

@ -1,5 +1,5 @@
{ {
"name": "warehost client", "name": "warehost-webclient",
"authors": [ "authors": [
"Martin Geno <geno+dev@fireorbit.de>" "Martin Geno <geno+dev@fireorbit.de>"
], ],

View File

@ -1,5 +1,5 @@
{ {
"name": "freifunkmanager", "name": "warehost-webclient",
"version": "1.0.0", "version": "1.0.0",
"description": "Eventmanager for respond-collector", "description": "Eventmanager for respond-collector",
"main": "Gruntfile.js", "main": "Gruntfile.js",
@ -27,9 +27,14 @@
"grunt-wiredep": "^2.0.0", "grunt-wiredep": "^2.0.0",
"jit-grunt": "^0.9.1", "jit-grunt": "^0.9.1",
"jshint-stylish": "^2.1.0", "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": { "scripts": {
"start": "grunt serve" "start": "grunt serve",
"test": "mocha --compilers coffee:coffee-script/register tests"
} }
} }

View File

@ -10,10 +10,10 @@ angular.module('warehost')
}); });
}; };
$scope.delete = function(){ $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){ $http.get(config.api+'/delete').then(function(res){
session.set(res); session.set(res);
}); });
} }
} };
}); });

7
tests/config.json Normal file
View File

@ -0,0 +1,7 @@
{
"ADDRESS":"http://[::1]:8080",
"testdata":{
"username":"root",
"password":"root"
}
}

View File

@ -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()
)
)
)
)
)

16
tests/lib.coffee Normal file
View File

@ -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)
)