mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Allow the JSONata Expression to handle persistable store.
This commit is contained in:
@@ -459,7 +459,7 @@ describe("red/util", function() {
|
||||
should.not.exist(result);
|
||||
});
|
||||
it('handles async flow context access', function(done) {
|
||||
var expr = util.prepareJSONataExpression('$flowContext("foo")',{context:function() { return {flow:{get: function(key,callback) { setTimeout(()=>{callback(null,{'foo':'bar'}[key])},10)}}}}});
|
||||
var expr = util.prepareJSONataExpression('$flowContext("foo")',{context:function() { return {flow:{get: function(key,store,callback) { setTimeout(()=>{callback(null,{'foo':'bar'}[key])},10)}}}}});
|
||||
util.evaluateJSONataExpression(expr,{payload:"hello"},function(err,value) {
|
||||
try {
|
||||
should.not.exist(err);
|
||||
@@ -471,7 +471,7 @@ describe("red/util", function() {
|
||||
});
|
||||
})
|
||||
it('handles async global context access', function(done) {
|
||||
var expr = util.prepareJSONataExpression('$globalContext("foo")',{context:function() { return {global:{get: function(key,callback) { setTimeout(()=>{callback(null,{'foo':'bar'}[key])},10)}}}}});
|
||||
var expr = util.prepareJSONataExpression('$globalContext("foo")',{context:function() { return {global:{get: function(key,store,callback) { setTimeout(()=>{callback(null,{'foo':'bar'}[key])},10)}}}}});
|
||||
util.evaluateJSONataExpression(expr,{payload:"hello"},function(err,value) {
|
||||
try {
|
||||
should.not.exist(err);
|
||||
@@ -482,6 +482,34 @@ describe("red/util", function() {
|
||||
}
|
||||
});
|
||||
})
|
||||
it('handles persistable store in flow context access', function(done) {
|
||||
var storeName;
|
||||
var expr = util.prepareJSONataExpression('$flowContext("foo", "flowStoreName")',{context:function() { return {flow:{get: function(key,store,callback) { storeName = store;setTimeout(()=>{callback(null,{'foo':'bar'}[key])},10)}}}}});
|
||||
util.evaluateJSONataExpression(expr,{payload:"hello"},function(err,value) {
|
||||
try {
|
||||
should.not.exist(err);
|
||||
value.should.eql("bar");
|
||||
storeName.should.equal("flowStoreName");
|
||||
done();
|
||||
} catch(err2) {
|
||||
done(err2);
|
||||
}
|
||||
});
|
||||
})
|
||||
it('handles persistable store in global context access', function(done) {
|
||||
var storeName;
|
||||
var expr = util.prepareJSONataExpression('$globalContext("foo", "globalStoreName")',{context:function() { return {global:{get: function(key,store,callback) { storeName = store;setTimeout(()=>{callback(null,{'foo':'bar'}[key])},10)}}}}});
|
||||
util.evaluateJSONataExpression(expr,{payload:"hello"},function(err,value) {
|
||||
try {
|
||||
should.not.exist(err);
|
||||
value.should.eql("bar");
|
||||
storeName.should.equal("globalStoreName");
|
||||
done();
|
||||
} catch(err2) {
|
||||
done(err2);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user