mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Moved get node set response to /nodes/:mod/:set
Updated tests Changed plugin back to module
This commit is contained in:
parent
0ff65f6805
commit
d614b7c39f
@ -52,10 +52,12 @@ function init(adminApp) {
|
||||
adminApp.get("/nodes",nodes.getAll);
|
||||
adminApp.post("/nodes",nodes.post);
|
||||
|
||||
adminApp.get("/nodes/:id",nodes.get);
|
||||
adminApp.get("/nodes/:mod",nodes.getModule);
|
||||
adminApp.put("/nodes/:id",nodes.put);
|
||||
adminApp.delete("/nodes/:id",nodes.delete);
|
||||
|
||||
adminApp.get("/nodes/:mod/:set",nodes.getSet);
|
||||
|
||||
// Plugins
|
||||
adminApp.get("/plugins",plugins.getAll);
|
||||
adminApp.get("/plugins/:id",plugins.get);
|
||||
|
@ -64,7 +64,7 @@ module.exports = {
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
delete: function(req,res) {
|
||||
if (!settings.available()) {
|
||||
res.send(400,new Error("Settings unavailable").toString());
|
||||
@ -86,7 +86,7 @@ module.exports = {
|
||||
} else {
|
||||
promise = when.resolve([redNodes.removeNode(id)]).then(server.reportRemovedModules);
|
||||
}
|
||||
|
||||
|
||||
promise.then(function(removedNodes) {
|
||||
res.json(removedNodes);
|
||||
}).otherwise(function(err) {
|
||||
@ -96,11 +96,11 @@ module.exports = {
|
||||
res.send(400,err.toString());
|
||||
}
|
||||
},
|
||||
|
||||
get: function(req,res) {
|
||||
var id = req.params.id;
|
||||
|
||||
getSet: function(req,res) {
|
||||
var id = req.params.mod + "/" + req.params.set;
|
||||
var result = null;
|
||||
if (req.get("accept") == "application/json") {
|
||||
if (req.get("accept") === "application/json") {
|
||||
result = redNodes.getNodeInfo(id);
|
||||
} else {
|
||||
result = redNodes.getNodeConfig(id);
|
||||
@ -111,7 +111,17 @@ module.exports = {
|
||||
res.send(404);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
getModule: function(req,res) {
|
||||
var module = req.params.mod;
|
||||
var result = redNodes.getModuleInfo(module);
|
||||
if (result) {
|
||||
res.send(result);
|
||||
} else {
|
||||
res.send(404);
|
||||
}
|
||||
},
|
||||
|
||||
put: function(req,res) {
|
||||
if (!settings.available()) {
|
||||
res.send(400,new Error("Settings unavailable").toString());
|
||||
@ -150,6 +160,6 @@ module.exports = {
|
||||
}
|
||||
} catch(err) {
|
||||
res.send(400,err.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -18,11 +18,11 @@ var redNodes = require("../nodes");
|
||||
|
||||
module.exports = {
|
||||
getAll: function(req,res) {
|
||||
res.json(redNodes.getPluginList());
|
||||
res.json(redNodes.getModuleList());
|
||||
},
|
||||
get: function(req,res) {
|
||||
var id = req.params.id;
|
||||
var result = redNodes.getPluginInfo(id);
|
||||
var result = redNodes.getModuleInfo(id);
|
||||
if (result) {
|
||||
res.send(result);
|
||||
} else {
|
||||
|
@ -112,13 +112,18 @@ module.exports = {
|
||||
// Node type registry
|
||||
registerType: registerType,
|
||||
getType: registry.get,
|
||||
|
||||
getNodeInfo: registry.getNodeInfo,
|
||||
getNodeModuleInfo: registry.getNodeModuleInfo,
|
||||
getPluginInfo: registry.getPluginInfo,
|
||||
getNodeList: registry.getNodeList,
|
||||
getPluginList: registry.getPluginList,
|
||||
|
||||
getNodeModuleInfo: registry.getNodeModuleInfo,
|
||||
|
||||
getModuleInfo: registry.getModuleInfo,
|
||||
getModuleList: registry.getModuleList,
|
||||
|
||||
getNodeConfigs: registry.getNodeConfigs,
|
||||
getNodeConfig: registry.getNodeConfig,
|
||||
|
||||
clearRegistry: registry.clear,
|
||||
cleanNodeList: registry.cleanNodeList,
|
||||
|
||||
|
@ -161,31 +161,31 @@ var registry = (function() {
|
||||
}
|
||||
return list;
|
||||
},
|
||||
getPluginList: function() {
|
||||
getModuleList: function() {
|
||||
var list = [];
|
||||
for (var plugin in nodeModules) {
|
||||
if (nodeModules.hasOwnProperty(plugin)) {
|
||||
var nodes = nodeModules[plugin].nodes;
|
||||
for (var module in nodeModules) {
|
||||
if (nodeModules.hasOwnProperty(module)) {
|
||||
var nodes = nodeModules[module].nodes;
|
||||
var m = {
|
||||
name: plugin,
|
||||
name: module,
|
||||
nodes: []
|
||||
};
|
||||
for (var i = 0; i < nodes.length; ++i) {
|
||||
m.nodes.push(filterNodeInfo(nodeConfigs[plugin+"/"+nodes[i]]));
|
||||
m.nodes.push(filterNodeInfo(nodeConfigs[module+"/"+nodes[i]]));
|
||||
}
|
||||
list.push(m);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
},
|
||||
getPluginInfo: function(plugin) {
|
||||
var nodes = nodeModules[plugin].nodes;
|
||||
getModuleInfo: function(module) {
|
||||
var nodes = nodeModules[module].nodes;
|
||||
var m = {
|
||||
name: plugin,
|
||||
name: module,
|
||||
nodes: []
|
||||
};
|
||||
for (var i = 0; i < nodes.length; ++i) {
|
||||
m.nodes.push(filterNodeInfo(nodeConfigs[plugin+"/"+nodes[i]]));
|
||||
m.nodes.push(filterNodeInfo(nodeConfigs[module+"/"+nodes[i]]));
|
||||
}
|
||||
return m;
|
||||
},
|
||||
@ -260,7 +260,7 @@ var registry = (function() {
|
||||
return nodeTypeToId[type];
|
||||
},
|
||||
|
||||
getModuleInfo: function(type) {
|
||||
getNodeModuleInfo: function(type) {
|
||||
return nodeModules[type];
|
||||
},
|
||||
|
||||
@ -398,7 +398,7 @@ function scanTreeForNodesModules(moduleName) {
|
||||
var files = fs.readdirSync(pm);
|
||||
for (var i=0;i<files.length;i++) {
|
||||
var fn = files[i];
|
||||
if (!registry.getModuleInfo(fn)) {
|
||||
if (!registry.getNodeModuleInfo(fn)) {
|
||||
if (!moduleName || fn == moduleName) {
|
||||
var pkgfn = path.join(pm,fn,"package.json");
|
||||
try {
|
||||
@ -675,7 +675,7 @@ function addModule(module) {
|
||||
throw new Error("Settings unavailable");
|
||||
}
|
||||
var nodes = [];
|
||||
if (registry.getModuleInfo(module)) {
|
||||
if (registry.getNodeModuleInfo(module)) {
|
||||
return when.reject(new Error("Module already loaded"));
|
||||
}
|
||||
var moduleFiles = scanTreeForNodesModules(module);
|
||||
@ -695,14 +695,19 @@ module.exports = {
|
||||
load:load,
|
||||
clear: registry.clear,
|
||||
registerType: registry.registerNodeConstructor,
|
||||
|
||||
get: registry.getNodeConstructor,
|
||||
getNodeInfo: registry.getNodeInfo,
|
||||
getNodeModuleInfo: registry.getModuleInfo,
|
||||
getPluginInfo: registry.getPluginInfo,
|
||||
getNodeList: registry.getNodeList,
|
||||
getPluginList: registry.getPluginList,
|
||||
|
||||
getNodeModuleInfo: registry.getNodeModuleInfo,
|
||||
|
||||
getModuleInfo: registry.getModuleInfo,
|
||||
getModuleList: registry.getModuleList,
|
||||
|
||||
getNodeConfigs: registry.getAllNodeConfigs,
|
||||
getNodeConfig: registry.getNodeConfig,
|
||||
|
||||
addNode: addNode,
|
||||
removeNode: registry.removeNode,
|
||||
enableNode: registry.enableNodeSet,
|
||||
|
@ -28,7 +28,7 @@ var settings = require("../../../red/settings");
|
||||
var nodes = require("../../../red/api/nodes");
|
||||
|
||||
describe("nodes api", function() {
|
||||
|
||||
|
||||
var app;
|
||||
|
||||
before(function() {
|
||||
@ -36,11 +36,12 @@ describe("nodes api", function() {
|
||||
app.use(express.json());
|
||||
app.get("/nodes",nodes.getAll);
|
||||
app.post("/nodes",nodes.post);
|
||||
app.get("/nodes/:id",nodes.get);
|
||||
app.get("/nodes/:mod",nodes.getModule);
|
||||
app.get("/nodes/:mod/:set",nodes.getSet);
|
||||
app.put("/nodes/:id",nodes.put);
|
||||
app.delete("/nodes/:id",nodes.delete);
|
||||
});
|
||||
|
||||
|
||||
describe('get nodes', function() {
|
||||
it('returns node list', function(done) {
|
||||
var getNodeList = sinon.stub(redNodes,'getNodeList', function() {
|
||||
@ -59,7 +60,7 @@ describe("nodes api", function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('returns node configs', function(done) {
|
||||
var getNodeConfigs = sinon.stub(redNodes,'getNodeConfigs', function() {
|
||||
return "<script></script>";
|
||||
@ -77,13 +78,46 @@ describe("nodes api", function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an individual node info', function(done) {
|
||||
var getNodeInfo = sinon.stub(redNodes,'getNodeInfo', function(id) {
|
||||
return {"123":{id:"123"}}[id];
|
||||
|
||||
it('returns node module info', function(done) {
|
||||
var getNodeInfo = sinon.stub(redNodes,'getModuleInfo', function(id) {
|
||||
return {"node-red":{name:"node-red"}}[id];
|
||||
});
|
||||
request(app)
|
||||
.get('/nodes/123')
|
||||
.get('/nodes/node-red')
|
||||
.expect(200)
|
||||
.end(function(err,res) {
|
||||
getNodeInfo.restore();
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
res.body.should.have.property("name","node-red");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('returns 404 for unknown module', function(done) {
|
||||
var getNodeInfo = sinon.stub(redNodes,'getModuleInfo', function(id) {
|
||||
return {"node-red":{name:"node-red"}}[id];
|
||||
});
|
||||
request(app)
|
||||
.get('/nodes/node-blue')
|
||||
.expect(404)
|
||||
.end(function(err,res) {
|
||||
getNodeInfo.restore();
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('returns individual node info', function(done) {
|
||||
var getNodeInfo = sinon.stub(redNodes,'getNodeInfo', function(id) {
|
||||
return {"node-red/123":{id:"node-red/123"}}[id];
|
||||
});
|
||||
request(app)
|
||||
.get('/nodes/node-red/123')
|
||||
.set('Accept', 'application/json')
|
||||
.expect(200)
|
||||
.end(function(err,res) {
|
||||
@ -91,17 +125,17 @@ describe("nodes api", function() {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
res.body.should.have.property("id","123");
|
||||
res.body.should.have.property("id","node-red/123");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an individual node configs', function(done) {
|
||||
|
||||
it('returns individual node configs', function(done) {
|
||||
var getNodeConfig = sinon.stub(redNodes,'getNodeConfig', function(id) {
|
||||
return {"123":"<script></script>"}[id];
|
||||
return {"node-red/123":"<script></script>"}[id];
|
||||
});
|
||||
request(app)
|
||||
.get('/nodes/123')
|
||||
.get('/nodes/node-red/123')
|
||||
.set('Accept', 'text/html')
|
||||
.expect(200)
|
||||
.expect("<script></script>")
|
||||
@ -113,13 +147,13 @@ describe("nodes api", function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('returns 404 for unknown node', function(done) {
|
||||
var getNodeInfo = sinon.stub(redNodes,'getNodeInfo', function(id) {
|
||||
return {"123":{id:"123"}}[id];
|
||||
return {"node-red/123":{id:"node-red/123"}}[id];
|
||||
});
|
||||
request(app)
|
||||
.get('/nodes/456')
|
||||
.get('/nodes/node-red/456')
|
||||
.set('Accept', 'application/json')
|
||||
.expect(404)
|
||||
.end(function(err,res) {
|
||||
@ -131,9 +165,9 @@ describe("nodes api", function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('install', function() {
|
||||
|
||||
|
||||
it('returns 400 if settings are unavailable', function(done) {
|
||||
var settingsAvailable = sinon.stub(settings,'available', function() {
|
||||
return false;
|
||||
@ -166,7 +200,7 @@ describe("nodes api", function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('by module', function() {
|
||||
it('installs the module and returns node info', function(done) {
|
||||
var settingsAvailable = sinon.stub(settings,'available', function() {
|
||||
@ -178,7 +212,7 @@ describe("nodes api", function() {
|
||||
var installModule = sinon.stub(server,'installModule', function() {
|
||||
return when.resolve({id:"123"});
|
||||
});
|
||||
|
||||
|
||||
request(app)
|
||||
.post('/nodes')
|
||||
.send({module: 'foo'})
|
||||
@ -194,7 +228,7 @@ describe("nodes api", function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('fails the install if already installed', function(done) {
|
||||
var settingsAvailable = sinon.stub(settings,'available', function() {
|
||||
return true;
|
||||
@ -205,7 +239,7 @@ describe("nodes api", function() {
|
||||
var installModule = sinon.stub(server,'installModule', function() {
|
||||
return when.resolve({id:"123"});
|
||||
});
|
||||
|
||||
|
||||
request(app)
|
||||
.post('/nodes')
|
||||
.send({module: 'foo'})
|
||||
@ -220,7 +254,7 @@ describe("nodes api", function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('fails the install if module error', function(done) {
|
||||
var settingsAvailable = sinon.stub(settings,'available', function() {
|
||||
return true;
|
||||
@ -231,7 +265,7 @@ describe("nodes api", function() {
|
||||
var installModule = sinon.stub(server,'installModule', function() {
|
||||
return when.reject(new Error("test error"));
|
||||
});
|
||||
|
||||
|
||||
request(app)
|
||||
.post('/nodes')
|
||||
.send({module: 'foo'})
|
||||
@ -259,7 +293,7 @@ describe("nodes api", function() {
|
||||
err.code = 404;
|
||||
return when.reject(err);
|
||||
});
|
||||
|
||||
|
||||
request(app)
|
||||
.post('/nodes')
|
||||
.send({module: 'foo'})
|
||||
@ -292,7 +326,7 @@ describe("nodes api", function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('by module', function() {
|
||||
it('uninstalls the module and returns node info', function(done) {
|
||||
var settingsAvailable = sinon.stub(settings,'available', function() {
|
||||
@ -307,7 +341,7 @@ describe("nodes api", function() {
|
||||
var uninstallModule = sinon.stub(server,'uninstallModule', function() {
|
||||
return when.resolve({id:"123"});
|
||||
});
|
||||
|
||||
|
||||
request(app)
|
||||
.del('/nodes/foo')
|
||||
.expect(200)
|
||||
@ -323,7 +357,7 @@ describe("nodes api", function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('fails the uninstall if the module is not installed', function(done) {
|
||||
var settingsAvailable = sinon.stub(settings,'available', function() {
|
||||
return true;
|
||||
@ -334,7 +368,7 @@ describe("nodes api", function() {
|
||||
var getNodeModuleInfo = sinon.stub(redNodes,'getNodeModuleInfo',function(id) {
|
||||
return null;
|
||||
});
|
||||
|
||||
|
||||
request(app)
|
||||
.del('/nodes/foo')
|
||||
.expect(404)
|
||||
@ -381,7 +415,7 @@ describe("nodes api", function() {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('enable/disable', function() {
|
||||
it('returns 400 if settings are unavailable', function(done) {
|
||||
var settingsAvailable = sinon.stub(settings,'available', function() {
|
||||
@ -398,7 +432,7 @@ describe("nodes api", function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('returns 400 for invalid payload', function(done) {
|
||||
var settingsAvailable = sinon.stub(settings,'available', function() {
|
||||
return true;
|
||||
@ -439,7 +473,7 @@ describe("nodes api", function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('enables disabled node', function(done) {
|
||||
var settingsAvailable = sinon.stub(settings,'available', function() {
|
||||
return true;
|
||||
@ -464,7 +498,7 @@ describe("nodes api", function() {
|
||||
}
|
||||
res.body.should.have.property("id","123");
|
||||
res.body.should.have.property("enabled",true);
|
||||
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -492,7 +526,7 @@ describe("nodes api", function() {
|
||||
}
|
||||
res.body.should.have.property("id","123");
|
||||
res.body.should.have.property("enabled",false);
|
||||
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -507,11 +541,11 @@ describe("nodes api", function() {
|
||||
var enableNode = sinon.stub(redNodes,'enableNode',function(id) {
|
||||
return {id:"123",enabled: true,types:['a']};
|
||||
});
|
||||
|
||||
|
||||
var disableNode = sinon.stub(redNodes,'disableNode',function(id) {
|
||||
return {id:"123",enabled: false,types:['a']};
|
||||
});
|
||||
|
||||
|
||||
request(app)
|
||||
.put('/nodes/foo')
|
||||
.send({enabled:state})
|
||||
@ -530,7 +564,7 @@ describe("nodes api", function() {
|
||||
disableNodeCalled.should.be.false;
|
||||
res.body.should.have.property("id","123");
|
||||
res.body.should.have.property("enabled",state);
|
||||
|
||||
|
||||
done();
|
||||
});
|
||||
}
|
||||
@ -552,11 +586,11 @@ describe("nodes api", function() {
|
||||
var enableNode = sinon.stub(redNodes,'enableNode',function(id) {
|
||||
return {id:"123",enabled: true,types:['a']};
|
||||
});
|
||||
|
||||
|
||||
var disableNode = sinon.stub(redNodes,'disableNode',function(id) {
|
||||
return {id:"123",enabled: false,types:['a']};
|
||||
});
|
||||
|
||||
|
||||
request(app)
|
||||
.put('/nodes/foo')
|
||||
.send({enabled:state})
|
||||
@ -575,7 +609,7 @@ describe("nodes api", function() {
|
||||
disableNodeCalled.should.be.equal(!state);
|
||||
res.body.should.have.property("id","123");
|
||||
res.body.should.have.property("enabled",state);
|
||||
|
||||
|
||||
done();
|
||||
});
|
||||
}
|
||||
@ -587,6 +621,6 @@ describe("nodes api", function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
@ -40,7 +40,7 @@ describe("plugins api", function() {
|
||||
|
||||
describe('get plugins', function() {
|
||||
it('returns plugins list', function(done) {
|
||||
var getPluginList = sinon.stub(redNodes,'getPluginList', function() {
|
||||
var getPluginList = sinon.stub(redNodes,'getModuleList', function() {
|
||||
return [1,2,3];
|
||||
});
|
||||
request(app)
|
||||
@ -57,7 +57,7 @@ describe("plugins api", function() {
|
||||
});
|
||||
|
||||
it('returns an individual plugin info', function(done) {
|
||||
var getPluginInfo = sinon.stub(redNodes,'getPluginInfo', function(id) {
|
||||
var getPluginInfo = sinon.stub(redNodes,'getModuleInfo', function(id) {
|
||||
return {"name":"123", "nodes":[1,2,3]};
|
||||
});
|
||||
request(app)
|
||||
|
@ -435,7 +435,7 @@ describe('NodeRegistry', function() {
|
||||
typeRegistry.load("wontexist",true).then(function(){
|
||||
|
||||
typeRegistry.addModule("TestNodeModule").then(function() {
|
||||
var list = typeRegistry.getPluginList();
|
||||
var list = typeRegistry.getModuleList();
|
||||
list.should.be.an.Array.and.have.lengthOf(1);
|
||||
list[0].should.have.property("name", "TestNodeModule");
|
||||
list[0].should.have.property("nodes");
|
||||
@ -487,9 +487,9 @@ describe('NodeRegistry', function() {
|
||||
typeRegistry.load("wontexist",true).then(function(){
|
||||
|
||||
typeRegistry.addModule("TestNodeModule").then(function(nodes) {
|
||||
var list = typeRegistry.getPluginList();
|
||||
var list = typeRegistry.getModuleList();
|
||||
|
||||
var plugin = typeRegistry.getPluginInfo(list[0].name);
|
||||
var plugin = typeRegistry.getModuleInfo(list[0].name);
|
||||
plugin.should.have.property("name", list[0].name);
|
||||
plugin.should.have.property("nodes", nodes);
|
||||
done();
|
||||
|
Loading…
Reference in New Issue
Block a user