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

remove api test

This commit is contained in:
Martin Geno 2016-09-22 17:47:45 +02:00
parent 85feebfc7e
commit ad49e34e53
6 changed files with 35 additions and 934 deletions

View File

@ -1,40 +1,37 @@
{ {
"name": "warehost-webclient", "name": "warehost-client-web",
"version": "1.0.0", "version": "1.0.0",
"description": "Eventmanager for respond-collector", "description": "For the api warehost a web client",
"main": "Gruntfile.js", "main": "Gruntfile.js",
"devDependencies": { "devDependencies": {
"grunt": "^0.4.5", "grunt": "^0.4.5",
"grunt-angular-templates": "^0.5.9", "grunt-angular-templates": "^0.5.9",
"grunt-ng-annotate": "^1.0.1", "grunt-asset-injector": "^0.1.0",
"grunt-autoprefixer": "^3.0.3", "grunt-autoprefixer": "^3.0.3",
"grunt-concurrent": "^2.1.0", "grunt-concurrent": "^2.1.0",
"grunt-contrib-clean": "^0.7.0", "grunt-contrib-clean": "^0.7.0",
"grunt-contrib-concat": "^0.5.1", "grunt-contrib-concat": "^0.5.1",
"grunt-contrib-copy": "^0.8.2", "grunt-contrib-connect": "^1.0.2",
"grunt-contrib-cssmin": "^0.14.0", "grunt-contrib-copy": "^0.8.2",
"grunt-contrib-htmlmin": "^0.6.0", "grunt-contrib-cssmin": "^0.14.0",
"grunt-contrib-imagemin": "^1.0.0", "grunt-contrib-htmlmin": "^0.6.0",
"grunt-contrib-jade": "^0.15.0", "grunt-contrib-imagemin": "^1.0.0",
"grunt-contrib-jshint": "^0.11.3", "grunt-contrib-jade": "^0.15.0",
"grunt-contrib-stylus": "^0.22.0", "grunt-contrib-jshint": "^0.11.3",
"grunt-contrib-uglify": "^0.11.0", "grunt-contrib-stylus": "^0.22.0",
"grunt-contrib-watch": "^0.6.1", "grunt-contrib-uglify": "^0.11.0",
"grunt-google-cdn": "^0.4.3", "grunt-contrib-watch": "^0.6.1",
"grunt-newer": "^1.1.1", "grunt-google-cdn": "^0.4.3",
"grunt-svgmin": "^3.1.0", "grunt-newer": "^1.1.1",
"grunt-usemin": "^3.1.1", "grunt-ng-annotate": "^1.0.1",
"grunt-wiredep": "^2.0.0", "grunt-svgmin": "^3.1.0",
"jit-grunt": "^0.9.1", "grunt-usemin": "^3.1.1",
"jshint-stylish": "^2.1.0", "grunt-wiredep": "^2.0.0",
"coffee-script": "^1.9.3", "jit-grunt": "^0.9.1",
"time-grunt": "^1.2.2", "jshint-stylish": "^2.1.0",
"chai": "^3.2.0", "time-grunt": "^1.2.2"
"mocha": "^2.3.2", },
"request": "*" "scripts": {
}, "start": "grunt serve"
"scripts": { }
"start": "grunt serve",
"test": "mocha --compilers coffee:coffee-script/register tests"
}
} }

View File

@ -1,7 +0,0 @@
{
"ADDRESS":"http://[::1]:8080",
"testdata":{
"username":"root",
"password":"root"
}
}

View File

@ -1,695 +0,0 @@
expect = require("chai").expect
request = require('request')
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)->
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()
)
)
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)->
invite = {
username: 'test',
password:'test'
}
request({method: 'POST',uri:config.ADDRESS+"/invite",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.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)->
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('-> without login',(done)->
request({method: 'GET',uri:config.ADDRESS+"/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.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+"/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('admin/toggle',->
before((done)->
lib.login({
username:'test',
password:'test'
},(j)->
invite = {
username:'test_admin',
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()
)
)
)
it('-> without login (get)',(done)->
request({method: 'GET',uri:config.ADDRESS+"/invitor"},(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('-> without login (put)',(done)->
request({method: 'PUT',uri:config.ADDRESS+"/invitor"},(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 on',(done)->
lib.login({username:'test_admin',password:'test'},(j)->
request({method: 'GET',uri:config.ADDRESS+"/invitor",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.admin).to.be.false
expect(body.session.login).to.not.be.null
request({method: 'PUT',uri:config.ADDRESS+"/invitor",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
expect(body.session.login).to.not.be.null
request({method: 'GET',uri:config.ADDRESS+"/invitor",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.admin).to.be.true
expect(body.session.login).to.not.be.null
done()
)
)
)
)
)
it('-> validate off',(done)->
lib.login({username:'test_admin',password:'test'},(j)->
request({method: 'GET',uri:config.ADDRESS+"/invitor",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.admin).to.be.true
expect(body.session.login).to.not.be.null
request({method: 'PUT',uri:config.ADDRESS+"/invitor",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
expect(body.session.login).to.not.be.null
request({method: 'GET',uri:config.ADDRESS+"/invitor",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.admin).to.be.false
expect(body.session.login).to.not.be.null
done()
)
)
)
)
)
it('-> validate on',(done)->
lib.login({username:'test_admin',password:'test'},(j)->
request({method: 'GET',uri:config.ADDRESS+"/invitor",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.admin).to.be.false
expect(body.session.login).to.not.be.null
request({method: 'PUT',uri:config.ADDRESS+"/invitor",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
expect(body.session.login).to.not.be.null
request({method: 'GET',uri:config.ADDRESS+"/invitor",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.admin).to.be.true
expect(body.session.login).to.not.be.null
done()
)
)
)
)
)
)
describe('edit',->
it('-> not invited/exists',(done)->
lib.login({username:'test',password:'test'},(j)->
request({method: 'PUT',uri:config.ADDRESS+"/user/"+1,jar:j,json:{
username: 'test_not_exits',
password:'test'
}},(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.not.undefined
expect(body.data).to.be.false
expect(body.session.login).to.not.be.null
done()
)
)
)
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+"/user/"+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 = {
username: 'test_not_used',
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
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_not_used")
request({method: 'PUT',uri:config.ADDRESS+"/user/"+invited.ID,jar:j,json:{
username:'test2_not_used',
password:'test2'
}},(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, used',(done)->
lib.login({username:'test',password:'test'},(j)->
invite = {
username: 'test_used',
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
lib.login({username:'test_used',password:'test'},()->
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_used")
request({method: 'PUT',uri:config.ADDRESS+"/user/"+invited.ID,jar:j,json:{
username:'test2_not_used',
password:'test2'
}},(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.not.undefined
expect(body.data).to.be.false
expect(body.session.login).to.not.be.null
done()
)
)
)
)
)
)
it('-> superadmin',(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
invited = getIndexOfInvitedUsername(body.data,"test")
request({method: 'PUT',uri:config.ADDRESS+"/user/"+invited.ID,jar:j,json:{
username:'test2',
password:'test2'
}},(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('delete',->
it('-> not invited/exists',(done)->
lib.login({username:'test2',password:'test2'},(j)->
request({method: 'DELETE',uri:config.ADDRESS+"/user/"+1,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.not.undefined
expect(body.data).to.be.false
expect(body.session.login).to.not.be.null
done()
)
)
)
it('-> invited, admin',(done)->
lib.login({username:'test2',password:'test2'},(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: 'DELETE',uri:config.ADDRESS+"/user/"+invited.ID,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
expect(body.session.login).to.not.be.null
done()
)
)
)
)
it('-> invited, not used',(done)->
lib.login({username:'test2',password:'test2'},(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_not_used")
request({method: 'DELETE',uri:config.ADDRESS+"/user/"+invited.ID,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
expect(body.session.login).to.not.be.null
done()
)
)
)
)
it('-> invited, used',(done)->
lib.login({username:'test2',password:'test2'},(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_used")
request({method: 'DELETE',uri:config.ADDRESS+"/user/"+invited.ID,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.not.undefined
expect(body.data).to.be.false
expect(body.session.login).to.not.be.null
done()
)
)
)
)
it('-> superadmin',(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
invited = getIndexOfInvitedUsername(body.data,"test2")
request({method: 'DELETE',uri:config.ADDRESS+"/user/"+invited.ID,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
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.error).to.be.undefined
expect(body.data).to.be.true
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.error).to.be.undefined
expect(body.data).to.be.true
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()
)
)
)
)
)
modules()
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({username:'test_used',password:'test'},(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.error).to.be.undefined
expect(body.data).to.be.true
expect(body.session.login).to.be.undefined
done()
)
)
)
)
)

View File

@ -1,21 +0,0 @@
expect = require("chai").expect
request = require('request')
config = require('./config')
module.exports.login = (args,args2)->
j = request.jar()
login = {
username: config.testdata.username,
password: config.testdata.password
}
call = args
if args2
login = args
call = args2
request({method: 'POST',uri: config.ADDRESS+"/login",json:login,jar:j},(err,res,body)->
expect(err).to.be.null
expect(res.statusCode).to.be.equal(200)
expect(body.data).to.be.true
call(j,body.session)
)

View File

@ -1,6 +0,0 @@
web = require('./web')
module.exports = ()->
describe('MODULES',->
web()
)

View File

@ -1,167 +0,0 @@
expect = require("chai").expect
request = require('request')
lib = require('../lib')
config = require('../config')
module.exports = ()->
describe('web',->
websiteid = -1;
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.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('website',->
describe('add',->
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: "Test-Pls-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.error).to.be.undefined
expect(body.data).to.be.true
done()
)
)
)
)
describe('edit',->
it('-> not logged in',(done)->
request({method: 'PUT',uri:config.ADDRESS+"/web/website/"+websiteid,json:{
name: "Test-Pls-Delete2"
}},(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('-> not involved',(done)->
lib.login((j,login)->
request({method: 'PUT',uri:config.ADDRESS+"/web/website"+websiteid,json:{
name: "Test-Pls-Delete2"
},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()
)
)
)
it('-> validate',(done)->
lib.login({username:'test_used',password:'test'},(j,login)->
request({method: 'PUT',uri:config.ADDRESS+"/web/website"+websiteid,json:{
name: "Test-Pls-Delete2"
},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()
)
)
)
)
describe('delete',->
it('-> try',(done)->done())
)
)
describe('permissions',->
describe('add',->
it('-> try',(done)->done())
)
describe('delete',->
it('-> try',(done)->done())
)
)
describe('domain',->
describe('add',->
it('-> try',(done)->done())
)
describe('edit',->
it('-> try',(done)->done())
)
describe('delete',->
it('-> try',(done)->done())
)
)
describe('page',->
describe('add',->
it('-> try',(done)->done())
)
describe('edit',->
it('-> try',(done)->done())
)
describe('delete',->
it('-> try',(done)->done())
)
)
describe('menu',->
describe('add',->
it('-> try',(done)->done())
)
describe('edit',->
it('-> try',(done)->done())
)
describe('delete',->
it('-> try',(done)->done())
)
)
describe('media',->
describe('add',->
it('-> try',(done)->done())
)
describe('edit',->
it('-> try',(done)->done())
)
describe('delete',->
it('-> try',(done)->done())
)
)
)