From 044bfd7eca220000cd16eceac71a9fe7f44885c8 Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Sat, 3 Sep 2016 13:24:27 +0200 Subject: [PATCH] testing ready --- tests/index.coffee | 94 +++++++++++++++++++++++++++++------------- tests/modul/web.coffee | 52 ++++++++++++++++++++--- 2 files changed, 111 insertions(+), 35 deletions(-) diff --git a/tests/index.coffee b/tests/index.coffee index 54bd42b..a53ad3f 100644 --- a/tests/index.coffee +++ b/tests/index.coffee @@ -6,6 +6,12 @@ lib = require('./lib') config = require('./config') 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',-> it('status',(done)-> request({method: 'GET',uri:config.ADDRESS+"/status"},(err,res,body)-> @@ -18,6 +24,17 @@ describe('API',-> 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('add',-> it('-> without login',(done)-> @@ -77,7 +94,6 @@ describe('API',-> body = JSON.parse(body) expect(body.error).to.be.undefined expect(body.data).to.be.a("array") - expect(body.data).to.have.length(1) expect(body.session.login).to.not.be.null 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)-> lib.login({username:'test',password:'test'},(j)-> invite = { @@ -265,9 +308,10 @@ describe('API',-> if(typeof body == "string") body = JSON.parse(body) 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 - 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', password:'test2' }},(err,res,body)-> @@ -305,12 +349,10 @@ describe('API',-> if(typeof body == "string") body = JSON.parse(body) 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 - i = 0 - if(body.data[0].invited.username!="test_used") - i = 1 - request({method: 'PUT',uri:config.ADDRESS+"/invite/"+body.data[i].invited.ID,jar:j,json:{ + invited = getIndexOfInvitedUsername(body.data,"test_used") + request({method: 'PUT',uri:config.ADDRESS+"/invite/"+invited.ID,jar:j,json:{ username:'test2_not_used', password:'test2' }},(err,res,body)-> @@ -336,9 +378,10 @@ describe('API',-> if(typeof body == "string") body = JSON.parse(body) 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 - 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', password:'test2' }},(err,res,body)-> @@ -378,14 +421,10 @@ describe('API',-> if(typeof body == "string") body = JSON.parse(body) 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 - i = 0 - if(body.data[i].invited.username!="test_admin") - 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)-> + invited = getIndexOfInvitedUsername(body.data,"test_admin") + request({method: 'DELETE',uri:config.ADDRESS+"/invite/"+invited.ID,jar:j},(err,res,body)-> expect(err).to.be.null expect(res.statusCode).to.be.equal(200) if(typeof body == "string") @@ -406,12 +445,10 @@ describe('API',-> if(typeof body == "string") body = JSON.parse(body) 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 - i = 0 - if(body.data[0].invited.username!="test_not_used") - i = 1 - request({method: 'DELETE',uri:config.ADDRESS+"/invite/"+body.data[i].invited.ID,jar:j},(err,res,body)-> + invited = getIndexOfInvitedUsername(body.data,"test_not_used") + request({method: 'DELETE',uri:config.ADDRESS+"/invite/"+invited.ID,jar:j},(err,res,body)-> expect(err).to.be.null expect(res.statusCode).to.be.equal(200) if(typeof body == "string") @@ -432,12 +469,10 @@ describe('API',-> if(typeof body == "string") body = JSON.parse(body) 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 - i = 0 - if(body.data[0].invited.username!="test_used") - i = 1 - request({method: 'DELETE',uri:config.ADDRESS+"/invite/"+body.data[i].invited.ID,jar:j},(err,res,body)-> + invited = getIndexOfInvitedUsername(body.data,"test_used") + request({method: 'DELETE',uri:config.ADDRESS+"/invite/"+invited.ID,jar:j},(err,res,body)-> expect(err).to.be.null expect(res.statusCode).to.be.equal(200) if(typeof body == "string") @@ -458,9 +493,10 @@ describe('API',-> if(typeof body == "string") body = JSON.parse(body) 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 - 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(res.statusCode).to.be.equal(200) if(typeof body == "string") diff --git a/tests/modul/web.coffee b/tests/modul/web.coffee index e7e9d79..1167cc4 100644 --- a/tests/modul/web.coffee +++ b/tests/modul/web.coffee @@ -7,18 +7,58 @@ config = require('../config') module.exports = ()-> describe('web',-> - it('test of test',(done)-> - lib.login((j,login)-> - request({method: 'GET',uri:config.ADDRESS+"/web/involve",jar:j},(err,res,body)-> + describe('involve',-> + it('-> not logged in',(done)-> + request({method: 'GET',uri:config.ADDRESS+"/web/involve"},(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") - console.log(login,body.data) + 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: '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() + ) + ) + ) ) )