WIP: separate runtime and api components

This commit is contained in:
Nick O'Leary
2015-11-11 22:11:02 +00:00
parent 923a46d304
commit f43738446e
49 changed files with 695 additions and 612 deletions

View File

@@ -15,12 +15,12 @@
**/
var should = require("should");
var sinon = require("sinon");
var request = require("supertest");
var express = require("express");
var when = require("when");
var fs = require("fs");
var path = require("path");
var settings = require("../../../red/settings");
var api = require("../../../red/api");
describe("api index", function() {
@@ -28,12 +28,13 @@ describe("api index", function() {
describe("disables editor", function() {
before(function() {
settings.init({disableEditor:true});
app = express();
api.init(app);
});
after(function() {
settings.reset();
api.init(app,{
settings:{disableEditor:true},
api:{
}
});
});
it('does not serve the editor', function(done) {
@@ -54,14 +55,25 @@ describe("api index", function() {
});
describe("can serve auth", function() {
var mockList = [
'ui','nodes','flows','library','info','theme','locales','credentials'
]
before(function() {
//settings.init({disableEditor:true});
settings.init({adminAuth:{type: "credentials",users:[],default:{permissions:"read"}}});
app = express();
api.init(app,{getSessions:function(){return when.resolve({})}});
mockList.forEach(function(m) {
sinon.stub(require("../../../red/api/"+m),"init",function(){});
});
});
after(function() {
settings.reset();
mockList.forEach(function(m) {
require("../../../red/api/"+m).init.restore();
})
});
before(function() {
app = express();
api.init(app,{
settings:{adminAuth:{type: "credentials",users:[],default:{permissions:"read"}}},
storage:{getSessions:function(){return when.resolve({})}}
});
});
it('it now serves auth', function(done) {
@@ -77,15 +89,29 @@ describe("api index", function() {
});
describe("enables editor", function() {
var mockList = [
'nodes','flows','library','info','theme','locales','credentials'
]
before(function() {
settings.init({disableEditor:false});
app = express();
api.init(app);
mockList.forEach(function(m) {
sinon.stub(require("../../../red/api/"+m),"init",function(){});
});
});
after(function() {
settings.reset();
mockList.forEach(function(m) {
require("../../../red/api/"+m).init.restore();
})
});
before(function() {
app = express();
api.init(app,{
log:{audit:function(){}},
settings:{disableEditor:false},
events:{on:function(){},removeListener:function(){}}
});
});
it('serves the editor', function(done) {
request(app)
.get("/")