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

Add function tests for multiple-set access to context

This commit is contained in:
Nick O'Leary 2018-07-26 21:15:32 +01:00
parent 52f74ff7e0
commit 4e549dd426
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -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) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"context.set('count','0','memory1', function (err) { node.send(msg); });"},
{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) {
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"context.set('count','0');return msg;"},
{id:"n2", type:"helper"}];