1
0
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:
Anna Thomas 2014-11-20 15:17:13 +00:00
parent 0ff65f6805
commit d614b7c39f
8 changed files with 136 additions and 80 deletions

View File

@ -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);

View File

@ -97,10 +97,10 @@ module.exports = {
}
},
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);
@ -112,6 +112,16 @@ module.exports = {
}
},
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());
@ -152,4 +162,4 @@ module.exports = {
res.send(400,err.toString());
}
}
}
};

View File

@ -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 {

View File

@ -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,

View File

@ -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,

View File

@ -36,7 +36,8 @@ 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);
});
@ -78,12 +79,45 @@ describe("nodes api", function() {
});
});
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>")
@ -116,10 +150,10 @@ describe("nodes api", function() {
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) {

View File

@ -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)

View File

@ -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();