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