2016-08-14 14:22:11 +02:00
|
|
|
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)
|
2016-08-17 22:35:25 +02:00
|
|
|
if(typeof body == "string")
|
|
|
|
body = JSON.parse(body)
|
|
|
|
expect(body.data).to.be.true
|
2016-08-20 01:17:28 +02:00
|
|
|
expect(body.error).to.be.undefined
|
2016-08-14 14:22:11 +02:00
|
|
|
done()
|
|
|
|
)
|
|
|
|
)
|
2016-08-20 01:17:28 +02:00
|
|
|
describe('invite',->
|
|
|
|
describe('list',->
|
|
|
|
it('-> validate',(done)->
|
|
|
|
lib.login((j)->
|
|
|
|
request({method: 'GET',uri:config.ADDRESS+"/invite",jar:j},(err,res,body)->
|
|
|
|
expect(err).to.be.null
|
|
|
|
expect(res.statusCode).to.be.equal(200)
|
|
|
|
if(typeof body == "string")
|
|
|
|
body = JSON.parse(body)
|
|
|
|
console.log(body.data)
|
|
|
|
expect(body.error).to.be.null
|
|
|
|
expect(body.session.login).to.be.undefined
|
|
|
|
done()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2016-08-14 14:22:11 +02:00
|
|
|
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)
|
2016-08-17 22:35:25 +02:00
|
|
|
if(typeof body == "string")
|
|
|
|
body = JSON.parse(body)
|
2016-08-14 14:22:11 +02:00
|
|
|
expect(body.data).to.be.false
|
2016-08-17 22:35:25 +02:00
|
|
|
expect(body.error.msg).to.not.be.null
|
|
|
|
expect(body.error.fields).to.include('username')
|
2016-08-14 14:22:11 +02:00
|
|
|
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)
|
2016-08-17 22:35:25 +02:00
|
|
|
if(typeof body == "string")
|
|
|
|
body = JSON.parse(body)
|
2016-08-14 14:22:11 +02:00
|
|
|
expect(body.data).to.be.false
|
2016-08-17 22:35:25 +02:00
|
|
|
expect(body.error.msg).to.not.be.null
|
|
|
|
expect(body.error.fields).to.include('password')
|
2016-08-14 14:22:11 +02:00
|
|
|
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)
|
2016-08-17 22:35:25 +02:00
|
|
|
if(typeof body == "string")
|
|
|
|
body = JSON.parse(body)
|
2016-08-14 14:22:11 +02:00
|
|
|
expect(body.data).to.be.true
|
2016-08-17 22:35:25 +02:00
|
|
|
expect(body.error).to.be.null
|
2016-08-14 14:22:11 +02:00
|
|
|
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)
|
2016-08-17 22:35:25 +02:00
|
|
|
if(typeof body == "string")
|
|
|
|
body = JSON.parse(body)
|
|
|
|
expect(body.data).to.be.false
|
|
|
|
expect(body.error.msg).to.not.be.null
|
|
|
|
expect(body.error.fields).to.include('session')
|
2016-08-14 14:22:11 +02:00
|
|
|
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)
|
2016-08-17 22:35:25 +02:00
|
|
|
if(typeof body == "string")
|
|
|
|
body = JSON.parse(body)
|
|
|
|
expect(body.data).to.be.true
|
|
|
|
expect(body.error).to.be.null
|
|
|
|
expect(body.session.login).to.be.null
|
2016-08-14 14:22:11 +02:00
|
|
|
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)
|
2016-08-17 22:35:25 +02:00
|
|
|
if(typeof body == "string")
|
|
|
|
body = JSON.parse(body)
|
|
|
|
expect(body.data).to.be.false
|
|
|
|
expect(body.error.msg).to.not.be.null
|
|
|
|
expect(body.error.fields).to.include('session')
|
|
|
|
expect(body.session.login).to.be.null
|
2016-08-14 14:22:11 +02:00
|
|
|
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)
|
2016-08-17 22:35:25 +02:00
|
|
|
if(typeof body == "string")
|
|
|
|
body = JSON.parse(body)
|
|
|
|
expect(body.data).to.be.false
|
|
|
|
expect(body.error.msg).to.not.be.null
|
|
|
|
expect(body.error.fields).to.include('currentpassword')
|
|
|
|
expect(body.session.login).to.not.be.null
|
2016-08-14 14:22:11 +02:00
|
|
|
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)
|
2016-08-17 22:35:25 +02:00
|
|
|
if(typeof body == "string")
|
|
|
|
body = JSON.parse(body)
|
|
|
|
expect(body.data).to.be.false
|
|
|
|
expect(body.error.msg).to.not.be.null
|
|
|
|
expect(body.error.fields).to.include('newpassword')
|
|
|
|
expect(body.session.login).to.not.be.null
|
2016-08-14 14:22:11 +02:00
|
|
|
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)
|
2016-08-17 22:35:25 +02:00
|
|
|
if(typeof body == "string")
|
|
|
|
body = JSON.parse(body)
|
|
|
|
expect(body.data).to.be.true
|
|
|
|
expect(body.error).to.be.null
|
2016-08-14 14:22:11 +02:00
|
|
|
request({method: 'POST',uri: config.ADDRESS+"/password",json:{
|
|
|
|
currentpassword: config.testdata.password+"f",
|
|
|
|
newpassword: config.testdata.password,
|
|
|
|
},jar:j},(err,res,body)->
|
2016-08-17 22:35:25 +02:00
|
|
|
expect(body.data).to.be.true
|
2016-08-14 14:22:11 +02:00
|
|
|
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)
|
2016-08-17 22:35:25 +02:00
|
|
|
if(typeof body == "string")
|
|
|
|
body = JSON.parse(body)
|
|
|
|
expect(body.data).to.be.false
|
|
|
|
expect(body.error.msg).to.not.be.null
|
|
|
|
expect(body.error.fields).to.include('session')
|
|
|
|
expect(body.session.login).to.be.null
|
2016-08-14 14:22:11 +02:00
|
|
|
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)
|
2016-08-17 22:35:25 +02:00
|
|
|
if(typeof body == "string")
|
|
|
|
body = JSON.parse(body)
|
|
|
|
expect(body.data).to.be.true
|
|
|
|
expect(body.error).to.be.null
|
|
|
|
expect(body.session.login).to.be.null
|
2016-08-14 14:22:11 +02:00
|
|
|
done()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|