Add /settings/user end point

This commit is contained in:
Nick O'Leary
2017-12-04 17:15:17 +00:00
parent a7e14f1093
commit fff0b15ae5
8 changed files with 102 additions and 41 deletions

View File

@@ -24,7 +24,6 @@ var auth = require("../../../../red/api/auth");
var nodes = require("../../../../red/api/admin/nodes");
var flows = require("../../../../red/api/admin/flows");
var flow = require("../../../../red/api/admin/flow");
var info = require("../../../../red/api/admin/info");
/**
* Ensure all API routes are correctly mounted, with the expected permissions checks
@@ -33,7 +32,7 @@ describe("api/admin/index", function() {
describe("Ensure all API routes are correctly mounted, with the expected permissions checks", function() {
var app;
var mockList = [
flows,flow,info,nodes
flows,flow,nodes
]
var permissionChecks = {};
var lastRequest;
@@ -68,8 +67,6 @@ describe("api/admin/index", function() {
sinon.stub(nodes,"getSet",stubApp);
sinon.stub(nodes,"putSet",stubApp);
sinon.stub(info,"settings",stubApp);
});
after(function() {
mockList.forEach(function(m) {
@@ -91,7 +88,6 @@ describe("api/admin/index", function() {
nodes.getSet.restore();
nodes.putSet.restore();
info.settings.restore();
});
before(function() {
@@ -285,15 +281,5 @@ describe("api/admin/index", function() {
done();
})
});
it('GET /settings', function(done) {
request(app).get("/settings").expect(200).end(function(err,res) {
if (err) {
return done(err);
}
permissionChecks.should.have.property('settings.read',1);
done();
})
});
});
});

View File

@@ -1,102 +0,0 @@
/**
* 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 request = require('supertest');
var express = require('express');
var sinon = require('sinon');
var when = require('when');
var app = express();
var info = require("../../../../red/api/admin/info");
var theme = require("../../../../red/api/editor/theme");
describe("api/admin/info", function() {
describe("settings handler", function() {
before(function() {
sinon.stub(theme,"settings",function() { return { test: 456 };});
app = express();
app.get("/settings",info.settings);
});
after(function() {
theme.settings.restore();
});
it('returns the filtered settings', function(done) {
info.init({
settings: {
foo: 123,
httpNodeRoot: "testHttpNodeRoot",
version: "testVersion",
paletteCategories :["red","blue","green"],
exportNodeSettings: function(obj) {
obj.testNodeSetting = "helloWorld";
}
},
nodes: {
paletteEditorEnabled: function() { return true; }
}
});
request(app)
.get("/settings")
.expect(200)
.end(function(err,res) {
if (err) {
return done(err);
}
res.body.should.have.property("httpNodeRoot","testHttpNodeRoot");
res.body.should.have.property("version","testVersion");
res.body.should.have.property("paletteCategories",["red","blue","green"]);
res.body.should.have.property("editorTheme",{test:456});
res.body.should.have.property("testNodeSetting","helloWorld");
res.body.should.not.have.property("foo",123);
done();
});
});
it('overrides palette editable if runtime says it is disabled', function(done) {
info.init({
settings: {
httpNodeRoot: "testHttpNodeRoot",
version: "testVersion",
paletteCategories :["red","blue","green"],
exportNodeSettings: function() {}
},
nodes: {
paletteEditorEnabled: function() { return false; }
}
});
request(app)
.get("/settings")
.expect(200)
.end(function(err,res) {
if (err) {
return done(err);
}
res.body.should.have.property("httpNodeRoot","testHttpNodeRoot");
res.body.should.have.property("version","testVersion");
res.body.should.have.property("paletteCategories",["red","blue","green"]);
res.body.should.have.property("editorTheme");
res.body.editorTheme.should.have.property("test",456);
res.body.editorTheme.should.have.property("palette",{editable:false});
done();
});
})
});
});