add test cases

This commit is contained in:
Hiroyasu Nishiyama 2022-07-27 20:25:43 +09:00
parent 93a88a83a8
commit 1ddbeaa50f
2 changed files with 38 additions and 2 deletions

View File

@ -260,7 +260,8 @@ describe('subflow', function() {
{name: "KB", type: "bool", value: "true"},
{name: "KJ", type: "json", value: "[1,2,3]"},
{name: "Kb", type: "bin", value: "[65,65]"},
{name: "Ke", type: "env", value: "KS"}
{name: "Ke", type: "env", value: "KS"},
{name: "Kj", type: "jsonata", value: "1+2"},
],
wires:[["n2"]]},
{id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]},
@ -279,7 +280,7 @@ describe('subflow', function() {
]
},
{id:"s1-n1", x:10, y:10, z:"s1", type:"function",
func:"msg.VE = env.get('Ke'); msg.VS = env.get('KS'); msg.VN = env.get('KN'); msg.VB = env.get('KB'); msg.VJ = env.get('KJ'); msg.Vb = env.get('Kb'); return msg;",
func:"msg.VE = env.get('Ke'); msg.VS = env.get('KS'); msg.VN = env.get('KN'); msg.VB = env.get('KB'); msg.VJ = env.get('KJ'); msg.Vb = env.get('Kb'); msg.Vj = env.get('Kj'); return msg;",
wires:[]}
];
helper.load(functionNode, flow, function() {
@ -294,6 +295,7 @@ describe('subflow', function() {
msg.should.have.property("Vb");
should.ok(msg.Vb instanceof Buffer);
msg.should.have.property("VE","STR");
msg.should.have.property("Vj",3);
done();
}
catch (e) {

View File

@ -1322,6 +1322,40 @@ describe('Flow', function() {
});
it("can define environment variable using JSONata", function (done) {
try {
after(function() {
delete process.env.V0;
})
var config = flowUtils.parseConfig([
{id:"t1",type:"tab",env:[
{"name": "V0", value: "1+2", type: "jsonata"}
]},
{id:"g1",type:"group",z:"t1",env:[
{"name": "V1", value: "2+3", type: "jsonata"},
]},
{id:"1",x:10,y:10,z:"t1",g:"g1",type:"test",foo:"$(V0)",wires:[]},
{id:"2",x:10,y:10,z:"t1",g:"g1",type:"test",foo:"$(V1)",wires:[]},
]);
var flow = Flow.create({getSetting:v=>process.env[v]},config,config.flows["t1"]);
flow.start();
var activeNodes = flow.getActiveNodes();
activeNodes["1"].foo.should.equal(3);
activeNodes["2"].foo.should.equal(5);
flow.stop().then(function() {
done();
});
}
catch (e) {
console.log(e.stack);
done(e);
}
});
});
});