Allow node.status() to be passed number/bool types

Adds to the existing support for string types. Also
adds unit tests for all three cases
This commit is contained in:
Nick O'Leary 2019-10-14 13:06:59 +01:00
parent 147d2a02be
commit c1c694035d
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 33 additions and 4 deletions

View File

@ -539,7 +539,12 @@ Node.prototype.metric = function(eventname, msg, metricValue) {
* status: "simple text status"
*/
Node.prototype.status = function(status) {
if (typeof(status) === "string") { status = {text:status}; }
switch (typeof status) {
case "string":
case "number":
case "boolean":
status = {text:""+status}
}
this._flow.handleStatus(this,status);
};

View File

@ -613,9 +613,6 @@ describe('Node', function() {
}
var n = new RedNode({_flow:flow,id:'123',type:'abc'});
var status = {fill:"green",shape:"dot",text:"connected"};
var topic;
var message;
var retain;
n.status(status);
@ -624,6 +621,33 @@ describe('Node', function() {
flow.handleStatus.args[0][1].should.eql(status);
done();
});
it('publishes status for plain string', function(done) {
var flow = { handleStatus: sinon.stub() }
var n = new RedNode({_flow:flow,id:'123',type:'abc'});
n.status("text status");
flow.handleStatus.called.should.be.true();
flow.handleStatus.args[0][0].should.eql(n);
flow.handleStatus.args[0][1].should.eql({text:"text status"});
done();
});
it('publishes status for plain boolean', function(done) {
var flow = { handleStatus: sinon.stub() }
var n = new RedNode({_flow:flow,id:'123',type:'abc'});
n.status(false);
flow.handleStatus.called.should.be.true();
flow.handleStatus.args[0][0].should.eql(n);
flow.handleStatus.args[0][1].should.eql({text:"false"});
done();
});
it('publishes status for plain number', function(done) {
var flow = { handleStatus: sinon.stub() }
var n = new RedNode({_flow:flow,id:'123',type:'abc'});
n.status(123);
flow.handleStatus.called.should.be.true();
flow.handleStatus.args[0][0].should.eql(n);
flow.handleStatus.args[0][1].should.eql({text:"123"});
done();
});
});
});