mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add test cases of persistable context for inject node
This commit is contained in:
parent
c2675600f6
commit
d53ced7830
@ -16,12 +16,21 @@
|
|||||||
|
|
||||||
var should = require("should");
|
var should = require("should");
|
||||||
var injectNode = require("../../../../nodes/core/core/20-inject.js");
|
var injectNode = require("../../../../nodes/core/core/20-inject.js");
|
||||||
|
var Context = require("../../../../red/runtime/nodes/context");
|
||||||
var helper = require("node-red-node-test-helper");
|
var helper = require("node-red-node-test-helper");
|
||||||
|
|
||||||
describe('inject node', function() {
|
describe('inject node', function() {
|
||||||
|
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
helper.startServer(done);
|
helper.startServer(done);
|
||||||
|
Context.init({
|
||||||
|
contextStorage: {
|
||||||
|
memory: {
|
||||||
|
module: "memory"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Context.load();
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function(done) {
|
after(function(done) {
|
||||||
@ -30,6 +39,90 @@ describe('inject node', function() {
|
|||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
helper.unload();
|
helper.unload();
|
||||||
|
Context.clean({allNodes: {}});
|
||||||
|
Context.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
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"},
|
||||||
|
{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", "changeMe");
|
||||||
|
done();
|
||||||
|
} catch (err) {
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
n1.context().flow.set("flowValue", "changeMe");
|
||||||
|
n1.receive({});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets the value of persistable flow context property', function (done) {
|
||||||
|
var flow = [{id: "n1", type: "inject", topic: "t1", payload: "#:(memory)::flowValue", payloadType: "flow", 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", "changeMe");
|
||||||
|
done();
|
||||||
|
} catch (err) {
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
n1.context().flow.set("flowValue", "changeMe", "memory", function (err) {
|
||||||
|
n1.receive({});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets the value of global context property', function (done) {
|
||||||
|
var flow = [{id: "n1", type: "inject", topic: "t1", payload: "globalValue", payloadType: "global", wires: [["n2"]]},
|
||||||
|
{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", "changeMe");
|
||||||
|
done();
|
||||||
|
} catch (err) {
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
n1.context().global.set("globalValue", "changeMe");
|
||||||
|
n1.receive({});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets the value of persistable global context property', function (done) {
|
||||||
|
var flow = [{id: "n1", type: "inject", topic: "t1", payload: "#:(memory)::globalValue", payloadType: "global", wires: [["n2"]]},
|
||||||
|
{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", "changeMe");
|
||||||
|
done();
|
||||||
|
} catch (err) {
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
n1.context().global.set("globalValue", "changeMe", "memory", function (err) {
|
||||||
|
n1.receive({});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should inject once with default delay property', function(done) {
|
it('should inject once with default delay property', function(done) {
|
||||||
|
@ -1062,7 +1062,7 @@ describe('change Node', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('changes the value and type of the flow context if a complete match', function(done) {
|
it('changes the value and type of the persistable flow context if a complete match', function(done) {
|
||||||
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "#:(memory)::payload", "pt": "flow", "from": "123", "fromt": "str", "to": "456", "tot": "num" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
|
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "#:(memory)::payload", "pt": "flow", "from": "123", "fromt": "str", "to": "456", "tot": "num" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
|
||||||
{id:"helperNode1", type:"helper", wires:[],"z":"flow"}];
|
{id:"helperNode1", type:"helper", wires:[],"z":"flow"}];
|
||||||
helper.load(changeNode, flow, function() {
|
helper.load(changeNode, flow, function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user