2017-08-22 23:26:29 +02:00
|
|
|
/**
|
|
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
**/
|
|
|
|
|
|
|
|
var should = require("should");
|
|
|
|
var sinon = require("sinon");
|
|
|
|
var request = require("supertest");
|
|
|
|
var express = require("express");
|
|
|
|
var editorApi = require("../../../../red/api/editor");
|
|
|
|
var comms = require("../../../../red/api/editor/comms");
|
2017-12-04 18:15:17 +01:00
|
|
|
var info = require("../../../../red/api/editor/settings");
|
2017-12-06 14:18:36 +01:00
|
|
|
var auth = require("../../../../red/api/auth");
|
2018-04-24 16:01:49 +02:00
|
|
|
|
|
|
|
var log = require("../../../../red/util/log");
|
|
|
|
|
|
|
|
|
2017-12-06 14:18:36 +01:00
|
|
|
var when = require("when");
|
2017-08-22 23:26:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
describe("api/editor/index", function() {
|
|
|
|
var app;
|
|
|
|
describe("disabled the editor", function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
sinon.stub(comms,'init', function(){});
|
2017-12-04 18:15:17 +01:00
|
|
|
sinon.stub(info,'init', function(){});
|
2017-08-22 23:26:29 +02:00
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
comms.init.restore();
|
2017-12-04 18:15:17 +01:00
|
|
|
info.init.restore();
|
2017-08-22 23:26:29 +02:00
|
|
|
});
|
|
|
|
it("disables the editor", function() {
|
2018-04-24 16:01:49 +02:00
|
|
|
var editorApp = editorApi.init({},{disableEditor:true},{});
|
2017-08-22 23:26:29 +02:00
|
|
|
should.not.exist(editorApp);
|
|
|
|
comms.init.called.should.be.false();
|
2017-12-04 18:15:17 +01:00
|
|
|
info.init.called.should.be.false();
|
2017-08-22 23:26:29 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("enables the editor", function() {
|
|
|
|
var mockList = [
|
2018-01-16 17:18:18 +01:00
|
|
|
'library','theme','locales','credentials','comms',"settings"
|
2017-08-22 23:26:29 +02:00
|
|
|
]
|
|
|
|
var isStarted = true;
|
|
|
|
var errors = [];
|
2017-12-06 14:18:36 +01:00
|
|
|
var session_data = {};
|
2017-08-22 23:26:29 +02:00
|
|
|
before(function() {
|
2018-01-16 17:18:18 +01:00
|
|
|
sinon.stub(auth,'needsPermission',function(permission) {
|
|
|
|
return function(req,res,next) { next(); }
|
|
|
|
});
|
2017-08-22 23:26:29 +02:00
|
|
|
mockList.forEach(function(m) {
|
|
|
|
sinon.stub(require("../../../../red/api/editor/"+m),"init",function(){});
|
|
|
|
});
|
|
|
|
sinon.stub(require("../../../../red/api/editor/theme"),"app",function(){ return express()});
|
|
|
|
});
|
|
|
|
after(function() {
|
|
|
|
mockList.forEach(function(m) {
|
|
|
|
require("../../../../red/api/editor/"+m).init.restore();
|
|
|
|
})
|
|
|
|
require("../../../../red/api/editor/theme").app.restore();
|
2018-01-16 17:18:18 +01:00
|
|
|
auth.needsPermission.restore();
|
2018-04-24 16:01:49 +02:00
|
|
|
log.error.restore();
|
2017-08-22 23:26:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
before(function() {
|
2018-04-24 16:01:49 +02:00
|
|
|
sinon.stub(log,"error",function(err) { errors.push(err)})
|
|
|
|
app = editorApi.init({},{httpNodeRoot:true, httpAdminRoot: true,disableEditor:false,exportNodeSettings:function(){}},{
|
|
|
|
isStarted: () => Promise.resolve(isStarted)
|
2017-08-22 23:26:29 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
it('serves the editor', function(done) {
|
|
|
|
request(app)
|
|
|
|
.get("/")
|
|
|
|
.expect(200)
|
|
|
|
.end(function(err,res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
// Index page should probably mention Node-RED somewhere
|
|
|
|
res.text.indexOf("Node-RED").should.not.eql(-1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('serves icons', function(done) {
|
|
|
|
request(app)
|
|
|
|
.get("/icons/inject.png")
|
|
|
|
.expect("Content-Type", /image\/png/)
|
|
|
|
.expect(200,done)
|
|
|
|
});
|
|
|
|
it('handles page not there', function(done) {
|
|
|
|
request(app)
|
|
|
|
.get("/foo")
|
|
|
|
.expect(404,done)
|
|
|
|
});
|
|
|
|
it('warns if runtime not started', function(done) {
|
|
|
|
isStarted = false;
|
|
|
|
request(app)
|
|
|
|
.get("/")
|
|
|
|
.expect(503)
|
|
|
|
.end(function(err,res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
res.text.should.eql("Not started");
|
|
|
|
errors.should.have.lengthOf(1);
|
|
|
|
errors[0].should.eql("Node-RED runtime not started");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-04-24 16:01:49 +02:00
|
|
|
// it.skip('GET /settings', function(done) {
|
2018-01-16 17:18:18 +01:00
|
|
|
// request(app).get("/settings").expect(200).end(function(err,res) {
|
|
|
|
// if (err) {
|
|
|
|
// return done(err);
|
|
|
|
// }
|
|
|
|
// // permissionChecks.should.have.property('settings.read',1);
|
|
|
|
// done();
|
|
|
|
// })
|
|
|
|
// });
|
2017-08-22 23:26:29 +02:00
|
|
|
});
|
|
|
|
});
|