sum7/warehost-frontend
sum7
/
warehost-frontend
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
warehost-frontend/tests/index.coffee

219 lines
6.3 KiB
CoffeeScript

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)
if(typeof body == "string")
body = JSON.parse(body)
expect(body.data).to.be.true
expect(body.error).to.be.undefined
done()
)
)
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()
)
)
)
)
)
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)
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('username')
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)
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('password')
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)
if(typeof body == "string")
body = JSON.parse(body)
expect(body.data).to.be.true
expect(body.error).to.be.null
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)
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')
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)
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
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)
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
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)
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
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)
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
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)
if(typeof body == "string")
body = JSON.parse(body)
expect(body.data).to.be.true
expect(body.error).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)->
expect(body.data).to.be.true
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)
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
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)
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
done()
)
)
)
)
)