mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Tidy up API passed to node modules
This commit is contained in:
@@ -30,7 +30,7 @@ describe('credentials api', function() {
|
||||
app.get('/credentials/:type/:id',credentials.get);
|
||||
credentials.init({
|
||||
log:{audit:function(){}},
|
||||
api:{
|
||||
nodes:{
|
||||
getCredentials: function(id) {
|
||||
if (id === "n1") {
|
||||
return {user1:"abc",password1:"123"};
|
||||
|
@@ -37,7 +37,7 @@ describe("flows api", function() {
|
||||
it('returns flow', function(done) {
|
||||
flows.init({
|
||||
log:{warn:function(){},_:function(){},audit:function(){}},
|
||||
api:{
|
||||
nodes:{
|
||||
getFlows: function() { return [1,2,3]; }
|
||||
}
|
||||
});
|
||||
@@ -58,7 +58,7 @@ describe("flows api", function() {
|
||||
var setFlows = sinon.spy(function() { return when.resolve();});
|
||||
flows.init({
|
||||
log:{warn:function(){},_:function(){},audit:function(){}},
|
||||
api:{
|
||||
nodes:{
|
||||
setFlows: setFlows
|
||||
}
|
||||
});
|
||||
@@ -79,7 +79,7 @@ describe("flows api", function() {
|
||||
var setFlows = sinon.spy(function() { return when.resolve();});
|
||||
flows.init({
|
||||
log:{warn:function(){},_:function(){},audit:function(){}},
|
||||
api:{
|
||||
nodes:{
|
||||
setFlows: setFlows
|
||||
}
|
||||
});
|
||||
@@ -102,7 +102,7 @@ describe("flows api", function() {
|
||||
var loadFlows = sinon.spy(function() { return when.resolve(); });
|
||||
flows.init({
|
||||
log:{warn:function(){},_:function(){},audit:function(){}},
|
||||
api:{
|
||||
nodes:{
|
||||
loadFlows: loadFlows
|
||||
}
|
||||
});
|
||||
@@ -123,7 +123,7 @@ describe("flows api", function() {
|
||||
it('returns error when set fails', function(done) {
|
||||
flows.init({
|
||||
log:{warn:function(){},_:function(){},audit:function(){}},
|
||||
api:{
|
||||
nodes:{
|
||||
setFlows: function() { return when.reject(new Error("expected error")); }
|
||||
}
|
||||
});
|
||||
|
@@ -32,7 +32,7 @@ describe("api index", function() {
|
||||
settings:{httpNodeRoot:true, httpAdminRoot: true,disableEditor:true},
|
||||
events: {on:function(){},removeListener: function(){}}
|
||||
});
|
||||
app = api.adminApp();
|
||||
app = api.adminApp;
|
||||
});
|
||||
|
||||
it('does not serve the editor', function(done) {
|
||||
@@ -72,7 +72,7 @@ describe("api index", function() {
|
||||
storage:{getSessions:function(){return when.resolve({})}},
|
||||
events:{on:function(){},removeListener:function(){}}
|
||||
});
|
||||
app = api.adminApp();
|
||||
app = api.adminApp;
|
||||
});
|
||||
|
||||
it('it now serves auth', function(done) {
|
||||
@@ -109,7 +109,7 @@ describe("api index", function() {
|
||||
settings:{httpNodeRoot:true, httpAdminRoot: true,disableEditor:false},
|
||||
events:{on:function(){},removeListener:function(){}}
|
||||
});
|
||||
app = api.adminApp();
|
||||
app = api.adminApp;
|
||||
});
|
||||
it('serves the editor', function(done) {
|
||||
request(app)
|
||||
|
@@ -62,7 +62,7 @@ describe("nodes api", function() {
|
||||
describe('get nodes', function() {
|
||||
it('returns node list', function(done) {
|
||||
initNodes({
|
||||
api:{
|
||||
nodes:{
|
||||
getNodeList: function() {
|
||||
return [1,2,3];
|
||||
}
|
||||
@@ -83,7 +83,7 @@ describe("nodes api", function() {
|
||||
|
||||
it('returns node configs', function(done) {
|
||||
initNodes({
|
||||
api:{
|
||||
nodes:{
|
||||
getNodeConfigs: function() {
|
||||
return "<script></script>";
|
||||
}
|
||||
@@ -107,7 +107,7 @@ describe("nodes api", function() {
|
||||
|
||||
it('returns node module info', function(done) {
|
||||
initNodes({
|
||||
api:{
|
||||
nodes:{
|
||||
getModuleInfo: function(id) {
|
||||
return {"node-red":{name:"node-red"}}[id];
|
||||
}
|
||||
@@ -127,7 +127,7 @@ describe("nodes api", function() {
|
||||
|
||||
it('returns 404 for unknown module', function(done) {
|
||||
initNodes({
|
||||
api:{
|
||||
nodes:{
|
||||
getModuleInfo: function(id) {
|
||||
return {"node-red":{name:"node-red"}}[id];
|
||||
}
|
||||
@@ -146,7 +146,7 @@ describe("nodes api", function() {
|
||||
|
||||
it('returns individual node info', function(done) {
|
||||
initNodes({
|
||||
api:{
|
||||
nodes:{
|
||||
getNodeInfo: function(id) {
|
||||
return {"node-red/123":{id:"node-red/123"}}[id];
|
||||
}
|
||||
@@ -167,7 +167,7 @@ describe("nodes api", function() {
|
||||
|
||||
it('returns individual node configs', function(done) {
|
||||
initNodes({
|
||||
api:{
|
||||
nodes:{
|
||||
getNodeConfig: function(id) {
|
||||
return {"node-red/123":"<script></script>"}[id];
|
||||
}
|
||||
@@ -191,7 +191,7 @@ describe("nodes api", function() {
|
||||
|
||||
it('returns 404 for unknown node', function(done) {
|
||||
initNodes({
|
||||
api:{
|
||||
nodes:{
|
||||
getNodeInfo: function(id) {
|
||||
return {"node-red/123":{id:"node-red/123"}}[id];
|
||||
}
|
||||
@@ -247,7 +247,7 @@ describe("nodes api", function() {
|
||||
it('installs the module and returns module info', function(done) {
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
api:{
|
||||
nodes:{
|
||||
getModuleInfo: function(id) { return null; },
|
||||
installModule: function() {
|
||||
return when.resolve({
|
||||
@@ -275,7 +275,7 @@ describe("nodes api", function() {
|
||||
it('fails the install if already installed', function(done) {
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
api:{
|
||||
nodes:{
|
||||
getModuleInfo: function(id) { return {nodes:{id:"123"}}; },
|
||||
installModule: function() {
|
||||
return when.resolve({id:"123"});
|
||||
@@ -297,7 +297,7 @@ describe("nodes api", function() {
|
||||
it('fails the install if module error', function(done) {
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
api:{
|
||||
nodes:{
|
||||
getModuleInfo: function(id) { return null },
|
||||
installModule: function() {
|
||||
return when.reject(new Error("test error"));
|
||||
@@ -319,7 +319,7 @@ describe("nodes api", function() {
|
||||
it('fails the install if module not found', function(done) {
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
api:{
|
||||
nodes:{
|
||||
getModuleInfo: function(id) { return null },
|
||||
installModule: function() {
|
||||
var err = new Error("test error");
|
||||
@@ -362,7 +362,7 @@ describe("nodes api", function() {
|
||||
it('uninstalls the module', function(done) {
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
api:{
|
||||
nodes:{
|
||||
getModuleInfo: function(id) { return {nodes:[{id:"123"}]} },
|
||||
getNodeInfo: function() { return null },
|
||||
uninstallModule: function() { return when.resolve({id:"123"});}
|
||||
@@ -382,7 +382,7 @@ describe("nodes api", function() {
|
||||
it('fails the uninstall if the module is not installed', function(done) {
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
api:{
|
||||
nodes:{
|
||||
getModuleInfo: function(id) { return null },
|
||||
getNodeInfo: function() { return null }
|
||||
}
|
||||
@@ -401,7 +401,7 @@ describe("nodes api", function() {
|
||||
it('fails the uninstall if the module is not installed', function(done) {
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
api:{
|
||||
nodes:{
|
||||
getModuleInfo: function(id) { return {nodes:[{id:"123"}]} },
|
||||
getNodeInfo: function() { return null },
|
||||
uninstallModule: function() { return when.reject(new Error("test error"));}
|
||||
@@ -476,7 +476,7 @@ describe("nodes api", function() {
|
||||
it('returns 404 for unknown node', function(done) {
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
api:{
|
||||
nodes:{
|
||||
getNodeInfo: function() { return null }
|
||||
}
|
||||
});
|
||||
@@ -496,7 +496,7 @@ describe("nodes api", function() {
|
||||
it('returns 404 for unknown module', function(done) {
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
api:{
|
||||
nodes:{
|
||||
getModuleInfo: function(id) { return null }
|
||||
}
|
||||
});
|
||||
@@ -516,7 +516,7 @@ describe("nodes api", function() {
|
||||
it('enables disabled node', function(done) {
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
api:{
|
||||
nodes:{
|
||||
getNodeInfo: function() { return {id:"123",enabled: false} },
|
||||
enableNode: function() { return when.resolve({id:"123",enabled: true,types:['a']}); }
|
||||
}
|
||||
@@ -539,7 +539,7 @@ describe("nodes api", function() {
|
||||
it('disables enabled node', function(done) {
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
api:{
|
||||
nodes:{
|
||||
getNodeInfo: function() { return {id:"123",enabled: true} },
|
||||
disableNode: function() { return when.resolve({id:"123",enabled: false,types:['a']}); }
|
||||
}
|
||||
@@ -566,7 +566,7 @@ describe("nodes api", function() {
|
||||
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
api:{
|
||||
nodes:{
|
||||
getNodeInfo: function() { return {id:"123",enabled: state} },
|
||||
enableNode: enableNode,
|
||||
disableNode: disableNode
|
||||
@@ -605,7 +605,7 @@ describe("nodes api", function() {
|
||||
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
api:{
|
||||
nodes:{
|
||||
getNodeInfo: function() { return {id:"123",enabled: state, err:"foo"} },
|
||||
enableNode: enableNode,
|
||||
disableNode: disableNode
|
||||
@@ -652,7 +652,7 @@ describe("nodes api", function() {
|
||||
enableNode.returns(null);
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
api:{
|
||||
nodes:{
|
||||
getModuleInfo: function() { return {name:"node-red", nodes:[n1, n2]} },
|
||||
enableNode: enableNode
|
||||
}
|
||||
@@ -690,7 +690,7 @@ describe("nodes api", function() {
|
||||
disableNode.returns(null);
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
api:{
|
||||
nodes:{
|
||||
getModuleInfo: function() { return {name:"node-red", nodes:[n1, n2]} },
|
||||
disableNode: disableNode
|
||||
}
|
||||
@@ -727,7 +727,7 @@ describe("nodes api", function() {
|
||||
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
api:{
|
||||
nodes:{
|
||||
getModuleInfo: function() { return {name:"node-red", nodes:[node]}; },
|
||||
enableNode: enableNode,
|
||||
disableNode: disableNode
|
||||
@@ -774,7 +774,7 @@ describe("nodes api", function() {
|
||||
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
api:{
|
||||
nodes:{
|
||||
getModuleInfo: function() { return {name:"node-red", nodes:[node]}; },
|
||||
enableNode: enableNode,
|
||||
disableNode: disableNode
|
||||
|
@@ -44,16 +44,19 @@ describe("runtime", function() {
|
||||
beforeEach(function() {
|
||||
sinon.stub(log,"init",function() {});
|
||||
sinon.stub(settings,"init",function() {});
|
||||
sinon.stub(redNodes,"init",function() {})
|
||||
});
|
||||
afterEach(function() {
|
||||
log.init.restore();
|
||||
settings.init.restore();
|
||||
redNodes.init.restore();
|
||||
})
|
||||
|
||||
it("initialises components", function() {
|
||||
runtime.init({testSettings: true, httpAdminRoot:"/"});
|
||||
log.init.called.should.be.true;
|
||||
settings.init.called.should.be.true;
|
||||
redNodes.init.called.should.be.true;
|
||||
});
|
||||
|
||||
it("returns version", function() {
|
||||
|
@@ -44,7 +44,7 @@ describe("red/nodes/registry/loader",function() {
|
||||
})
|
||||
describe("#init",function() {
|
||||
it("init",function() {
|
||||
loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}}});
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}}});
|
||||
localfilesystem.init.called.should.be.true;
|
||||
});
|
||||
});
|
||||
@@ -53,7 +53,7 @@ describe("red/nodes/registry/loader",function() {
|
||||
it("load empty set without settings available", function(done) {
|
||||
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ return {};}));
|
||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};}));
|
||||
loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return false;}}});
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return false;}}});
|
||||
loader.load("foo",true).then(function() {
|
||||
localfilesystem.getNodeFiles.called.should.be.true;
|
||||
localfilesystem.getNodeFiles.lastCall.args[0].should.eql('foo');
|
||||
@@ -65,7 +65,7 @@ describe("red/nodes/registry/loader",function() {
|
||||
it("load empty set with settings available triggers registery save", function(done) {
|
||||
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ return {};}));
|
||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};}));
|
||||
loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.load("foo",true).then(function() {
|
||||
registry.saveNodeList.called.should.be.true;
|
||||
done();
|
||||
@@ -96,7 +96,7 @@ describe("red/nodes/registry/loader",function() {
|
||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||
|
||||
stubs.push(sinon.stub(nodes,"registerType"));
|
||||
loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.load().then(function(result) {
|
||||
registry.addNodeSet.called.should.be.true;
|
||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode1");
|
||||
@@ -143,7 +143,7 @@ describe("red/nodes/registry/loader",function() {
|
||||
// This module isn't already loaded
|
||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||
stubs.push(sinon.stub(nodes,"registerType"));
|
||||
loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.load().then(function(result) {
|
||||
registry.addNodeSet.called.should.be.true;
|
||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/MultipleNodes1");
|
||||
@@ -194,7 +194,7 @@ describe("red/nodes/registry/loader",function() {
|
||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||
|
||||
stubs.push(sinon.stub(nodes,"registerType"));
|
||||
loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.load().then(function(result) {
|
||||
registry.addNodeSet.called.should.be.true;
|
||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode2");
|
||||
@@ -243,7 +243,7 @@ describe("red/nodes/registry/loader",function() {
|
||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||
|
||||
stubs.push(sinon.stub(nodes,"registerType"));
|
||||
loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.load().then(function(result) {
|
||||
registry.addNodeSet.called.should.be.true;
|
||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode3");
|
||||
@@ -290,7 +290,7 @@ describe("red/nodes/registry/loader",function() {
|
||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||
|
||||
stubs.push(sinon.stub(nodes,"registerType"));
|
||||
loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.load().then(function(result) {
|
||||
registry.addNodeSet.called.should.be.true;
|
||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/DoesNotExist");
|
||||
@@ -317,7 +317,7 @@ describe("red/nodes/registry/loader",function() {
|
||||
|
||||
describe("#addModule",function() {
|
||||
it("throws error if settings unavailable", function() {
|
||||
loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return false;}}});
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return false;}}});
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
loader.addModule("test-module");
|
||||
@@ -326,7 +326,7 @@ describe("red/nodes/registry/loader",function() {
|
||||
|
||||
it("returns rejected error if module already loaded", function(done) {
|
||||
stubs.push(sinon.stub(registry,"getModuleInfo",function(){return{}}));
|
||||
loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
|
||||
loader.addModule("test-module").otherwise(function(err) {
|
||||
err.code.should.eql("module_already_loaded");
|
||||
@@ -338,7 +338,7 @@ describe("red/nodes/registry/loader",function() {
|
||||
stubs.push(sinon.stub(localfilesystem,"getModuleFiles",function() {
|
||||
throw new Error("failure");
|
||||
}));
|
||||
loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.addModule("test-module").otherwise(function(err) {
|
||||
err.message.should.eql("failure");
|
||||
done();
|
||||
@@ -370,7 +370,7 @@ describe("red/nodes/registry/loader",function() {
|
||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" }));
|
||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
||||
stubs.push(sinon.stub(nodes,"registerType"));
|
||||
loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.addModule("TestNodeModule").then(function(result) {
|
||||
result.should.eql("a node list");
|
||||
registry.addNodeSet.calledOnce.should.be.true;
|
||||
@@ -420,7 +420,7 @@ describe("red/nodes/registry/loader",function() {
|
||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" }));
|
||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
||||
stubs.push(sinon.stub(nodes,"registerType"));
|
||||
loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},version: function() { return "0.12.0"}, settings:{available:function(){return true;}}});
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},version: function() { return "0.12.0"}, settings:{available:function(){return true;}}});
|
||||
loader.addModule("TestNodeModule").then(function(result) {
|
||||
result.should.eql("a node list");
|
||||
registry.addNodeSet.called.should.be.false;
|
||||
|
Reference in New Issue
Block a user