2014-11-06 23:59:48 +01:00
|
|
|
/**
|
2017-01-11 16:24:33 +01:00
|
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
2014-11-06 23:59:48 +01:00
|
|
|
*
|
|
|
|
* 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();
|
2017-12-04 18:15:17 +01:00
|
|
|
var info = require("../../../../red/api/editor/settings");
|
2017-08-22 23:26:29 +02:00
|
|
|
var theme = require("../../../../red/api/editor/theme");
|
2015-04-13 23:15:15 +02:00
|
|
|
|
2017-12-04 18:15:17 +01:00
|
|
|
describe("api/editor/settings", function() {
|
2014-11-06 23:59:48 +01:00
|
|
|
describe("settings handler", function() {
|
|
|
|
before(function() {
|
2015-04-13 23:15:15 +02:00
|
|
|
sinon.stub(theme,"settings",function() { return { test: 456 };});
|
2014-11-06 23:59:48 +01:00
|
|
|
app = express();
|
2017-12-04 18:15:17 +01:00
|
|
|
app.get("/settings",info.runtimeSettings);
|
2018-05-09 11:03:22 +02:00
|
|
|
app.get("/settingsWithUser",function(req,res,next) {
|
|
|
|
req.user = {
|
|
|
|
username: "nick",
|
|
|
|
permissions: "*",
|
|
|
|
image: "http://example.com",
|
|
|
|
anonymous: false,
|
|
|
|
private: "secret"
|
|
|
|
}
|
|
|
|
next();
|
|
|
|
},info.runtimeSettings);
|
2014-11-06 23:59:48 +01:00
|
|
|
});
|
2015-03-06 11:18:33 +01:00
|
|
|
|
2014-11-06 23:59:48 +01:00
|
|
|
after(function() {
|
2015-04-13 23:15:15 +02:00
|
|
|
theme.settings.restore();
|
2014-11-06 23:59:48 +01:00
|
|
|
});
|
2015-03-06 11:18:33 +01:00
|
|
|
|
2014-11-06 23:59:48 +01:00
|
|
|
it('returns the filtered settings', function(done) {
|
2016-10-12 23:30:32 +02:00
|
|
|
info.init({
|
|
|
|
settings: {
|
|
|
|
foo: 123,
|
|
|
|
httpNodeRoot: "testHttpNodeRoot",
|
|
|
|
version: "testVersion",
|
2017-03-01 16:01:07 +01:00
|
|
|
paletteCategories :["red","blue","green"],
|
|
|
|
exportNodeSettings: function(obj) {
|
|
|
|
obj.testNodeSetting = "helloWorld";
|
|
|
|
}
|
2016-10-12 23:30:32 +02:00
|
|
|
},
|
|
|
|
nodes: {
|
2018-01-16 17:18:18 +01:00
|
|
|
paletteEditorEnabled: function() { return true; },
|
|
|
|
getCredentialKeyType: function() { return "test-key-type"}
|
2017-12-04 18:15:17 +01:00
|
|
|
},
|
2018-01-16 17:18:18 +01:00
|
|
|
log: { error: console.error },
|
|
|
|
storage: {}
|
2016-10-12 23:30:32 +02:00
|
|
|
});
|
2014-11-06 23:59:48 +01:00
|
|
|
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");
|
2015-03-06 15:14:47 +01:00
|
|
|
res.body.should.have.property("paletteCategories",["red","blue","green"]);
|
2015-04-13 23:15:15 +02:00
|
|
|
res.body.should.have.property("editorTheme",{test:456});
|
2017-03-01 16:01:07 +01:00
|
|
|
res.body.should.have.property("testNodeSetting","helloWorld");
|
2014-11-06 23:59:48 +01:00
|
|
|
res.body.should.not.have.property("foo",123);
|
2018-01-16 17:18:18 +01:00
|
|
|
res.body.should.have.property("flowEncryptionType","test-key-type");
|
2018-05-09 11:03:22 +02:00
|
|
|
res.body.should.not.have.property("user");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('returns the filtered user in 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; },
|
|
|
|
getCredentialKeyType: function() { return "test-key-type"}
|
|
|
|
},
|
|
|
|
log: { error: console.error },
|
|
|
|
storage: {}
|
|
|
|
});
|
|
|
|
request(app)
|
|
|
|
.get("/settingsWithUser")
|
|
|
|
.expect(200)
|
|
|
|
.end(function(err,res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
res.body.should.have.property("user");
|
|
|
|
res.body.user.should.have.property("username","nick");
|
|
|
|
res.body.user.should.have.property("permissions","*");
|
|
|
|
res.body.user.should.have.property("image","http://example.com");
|
|
|
|
res.body.user.should.have.property("anonymous",false);
|
|
|
|
res.body.user.should.not.have.property("private");
|
|
|
|
|
2018-01-16 17:18:18 +01:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('includes project settings if projects available', 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; },
|
|
|
|
getCredentialKeyType: function() { return "test-key-type"}
|
|
|
|
},
|
|
|
|
log: { error: console.error },
|
|
|
|
storage: {
|
|
|
|
projects: {
|
|
|
|
getActiveProject: () => 'test-active-project',
|
|
|
|
getFlowFilename: () => 'test-flow-file',
|
2018-01-24 22:24:54 +01:00
|
|
|
getCredentialsFilename: () => 'test-creds-file',
|
|
|
|
getGlobalGitUser: () => {return {name:'foo',email:'foo@example.com'}}
|
2018-01-16 17:18:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
request(app)
|
|
|
|
.get("/settings")
|
|
|
|
.expect(200)
|
|
|
|
.end(function(err,res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
res.body.should.have.property("project","test-active-project");
|
2018-02-21 17:38:36 +01:00
|
|
|
res.body.should.not.have.property("files");
|
|
|
|
res.body.should.have.property("git");
|
|
|
|
res.body.git.should.have.property("globalUser",{name:'foo',email:'foo@example.com'});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('includes existing files details if projects enabled but no active project and files exist', 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; },
|
|
|
|
getCredentialKeyType: function() { return "test-key-type"}
|
|
|
|
},
|
|
|
|
log: { error: console.error },
|
|
|
|
storage: {
|
|
|
|
projects: {
|
|
|
|
flowFileExists: () => true,
|
|
|
|
getActiveProject: () => false,
|
|
|
|
getFlowFilename: () => 'test-flow-file',
|
|
|
|
getCredentialsFilename: () => 'test-creds-file',
|
|
|
|
getGlobalGitUser: () => {return {name:'foo',email:'foo@example.com'}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
request(app)
|
|
|
|
.get("/settings")
|
|
|
|
.expect(200)
|
|
|
|
.end(function(err,res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
res.body.should.not.have.property("project");
|
2018-01-16 17:18:18 +01:00
|
|
|
res.body.should.have.property("files");
|
|
|
|
res.body.files.should.have.property("flow",'test-flow-file');
|
|
|
|
res.body.files.should.have.property("credentials",'test-creds-file');
|
2018-01-24 22:24:54 +01:00
|
|
|
res.body.should.have.property("git");
|
|
|
|
res.body.git.should.have.property("globalUser",{name:'foo',email:'foo@example.com'});
|
2014-11-06 23:59:48 +01:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-02-21 17:38:36 +01:00
|
|
|
it('does not include file details if projects enabled but no active project and files do not exist', 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; },
|
|
|
|
getCredentialKeyType: function() { return "test-key-type"}
|
|
|
|
},
|
|
|
|
log: { error: console.error },
|
|
|
|
storage: {
|
|
|
|
projects: {
|
|
|
|
flowFileExists: () => false,
|
|
|
|
getActiveProject: () => false,
|
|
|
|
getFlowFilename: () => 'test-flow-file',
|
|
|
|
getCredentialsFilename: () => 'test-creds-file',
|
|
|
|
getGlobalGitUser: () => {return {name:'foo',email:'foo@example.com'}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
request(app)
|
|
|
|
.get("/settings")
|
|
|
|
.expect(200)
|
|
|
|
.end(function(err,res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
res.body.should.not.have.property("project");
|
|
|
|
res.body.should.not.have.property("files");
|
|
|
|
res.body.should.have.property("git");
|
|
|
|
res.body.git.should.have.property("globalUser",{name:'foo',email:'foo@example.com'});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2016-10-12 23:30:32 +02:00
|
|
|
it('overrides palette editable if runtime says it is disabled', function(done) {
|
|
|
|
info.init({
|
|
|
|
settings: {
|
|
|
|
httpNodeRoot: "testHttpNodeRoot",
|
|
|
|
version: "testVersion",
|
2017-03-01 16:01:07 +01:00
|
|
|
paletteCategories :["red","blue","green"],
|
|
|
|
exportNodeSettings: function() {}
|
2016-10-12 23:30:32 +02:00
|
|
|
},
|
|
|
|
nodes: {
|
2018-01-16 17:18:18 +01:00
|
|
|
paletteEditorEnabled: function() { return false; },
|
|
|
|
getCredentialKeyType: function() { return "test-key-type"}
|
|
|
|
|
2017-12-04 18:15:17 +01:00
|
|
|
},
|
2018-01-16 17:18:18 +01:00
|
|
|
log: { error: console.error },
|
|
|
|
storage: {}
|
|
|
|
|
2016-10-12 23:30:32 +02:00
|
|
|
});
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
})
|
2014-11-06 23:59:48 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|