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

239 lines
6.9 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('add',->
it('-> validate',(done)->
lib.login((j)->
invite = {
username: 'test',
password:'test'
}
request({method: 'POST',uri:config.ADDRESS+"/invite",jar:j,json:invite},(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.error).to.be.undefined
expect(body.data).to.be.true
expect(body.session.login).to.not.be.null
done()
)
)
)
)
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)
expect(body.error).to.be.undefined
expect(body.data).to.be.a("array")
expect(body.session.login).to.not.be.null
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.undefined
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.undefined
expect(body.session.login).to.be.undefined
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.undefined
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.undefined
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.undefined
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.undefined
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.undefined
expect(body.session.login).to.be.undefined
done()
)
)
)
)
)