1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Fix various tests due to projects rework

This commit is contained in:
Nick O'Leary 2018-01-16 16:18:18 +00:00
parent 1f3f32d377
commit 52475df783
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
7 changed files with 77 additions and 44 deletions

View File

@ -23,7 +23,7 @@ var info = require("./settings");
var auth = require("../auth"); var auth = require("../auth");
var nodes = require("../admin/nodes"); // TODO: move /icons into here var nodes = require("../admin/nodes"); // TODO: move /icons into here
var needsPermission = auth.needsPermission; var needsPermission;
var runtime; var runtime;
var log; var log;
var apiUtil = require("../util"); var apiUtil = require("../util");
@ -41,6 +41,7 @@ module.exports = {
init: function(server, _runtime) { init: function(server, _runtime) {
runtime = _runtime; runtime = _runtime;
log = runtime.log; log = runtime.log;
needsPermission = auth.needsPermission;
var settings = runtime.settings; var settings = runtime.settings;
if (!settings.disableEditor) { if (!settings.disableEditor) {
info.init(runtime); info.init(runtime);

View File

@ -29,6 +29,7 @@ var Projects = require("./Project");
var settings; var settings;
var runtime; var runtime;
var log;
var projectsEnabled = true; var projectsEnabled = true;
var projectLogMessages = []; var projectLogMessages = [];

View File

@ -47,12 +47,15 @@ describe("api/editor/index", function() {
}); });
describe("enables the editor", function() { describe("enables the editor", function() {
var mockList = [ var mockList = [
'library','theme','locales','credentials','comms' 'library','theme','locales','credentials','comms',"settings"
] ]
var isStarted = true; var isStarted = true;
var errors = []; var errors = [];
var session_data = {}; var session_data = {};
before(function() { before(function() {
sinon.stub(auth,'needsPermission',function(permission) {
return function(req,res,next) { next(); }
});
mockList.forEach(function(m) { mockList.forEach(function(m) {
sinon.stub(require("../../../../red/api/editor/"+m),"init",function(){}); sinon.stub(require("../../../../red/api/editor/"+m),"init",function(){});
}); });
@ -63,28 +66,10 @@ describe("api/editor/index", function() {
require("../../../../red/api/editor/"+m).init.restore(); require("../../../../red/api/editor/"+m).init.restore();
}) })
require("../../../../red/api/editor/theme").app.restore(); require("../../../../red/api/editor/theme").app.restore();
auth.needsPermission.restore();
}); });
before(function() { before(function() {
auth.init({
settings:{
adminAuth: {
default: {
permissions: ['read']
}
},
storage: {
getSessions: function(){
return when.resolve(session_data);
},
setSessions: function(_session) {
session_data = _session;
return when.resolve();
}
},
log:{audit:function(){},error:function(msg){errors.push(msg)}}
}
});
app = editorApi.init({},{ app = editorApi.init({},{
log:{audit:function(){},error:function(msg){errors.push(msg)}}, log:{audit:function(){},error:function(msg){errors.push(msg)}},
settings:{httpNodeRoot:true, httpAdminRoot: true,disableEditor:false,exportNodeSettings:function(){}}, settings:{httpNodeRoot:true, httpAdminRoot: true,disableEditor:false,exportNodeSettings:function(){}},
@ -132,14 +117,14 @@ describe("api/editor/index", function() {
done(); done();
}); });
}); });
it('GET /settings', function(done) { // it('GET /settings', function(done) {
request(app).get("/settings").expect(200).end(function(err,res) { // request(app).get("/settings").expect(200).end(function(err,res) {
if (err) { // if (err) {
return done(err); // return done(err);
} // }
// permissionChecks.should.have.property('settings.read',1); // // permissionChecks.should.have.property('settings.read',1);
done(); // done();
}) // })
}); // });
}); });
}); });

View File

@ -48,9 +48,11 @@ describe("api/editor/settings", function() {
} }
}, },
nodes: { nodes: {
paletteEditorEnabled: function() { return true; } paletteEditorEnabled: function() { return true; },
getCredentialKeyType: function() { return "test-key-type"}
}, },
log: { error: console.error } log: { error: console.error },
storage: {}
}); });
request(app) request(app)
.get("/settings") .get("/settings")
@ -65,7 +67,45 @@ describe("api/editor/settings", function() {
res.body.should.have.property("editorTheme",{test:456}); res.body.should.have.property("editorTheme",{test:456});
res.body.should.have.property("testNodeSetting","helloWorld"); res.body.should.have.property("testNodeSetting","helloWorld");
res.body.should.not.have.property("foo",123); res.body.should.not.have.property("foo",123);
res.body.should.have.property("flowEncryptionType","test-key-type");
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',
getCredentialsFilename: () => 'test-creds-file'
}
}
});
request(app)
.get("/settings")
.expect(200)
.end(function(err,res) {
if (err) {
return done(err);
}
res.body.should.have.property("project","test-active-project");
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');
done(); done();
}); });
}); });
@ -78,9 +118,13 @@ describe("api/editor/settings", function() {
exportNodeSettings: function() {} exportNodeSettings: function() {}
}, },
nodes: { nodes: {
paletteEditorEnabled: function() { return false; } paletteEditorEnabled: function() { return false; },
getCredentialKeyType: function() { return "test-key-type"}
}, },
log: { error: console.error } log: { error: console.error },
storage: {}
}); });
request(app) request(app)
.get("/settings") .get("/settings")

View File

@ -73,10 +73,10 @@ describe("api/index", function() {
}); });
}); });
after(afterEach); after(afterEach);
it('exposes the editor',function() { it('exposes the editor',function(done) {
request(api.adminApp).get("/editor").expect(200).end(done); request(api.adminApp).get("/editor").expect(200).end(done);
}) })
it('exposes the admin api',function() { it('exposes the admin api',function(done) {
request(api.adminApp).get("/admin").expect(200).end(done); request(api.adminApp).get("/admin").expect(200).end(done);
}) })
it('exposes the auth api',function(done) { it('exposes the auth api',function(done) {
@ -92,10 +92,10 @@ describe("api/index", function() {
}); });
}); });
after(afterEach); after(afterEach);
it('does not expose the editor',function() { it('does not expose the editor',function(done) {
request(api.adminApp).get("/editor").expect(404).end(done); request(api.adminApp).get("/editor").expect(404).end(done);
}) })
it('exposes the admin api',function() { it('exposes the admin api',function(done) {
request(api.adminApp).get("/admin").expect(200).end(done); request(api.adminApp).get("/admin").expect(200).end(done);
}) })
it('exposes the auth api',function(done) { it('exposes the auth api',function(done) {

View File

@ -136,7 +136,7 @@ describe("red/nodes/index", function() {
var userDir = path.join(__dirname,".testUserHome"); var userDir = path.join(__dirname,".testUserHome");
before(function(done) { before(function(done) {
sinon.stub(log,"log"); sinon.stub(log,"log",function(){});
fs.remove(userDir,function(err) { fs.remove(userDir,function(err) {
fs.mkdir(userDir,function() { fs.mkdir(userDir,function() {
sinon.stub(index, 'load', function() { sinon.stub(index, 'load', function() {
@ -159,7 +159,7 @@ describe("red/nodes/index", function() {
}); });
after(function(done) { after(function(done) {
fs.remove(userDir,function() {; fs.remove(userDir,function() {
runtime.stop().then(function() { runtime.stop().then(function() {
index.load.restore(); index.load.restore();
localfilesystem.getCredentials.restore(); localfilesystem.getCredentials.restore();

View File

@ -26,7 +26,9 @@ describe('storage/localfilesystem', function() {
var mockRuntime = { var mockRuntime = {
log:{ log:{
_:function() { return "placeholder message"}, _:function() { return "placeholder message"},
info: function() { } info: function() { },
warn: function() { },
trace: function() {}
} }
}; };
var userDir = path.join(__dirname,".testUserHome"); var userDir = path.join(__dirname,".testUserHome");
@ -290,7 +292,7 @@ describe('storage/localfilesystem', function() {
it('should fsync the flows file',function(done) { it('should fsync the flows file',function(done) {
var flowFile = 'test.json'; var flowFile = 'test.json';
var flowFilePath = path.join(userDir,flowFile); var flowFilePath = path.join(userDir,flowFile);
localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() { localfilesystem.init({userDir:userDir, flowFile:flowFilePath}, mockRuntime).then(function() {
sinon.spy(fs,"fsync"); sinon.spy(fs,"fsync");
localfilesystem.saveFlows(testFlow).then(function() { localfilesystem.saveFlows(testFlow).then(function() {
fs.fsync.callCount.should.eql(1); fs.fsync.callCount.should.eql(1);
@ -307,7 +309,7 @@ describe('storage/localfilesystem', function() {
it('should log fsync errors and continue',function(done) { it('should log fsync errors and continue',function(done) {
var flowFile = 'test.json'; var flowFile = 'test.json';
var flowFilePath = path.join(userDir,flowFile); var flowFilePath = path.join(userDir,flowFile);
localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() { localfilesystem.init({userDir:userDir, flowFile:flowFilePath}, mockRuntime).then(function() {
sinon.stub(fs,"fsync", function(fd, cb) { sinon.stub(fs,"fsync", function(fd, cb) {
cb(new Error()); cb(new Error());
}); });