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

testing ready

This commit is contained in:
Martin Geno 2016-09-03 13:24:27 +02:00
parent 908f09a014
commit 044bfd7eca
2 changed files with 111 additions and 35 deletions

View File

@ -6,6 +6,12 @@ lib = require('./lib')
config = require('./config') config = require('./config')
modules = require('./modul') modules = require('./modul')
getIndexOfInvitedUsername = (list,username) ->
for i in [0..list.length]
if(list[i].invited.username==username)
return list[i].invited
return null
describe('API',-> describe('API',->
it('status',(done)-> it('status',(done)->
request({method: 'GET',uri:config.ADDRESS+"/status"},(err,res,body)-> request({method: 'GET',uri:config.ADDRESS+"/status"},(err,res,body)->
@ -18,6 +24,17 @@ describe('API',->
done() done()
) )
) )
it('modules',(done)->
request({method: 'GET',uri:config.ADDRESS+"/modules"},(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.a("array")
expect(body.error).to.be.undefined
done()
)
)
describe('invite',-> describe('invite',->
describe('add',-> describe('add',->
it('-> without login',(done)-> it('-> without login',(done)->
@ -77,7 +94,6 @@ describe('API',->
body = JSON.parse(body) body = JSON.parse(body)
expect(body.error).to.be.undefined expect(body.error).to.be.undefined
expect(body.data).to.be.a("array") expect(body.data).to.be.a("array")
expect(body.data).to.have.length(1)
expect(body.session.login).to.not.be.null expect(body.session.login).to.not.be.null
done() done()
) )
@ -245,6 +261,33 @@ describe('API',->
) )
) )
) )
it('-> invited, admin',(done)->
lib.login({username:'test',password:'test'},(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
invited = getIndexOfInvitedUsername(body.data,"test_admin")
request({method: 'PUT',uri:config.ADDRESS+"/invite/"+invited.ID,jar:j,json:{
username:'test2_admin',
password:'test2_admin'
}},(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()
)
)
)
)
it('-> invited, not used',(done)-> it('-> invited, not used',(done)->
lib.login({username:'test',password:'test'},(j)-> lib.login({username:'test',password:'test'},(j)->
invite = { invite = {
@ -265,9 +308,10 @@ describe('API',->
if(typeof body == "string") if(typeof body == "string")
body = JSON.parse(body) body = JSON.parse(body)
expect(body.error).to.be.undefined expect(body.error).to.be.undefined
expect(body.data).to.have.length(1) expect(body.data).to.be.a("array")
expect(body.session.login).to.not.be.null expect(body.session.login).to.not.be.null
request({method: 'PUT',uri:config.ADDRESS+"/invite/"+body.data[0].invited.ID,jar:j,json:{ invited = getIndexOfInvitedUsername(body.data,"test_not_used")
request({method: 'PUT',uri:config.ADDRESS+"/invite/"+invited.ID,jar:j,json:{
username:'test2_not_used', username:'test2_not_used',
password:'test2' password:'test2'
}},(err,res,body)-> }},(err,res,body)->
@ -305,12 +349,10 @@ describe('API',->
if(typeof body == "string") if(typeof body == "string")
body = JSON.parse(body) body = JSON.parse(body)
expect(body.error).to.be.undefined expect(body.error).to.be.undefined
expect(body.data).to.have.length(2) expect(body.data).to.be.a("array")
expect(body.session.login).to.not.be.null expect(body.session.login).to.not.be.null
i = 0 invited = getIndexOfInvitedUsername(body.data,"test_used")
if(body.data[0].invited.username!="test_used") request({method: 'PUT',uri:config.ADDRESS+"/invite/"+invited.ID,jar:j,json:{
i = 1
request({method: 'PUT',uri:config.ADDRESS+"/invite/"+body.data[i].invited.ID,jar:j,json:{
username:'test2_not_used', username:'test2_not_used',
password:'test2' password:'test2'
}},(err,res,body)-> }},(err,res,body)->
@ -336,9 +378,10 @@ describe('API',->
if(typeof body == "string") if(typeof body == "string")
body = JSON.parse(body) body = JSON.parse(body)
expect(body.error).to.be.undefined expect(body.error).to.be.undefined
expect(body.data).to.have.length(1) expect(body.data).to.be.a("array")
expect(body.session.login).to.not.be.null expect(body.session.login).to.not.be.null
request({method: 'PUT',uri:config.ADDRESS+"/invite/"+body.data[0].invited.ID,jar:j,json:{ invited = getIndexOfInvitedUsername(body.data,"test")
request({method: 'PUT',uri:config.ADDRESS+"/invite/"+invited.ID,jar:j,json:{
username:'test2', username:'test2',
password:'test2' password:'test2'
}},(err,res,body)-> }},(err,res,body)->
@ -378,14 +421,10 @@ describe('API',->
if(typeof body == "string") if(typeof body == "string")
body = JSON.parse(body) body = JSON.parse(body)
expect(body.error).to.be.undefined expect(body.error).to.be.undefined
expect(body.data).to.have.length(2) expect(body.data).to.be.a("array")
expect(body.session.login).to.not.be.null expect(body.session.login).to.not.be.null
i = 0 invited = getIndexOfInvitedUsername(body.data,"test_admin")
if(body.data[i].invited.username!="test_admin") request({method: 'DELETE',uri:config.ADDRESS+"/invite/"+invited.ID,jar:j},(err,res,body)->
i = 1
if(body.data[i].invited.username!="test_admin")
i = 2
request({method: 'DELETE',uri:config.ADDRESS+"/invite/"+body.data[i].invited.ID,jar:j},(err,res,body)->
expect(err).to.be.null expect(err).to.be.null
expect(res.statusCode).to.be.equal(200) expect(res.statusCode).to.be.equal(200)
if(typeof body == "string") if(typeof body == "string")
@ -406,12 +445,10 @@ describe('API',->
if(typeof body == "string") if(typeof body == "string")
body = JSON.parse(body) body = JSON.parse(body)
expect(body.error).to.be.undefined expect(body.error).to.be.undefined
expect(body.data).to.have.length(2) expect(body.data).to.be.a("array")
expect(body.session.login).to.not.be.null expect(body.session.login).to.not.be.null
i = 0 invited = getIndexOfInvitedUsername(body.data,"test_not_used")
if(body.data[0].invited.username!="test_not_used") request({method: 'DELETE',uri:config.ADDRESS+"/invite/"+invited.ID,jar:j},(err,res,body)->
i = 1
request({method: 'DELETE',uri:config.ADDRESS+"/invite/"+body.data[i].invited.ID,jar:j},(err,res,body)->
expect(err).to.be.null expect(err).to.be.null
expect(res.statusCode).to.be.equal(200) expect(res.statusCode).to.be.equal(200)
if(typeof body == "string") if(typeof body == "string")
@ -432,12 +469,10 @@ describe('API',->
if(typeof body == "string") if(typeof body == "string")
body = JSON.parse(body) body = JSON.parse(body)
expect(body.error).to.be.undefined expect(body.error).to.be.undefined
expect(body.data).to.have.length(1) expect(body.data).to.be.a("array")
expect(body.session.login).to.not.be.null expect(body.session.login).to.not.be.null
i = 0 invited = getIndexOfInvitedUsername(body.data,"test_used")
if(body.data[0].invited.username!="test_used") request({method: 'DELETE',uri:config.ADDRESS+"/invite/"+invited.ID,jar:j},(err,res,body)->
i = 1
request({method: 'DELETE',uri:config.ADDRESS+"/invite/"+body.data[i].invited.ID,jar:j},(err,res,body)->
expect(err).to.be.null expect(err).to.be.null
expect(res.statusCode).to.be.equal(200) expect(res.statusCode).to.be.equal(200)
if(typeof body == "string") if(typeof body == "string")
@ -458,9 +493,10 @@ describe('API',->
if(typeof body == "string") if(typeof body == "string")
body = JSON.parse(body) body = JSON.parse(body)
expect(body.error).to.be.undefined expect(body.error).to.be.undefined
expect(body.data).to.have.length(1) expect(body.data).to.be.a("array")
expect(body.session.login).to.not.be.null expect(body.session.login).to.not.be.null
request({method: 'DELETE',uri:config.ADDRESS+"/invite/"+body.data[0].invited.ID,jar:j},(err,res,body)-> invited = getIndexOfInvitedUsername(body.data,"test2")
request({method: 'DELETE',uri:config.ADDRESS+"/invite/"+invited.ID,jar:j},(err,res,body)->
expect(err).to.be.null expect(err).to.be.null
expect(res.statusCode).to.be.equal(200) expect(res.statusCode).to.be.equal(200)
if(typeof body == "string") if(typeof body == "string")

View File

@ -7,18 +7,58 @@ config = require('../config')
module.exports = ()-> module.exports = ()->
describe('web',-> describe('web',->
it('test of test',(done)-> describe('involve',->
lib.login((j,login)-> it('-> not logged in',(done)->
request({method: 'GET',uri:config.ADDRESS+"/web/involve",jar:j},(err,res,body)-> request({method: 'GET',uri:config.ADDRESS+"/web/involve"},(err,res,body)->
expect(err).to.be.null expect(err).to.be.null
expect(res.statusCode).to.be.equal(200) expect(res.statusCode).to.be.equal(200)
if(typeof body == "string") if(typeof body == "string")
body = JSON.parse(body) body = JSON.parse(body)
expect(body.error).to.be.undefined expect(body.error).to.not.be.undefined
expect(body.data).to.be.a("array") expect(body.data).to.be.false
console.log(login,body.data)
done() done()
) )
) )
it('-> validate',(done)->
lib.login({username:'test_used',password:'test'},(j,login)->
request({method: 'GET',uri:config.ADDRESS+"/web/involve",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")
done()
)
)
)
)
describe('add website',->
it('-> not logged in',(done)->
request({method: 'POST',uri:config.ADDRESS+"/web/website"},(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.not.be.undefined
expect(body.data).to.be.false
done()
)
)
it('-> validate',(done)->
lib.login({username:'test_used',password:'test'},(j,login)->
request({method: 'POST',uri:config.ADDRESS+"/web/website",json:{
name: "FireSystem"
},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.true
done()
)
)
)
) )
) )