add Tests
This commit is contained in:
parent
669faeae87
commit
ef659724c7
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "warehost client",
|
||||
"name": "warehost-webclient",
|
||||
"authors": [
|
||||
"Martin Geno <geno+dev@fireorbit.de>"
|
||||
],
|
||||
|
|
11
package.json
11
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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"ADDRESS":"http://[::1]:8080",
|
||||
"testdata":{
|
||||
"username":"root",
|
||||
"password":"root"
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
|
@ -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)
|
||||
)
|
Reference in New Issue