mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
add test cases for inject node
This commit is contained in:
parent
be58b614e1
commit
ee74ed9ce9
@ -51,6 +51,61 @@ describe('inject node', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function basicTest(type, val, rval) {
|
||||||
|
it('inject value ('+type+')', function (done) {
|
||||||
|
var flow = [{id: "n1", type: "inject", topic: "t1", payload: val, payloadType: type, wires: [["n2"]], z: "flow"},
|
||||||
|
{id: "n2", type: "helper"}];
|
||||||
|
helper.load(injectNode, flow, function () {
|
||||||
|
var n1 = helper.getNode("n1");
|
||||||
|
var n2 = helper.getNode("n2");
|
||||||
|
n2.on("input", function (msg) {
|
||||||
|
try {
|
||||||
|
msg.should.have.property("topic", "t1");
|
||||||
|
if (rval) {
|
||||||
|
msg.should.have.property("payload");
|
||||||
|
should.deepEqual(msg.payload, rval);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
msg.should.have.property("payload", val);
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
} catch (err) {
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
n1.receive({});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
basicTest("num", 10);
|
||||||
|
basicTest("str", "10");
|
||||||
|
basicTest("bool", true);
|
||||||
|
var val_json = '{ "x":"vx", "y":"vy", "z":"vz" }';
|
||||||
|
basicTest("json", val_json, JSON.parse(val_json));
|
||||||
|
var val_buf = "[1,2,3,4,5]";
|
||||||
|
basicTest("bin", val_buf, Buffer.from(JSON.parse(val_buf)));
|
||||||
|
|
||||||
|
it('inject value of environment variable ', function (done) {
|
||||||
|
var flow = [{id: "n1", type: "inject", topic: "t1", payload: "NR_TEST", payloadType: "env", wires: [["n2"]], z: "flow"},
|
||||||
|
{id: "n2", type: "helper"}];
|
||||||
|
helper.load(injectNode, flow, function () {
|
||||||
|
var n1 = helper.getNode("n1");
|
||||||
|
var n2 = helper.getNode("n2");
|
||||||
|
n2.on("input", function (msg) {
|
||||||
|
try {
|
||||||
|
msg.should.have.property("topic", "t1");
|
||||||
|
msg.should.have.property("payload", "foo");
|
||||||
|
done();
|
||||||
|
} catch (err) {
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
process.env.NR_TEST = 'foo';
|
||||||
|
n1.receive({});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('sets the value of flow context property', function (done) {
|
it('sets the value of flow context property', function (done) {
|
||||||
var flow = [{id: "n1", type: "inject", topic: "t1", payload: "flowValue", payloadType: "flow", wires: [["n2"]], z: "flow"},
|
var flow = [{id: "n1", type: "inject", topic: "t1", payload: "flowValue", payloadType: "flow", wires: [["n2"]], z: "flow"},
|
||||||
{id: "n2", type: "helper"}];
|
{id: "n2", type: "helper"}];
|
||||||
|
Loading…
Reference in New Issue
Block a user