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

boost api index, nodes index and nodes Node test coverage

This commit is contained in:
dceejay 2015-03-06 22:58:30 +00:00
parent 910d983b82
commit 69f85bd688
5 changed files with 52 additions and 32 deletions

View File

@ -116,6 +116,7 @@ Node.prototype.send = function(msg) {
} }
this.metric("send",msg); this.metric("send",msg);
node = flows.get(this._wire); node = flows.get(this._wire);
/* istanbul ignore else */
if (node) { if (node) {
node.receive(msg); node.receive(msg);
} }
@ -136,6 +137,7 @@ Node.prototype.send = function(msg) {
// for each output of node eg. [msgs to output 0, msgs to output 1, ...] // for each output of node eg. [msgs to output 0, msgs to output 1, ...]
for (var i = 0; i < numOutputs; i++) { for (var i = 0; i < numOutputs; i++) {
var wires = this.wires[i]; // wires leaving output i var wires = this.wires[i]; // wires leaving output i
/* istanbul ignore else */
if (i < msg.length) { if (i < msg.length) {
var msgs = msg[i]; // msgs going to output i var msgs = msg[i]; // msgs going to output i
if (msgs !== null && typeof msgs !== "undefined") { if (msgs !== null && typeof msgs !== "undefined") {
@ -150,6 +152,7 @@ Node.prototype.send = function(msg) {
// for each msg to send eg. [[m1, m2, ...], ...] // for each msg to send eg. [[m1, m2, ...], ...]
for (k = 0; k < msgs.length; k++) { for (k = 0; k < msgs.length; k++) {
var m = msgs[k]; var m = msgs[k];
/* istanbul ignore else */
if (!sentMessageId) { if (!sentMessageId) {
sentMessageId = m._msgid; sentMessageId = m._msgid;
} }
@ -166,6 +169,7 @@ Node.prototype.send = function(msg) {
} }
} }
} }
/* istanbul ignore else */
if (!sentMessageId) { if (!sentMessageId) {
sentMessageId = constructUniqueIdentifier(); sentMessageId = constructUniqueIdentifier();
} }
@ -173,6 +177,7 @@ Node.prototype.send = function(msg) {
for (i=0;i<sendEvents.length;i++) { for (i=0;i<sendEvents.length;i++) {
var ev = sendEvents[i]; var ev = sendEvents[i];
/* istanbul ignore else */
if (!ev.m._msgid) { if (!ev.m._msgid) {
ev.m._msgid = sentMessageId; ev.m._msgid = sentMessageId;
} }
@ -215,6 +220,7 @@ Node.prototype.warn = function(msg) {
Node.prototype.error = function(logMessage,msg) { Node.prototype.error = function(logMessage,msg) {
logMessage = logMessage || ""; logMessage = logMessage || "";
log_helper(this, Log.ERROR, logMessage); log_helper(this, Log.ERROR, logMessage);
/* istanbul ignore else */
if (msg) { if (msg) {
flows.handleError(this,logMessage,msg); flows.handleError(this,logMessage,msg);
} }

View File

@ -19,17 +19,15 @@ var request = require("supertest");
var express = require("express"); var express = require("express");
var fs = require("fs"); var fs = require("fs");
var path = require("path"); var path = require("path");
var settings = require("../../../red/settings"); var settings = require("../../../red/settings");
var api = require("../../../red/api"); var api = require("../../../red/api");
describe("api index", function() { describe("api index", function() {
var app; var app;
describe("disables editor", function() { describe("disables editor", function() {
before(function() { before(function() {
settings.init({disableEditor:true}); settings.init({disableEditor:true,adminAuth:{type: "credentials",users:[],default:{permissions:"read"}}});
app = express(); app = express();
api.init(app); api.init(app);
}); });
@ -88,5 +86,10 @@ describe("api index", function() {
.get("/settings") .get("/settings")
.expect(200,done) .expect(200,done)
}); });
it('handles page not there', function(done) {
request(app)
.get("/foo")
.expect(404,done)
});
}); });
}); });

View File

@ -23,7 +23,7 @@ describe("red/log", function() {
}); });
var log = require("../../red/log"); var log = require("../../red/log");
var sett = {logging: { console: { level: 'metric', metrics: true } } } var sett = {logging: { console: { level: 'metric', metrics: true } } };
log.init(sett); log.init(sett);
beforeEach(function () { beforeEach(function () {

View File

@ -418,13 +418,12 @@ describe('Node', function() {
var message = {a:1}; var message = {a:1};
n.error("an error message",message); n.error(null,message);
should.deepEqual({level:Log.ERROR, id:n.id, should.deepEqual({level:Log.ERROR, id:n.id, type:n.type, msg:""}, loginfo);
type:n.type, msg:"an error message"}, loginfo);
flows.handleError.called.should.be.true; flows.handleError.called.should.be.true;
flows.handleError.args[0][0].should.eql(n); flows.handleError.args[0][0].should.eql(n);
flows.handleError.args[0][1].should.eql("an error message"); flows.handleError.args[0][1].should.eql("");
flows.handleError.args[0][2].should.eql(message); flows.handleError.args[0][2].should.eql(message);
Log.log.restore(); Log.log.restore();
@ -449,6 +448,20 @@ describe('Node', function() {
}); });
}); });
describe('#metric', function() {
it('returns metric value if eventname undefined', function(done) {
var n = new RedNode({id:'123',type:'abc'});
var loginfo = {};
sinon.stub(Log, 'log', function(msg) {
loginfo = msg;
});
var msg = {payload:"foo", _msgid:"987654321"};
var m = n.metric(undefined,msg,"15mb");
m.should.equal(true);
Log.log.restore();
done();
});
});
describe('#status', function() { describe('#status', function() {
after(function() { after(function() {

View File

@ -58,7 +58,6 @@ describe("red/nodes/index", function() {
} }
it('nodes are initialised with credentials',function(done) { it('nodes are initialised with credentials',function(done) {
index.init(settings, storage); index.init(settings, storage);
index.registerType('test', TestNode); index.registerType('test', TestNode);
index.loadFlows().then(function() { index.loadFlows().then(function() {
@ -69,7 +68,6 @@ describe("red/nodes/index", function() {
}).otherwise(function(err) { }).otherwise(function(err) {
done(err); done(err);
}); });
}); });
it('flows should be initialised',function(done) { it('flows should be initialised',function(done) {
@ -128,7 +126,7 @@ describe("red/nodes/index", function() {
foo: {type:"test"} foo: {type:"test"}
} }
}); });
var testnode = new TestNode({id:'tab1',type:'test',name:'barney'}); var testnode = new TestNode({id:'tab1',type:'test',name:'barney', '_alias':'tab1'});
credentials.getDefinition("test").should.have.property('foo'); credentials.getDefinition("test").should.have.property('foo');
done(); done();
}); });