mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add function tests for multiple-set access to context
This commit is contained in:
parent
52f74ff7e0
commit
4e549dd426
@ -1,18 +1,18 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright JS Foundation and other contributors, http://js.foundation
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var should = require("should");
|
var should = require("should");
|
||||||
var functionNode = require("../../../../nodes/core/core/80-function.js");
|
var functionNode = require("../../../../nodes/core/core/80-function.js");
|
||||||
@ -379,6 +379,35 @@ describe('function node', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should set two persistable node context (single call, w/o callback)', function(done) {
|
||||||
|
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"context.set(['count1','count2'],['0','1'],'memory1');return msg;"},
|
||||||
|
{id:"n2", type:"helper"}];
|
||||||
|
helper.load(functionNode, flow, function() {
|
||||||
|
initContext(function () {
|
||||||
|
var n1 = helper.getNode("n1");
|
||||||
|
var n2 = helper.getNode("n2");
|
||||||
|
n2.on("input", function(msg) {
|
||||||
|
try {
|
||||||
|
msg.should.have.property('topic', 'bar');
|
||||||
|
msg.should.have.property('payload', 'foo');
|
||||||
|
n1.context().get("count1", "memory1", function (err, val1) {
|
||||||
|
val1.should.equal("0");
|
||||||
|
n1.context().get("count2", "memory1", function (err, val2) {
|
||||||
|
val2.should.equal("1");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
n1.receive({payload:"foo",topic: "bar"});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should set persistable node context (w callback)', function(done) {
|
it('should set persistable node context (w callback)', function(done) {
|
||||||
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"context.set('count','0','memory1', function (err) { node.send(msg); });"},
|
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"context.set('count','0','memory1', function (err) { node.send(msg); });"},
|
||||||
{id:"n2", type:"helper"}];
|
{id:"n2", type:"helper"}];
|
||||||
@ -432,6 +461,35 @@ describe('function node', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should set two persistable node context (single call, w callback)', function(done) {
|
||||||
|
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"context.set(['count1','count2'],['0','1'],'memory1', function(err) { node.send(msg); });"},
|
||||||
|
{id:"n2", type:"helper"}];
|
||||||
|
helper.load(functionNode, flow, function() {
|
||||||
|
initContext(function () {
|
||||||
|
var n1 = helper.getNode("n1");
|
||||||
|
var n2 = helper.getNode("n2");
|
||||||
|
n2.on("input", function(msg) {
|
||||||
|
try {
|
||||||
|
msg.should.have.property('topic', 'bar');
|
||||||
|
msg.should.have.property('payload', 'foo');
|
||||||
|
n1.context().get("count1", "memory1", function (err, val1) {
|
||||||
|
val1.should.equal("0");
|
||||||
|
n1.context().get("count2", "memory1", function (err, val2) {
|
||||||
|
val2.should.equal("1");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
n1.receive({payload:"foo",topic: "bar"});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should set default persistable node context', function(done) {
|
it('should set default persistable node context', function(done) {
|
||||||
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"context.set('count','0');return msg;"},
|
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"context.set('count','0');return msg;"},
|
||||||
{id:"n2", type:"helper"}];
|
{id:"n2", type:"helper"}];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user