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

Merge pull request #1799 from kazuhitoyokoi/0.19-addtestcases4persistablecontext

Add test cases of persistable context for inject node
This commit is contained in:
Nick O'Leary 2018-07-12 08:41:27 +01:00 committed by GitHub
commit fc9040f715
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 94 additions and 1 deletions

View File

@ -16,12 +16,21 @@
var should = require("should");
var injectNode = require("../../../../nodes/core/core/20-inject.js");
var Context = require("../../../../red/runtime/nodes/context");
var helper = require("node-red-node-test-helper");
describe('inject node', function() {
before(function(done) {
helper.startServer(done);
Context.init({
contextStorage: {
memory: {
module: "memory"
}
}
});
Context.load();
});
after(function(done) {
@ -30,6 +39,90 @@ describe('inject node', function() {
afterEach(function() {
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) {

View File

@ -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"},
{id:"helperNode1", type:"helper", wires:[],"z":"flow"}];
helper.load(changeNode, flow, function() {