lpio
Version:
The last dashboard app you'll ever need
120 lines (105 loc) • 4.39 kB
JavaScript
var assert = require("chai").assert;
var Q = require('q');
var request = require('superagent');
var Promise = require('promise');
var agent = require('superagent-promise')(require('superagent'), Promise);
var log = require('../log');
var config = require('../config');
var server = require('../server');
var base_url = "http://localhost:"+config.app_settings.port;
var test_dash_id = null;
describe('LinchPin API',function(){
before(function(done){
server.start()
.then(function(){
done();
});
});
describe('CRUD dashboard',function(){
it('should be able to create a new dashboard',function(done){
this.timeout(5000); // Some extra time for db init
agent.post(base_url+'/v1/dashboard',{
name: 'My first Dashboard',
layout: {"some":"layout object"}
})
.then(function(response){
log.info({res:response.body});
assert.isObject(response.body);
assert.equal(response.body.status,"ok","Status should be ok");
test_dash_id = response.body.data.id;
assert.isAbove(test_dash_id.length,5,"id should be at least 5 chars:"+test_dash_id);
done();
})
.catch(function(err){
done(err);
})
});
it('should be able to retrieve the dashboard',function(done){
agent.get(base_url+'/v1/dashboard/'+test_dash_id)
.then(function(response){
log.info({res:response.body});
assert.isObject(response.body);
assert.isObject(response.body.dashboard);
assert.equal(response.body.dashboard._id,test_dash_id);
done();
})
.catch(function(err){
done(err);
})
});
it('should be able to retrieve ALL dashboards',function(done){
agent.get(base_url+'/v1/dashboard/_all')
.then(function(response){
log.info({res:response.body});
assert.isArray(response.body);
assert.isAbove(response.body.length,0)
assert.isObject(response.body[0]);
done();
})
.catch(function(err){
done(err);
})
});
it('should be able to update the dashboard',function(done){
agent.put(base_url+'/v1/dashboard/'+test_dash_id,{
name:"Another name",
layout: {"some":"layout object"}
})
.then(function(response){
log.info({res:response.body});
assert.isObject(response.body);
assert.equal(response.body.status,"ok","Status should be ok");
return agent.get(base_url+'/v1/dashboard/'+test_dash_id)
})
.then(function(response){
assert.isObject(response.body);
assert.isObject(response.body.dashboard);
assert.equal(response.body.dashboard._id,test_dash_id);
assert.equal(response.body.dashboard.name,"Another name");
done();
})
.catch(function(err){
done(err);
})
});
it('should be able to delete the dashboard',function(done){
agent.del(base_url+'/v1/dashboard/'+test_dash_id)
.then(function(response){
log.info({res:response.body});
assert.isObject(response.body);
assert.equal(response.body.status,"ok","Status should be ok");
return agent.get(base_url+'/v1/dashboard/'+test_dash_id)
})
.then(function(response){
done(new Error("Should not be found"));
})
.catch(function(err){
if(err.status == 404){
done();
} else {
done(err);
}
});
});
});
});