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

Fix invalid from property error in change node (#1442)

* Fix invalid from property error in change node

* Empty commit to run test cases again
This commit is contained in:
Kazuhito Yokoi 2017-10-18 06:17:27 +09:00 committed by Nick O'Leary
parent 611e598756
commit 5b137c457b
2 changed files with 40 additions and 2 deletions

View File

@ -129,9 +129,9 @@ module.exports = function(RED) {
if (rule.fromt === 'msg' || rule.fromt === 'flow' || rule.fromt === 'global') { if (rule.fromt === 'msg' || rule.fromt === 'flow' || rule.fromt === 'global') {
if (rule.fromt === "msg") { if (rule.fromt === "msg") {
fromValue = RED.util.getMessageProperty(msg,rule.from); fromValue = RED.util.getMessageProperty(msg,rule.from);
} else if (rule.tot === 'flow') { } else if (rule.fromt === 'flow') {
fromValue = node.context().flow.get(rule.from); fromValue = node.context().flow.get(rule.from);
} else if (rule.tot === 'global') { } else if (rule.fromt === 'global') {
fromValue = node.context().global.get(rule.from); fromValue = node.context().global.get(rule.from);
} }
if (typeof fromValue === 'number' || fromValue instanceof Number) { if (typeof fromValue === 'number' || fromValue instanceof Number) {

View File

@ -541,6 +541,44 @@ describe('change Node', function() {
}); });
}); });
it('changes the value using flow context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"topic","to":"123","fromt":"flow","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.equal("abc123abc");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("topic","ABC");
changeNode1.receive({payload:"abcABCabc"});
});
});
it('changes the value using global context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"topic","to":"123","fromt":"global","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.equal("abc123abc");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("topic","ABC");
changeNode1.receive({payload:"abcABCabc"});
});
});
it('changes the value using number - string payload', function(done) { it('changes the value using number - string payload', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"123","to":"456","fromt":"num","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]}, var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"123","to":"456","fromt":"num","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}]; {id:"helperNode1", type:"helper", wires:[]}];