mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
fc9906624e
commit
c93870316c
@ -338,7 +338,7 @@ function prepareJSONataExpression(value,node) {
|
|||||||
return node.context().flow.get(val);
|
return node.context().flow.get(val);
|
||||||
});
|
});
|
||||||
expr.assign('globalContext',function(val) {
|
expr.assign('globalContext',function(val) {
|
||||||
return node.context().global(val);
|
return node.context().global.get(val);
|
||||||
});
|
});
|
||||||
expr._legacyMode = /(^|[^a-zA-Z0-9_'"])msg([^a-zA-Z0-9_'"]|$)/.test(value);
|
expr._legacyMode = /(^|[^a-zA-Z0-9_'"])msg([^a-zA-Z0-9_'"]|$)/.test(value);
|
||||||
return expr;
|
return expr;
|
||||||
|
@ -381,4 +381,48 @@ describe("red/util", function() {
|
|||||||
it('pass http request',function() { normalise("http request", "httpRequest") });
|
it('pass http request',function() { normalise("http request", "httpRequest") });
|
||||||
it('pass HttpRequest',function() { normalise("HttpRequest", "httpRequest") });
|
it('pass HttpRequest',function() { normalise("HttpRequest", "httpRequest") });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('prepareJSONataExpression', function() {
|
||||||
|
it('prepares an expression', function() {
|
||||||
|
var result = util.prepareJSONataExpression('payload',{});
|
||||||
|
result.should.have.property('evaluate');
|
||||||
|
result.should.have.property('assign');
|
||||||
|
result.should.have.property('_legacyMode', false);
|
||||||
|
});
|
||||||
|
it('prepares a legacyMode expression', function() {
|
||||||
|
var result = util.prepareJSONataExpression('msg.payload',{});
|
||||||
|
result.should.have.property('evaluate');
|
||||||
|
result.should.have.property('assign');
|
||||||
|
result.should.have.property('_legacyMode', true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('evaluateJSONataExpression', function() {
|
||||||
|
it('evaluates an expression', function() {
|
||||||
|
var expr = util.prepareJSONataExpression('payload',{});
|
||||||
|
var result = util.evaluateJSONataExpression(expr,{payload:"hello"});
|
||||||
|
result.should.eql("hello");
|
||||||
|
});
|
||||||
|
it('evaluates a legacyMode expression', function() {
|
||||||
|
var expr = util.prepareJSONataExpression('msg.payload',{});
|
||||||
|
var result = util.evaluateJSONataExpression(expr,{payload:"hello"});
|
||||||
|
result.should.eql("hello");
|
||||||
|
});
|
||||||
|
it('accesses flow context from an expression', function() {
|
||||||
|
var expr = util.prepareJSONataExpression('$flowContext("foo")',{context:function() { return {flow:{get: function(key) { return {'foo':'bar'}[key]}}}}});
|
||||||
|
var result = util.evaluateJSONataExpression(expr,{payload:"hello"});
|
||||||
|
result.should.eql("bar");
|
||||||
|
});
|
||||||
|
it('handles non-existant flow context variable', function() {
|
||||||
|
var expr = util.prepareJSONataExpression('$flowContext("nonExistant")',{context:function() { return {flow:{get: function(key) { return {'foo':'bar'}[key]}}}}});
|
||||||
|
var result = util.evaluateJSONataExpression(expr,{payload:"hello"});
|
||||||
|
should.not.exist(result);
|
||||||
|
});
|
||||||
|
it('handles non-existant global context variable', function() {
|
||||||
|
var expr = util.prepareJSONataExpression('$globalContext("nonExistant")',{context:function() { return {global:{get: function(key) { return {'foo':'bar'}[key]}}}}});
|
||||||
|
var result = util.evaluateJSONataExpression(expr,{payload:"hello"});
|
||||||
|
should.not.exist(result);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user