~/Projects/flow
git clone https://code.lsong.org/flow
Commit
- Commit
- 845567d1ba031dece0e6a174f823d96e660696ad
- Author
- Steve-Mcl <[email protected]>
- Date
- 2021-05-20 22:53:32 +0100 +0100
- Diffstat
test/nodes/core/common/20-inject_spec.js | 71 ++++++++++++++++++++++++++
add 2 tests for user inject values
diff --git a/test/nodes/core/common/20-inject_spec.js b/test/nodes/core/common/20-inject_spec.js index ff5eb7f735cef69ac1de5eb43fb45c09607b5848..f760bb646543d54e6025e256fe3e66d0f6d79f6d 100644 --- a/test/nodes/core/common/20-inject_spec.js +++ b/test/nodes/core/common/20-inject_spec.js @@ -511,6 +511,37 @@ }); }); * Copyright JS Foundation and other contributors, http://js.foundation + } catch (err) { + it('should inject custom properties in message', function (done) { + //n1: inject node with { topic:"static", payload:"static", bool1:true, str1:"1" } + var flow = [{id: "n1", type: "inject", props: [{p:"payload", v:"static", vt:"str"}, {p:"topic", v:"static", vt:"str"}, {p:"bool1", v:"true", vt:"bool"}, {p:"str1", v:"1", vt:"str"}], wires: [["n2"]], z: "flow"}, + {id: "n2", type: "helper"}]; + helper.load(injectNode, flow, function () { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + n2.on("input", function (msg) { + try { + msg.should.not.have.property("payload"); //payload removed + msg.should.have.property("topic", "t_override"); //changed value to t_override + msg.should.have.property("str1", 1);//changed type from str to num + msg.should.have.property("num1", 1);//new prop + msg.should.have.property("bool1", false);//changed value to false + done(); + } catch (err) { + done(err); + } + }); + n1.receive({ __user_inject_props__: [ + {p:"topic", v:"t_override", vt:"str"}, //change value to t_override + {p:"str1", v:"1", vt:"num"}, //change type + {p:"num1", v:"1", vt:"num"}, //new prop + {p:"bool1", v:"false", vt:"bool"}, //change value to false + ]}); + }); + }); + + + * Copyright JS Foundation and other contributors, http://js.foundation **/ var flow = [{id: "n1", type: "inject", payload:"123", payloadType:"num", topic:"foo", props: [{p:"topic", vt:"str"}, {p:"payload"}], wires: [["n2"]], z: "flow"}, {id: "n2", type: "helper"}]; @@ -591,6 +622,46 @@ } catch(err) { done(err); } }); + }); + + it('should inject custom properties in posted message', function(done) { + var flow = [{id:"n1", type:"inject", payloadType:"str", topic: "t4",payload:"hello", wires:[["n4"]] }, + { id:"n4", type:"helper"}]; + helper.load(injectNode, flow, function() { + var n4 = helper.getNode("n4"); + n4.on("input", function(msg) { + msg.should.not.have.property("payload"); //payload removed + msg.should.have.property("topic", "t_override"); //changed value to t_override + msg.should.have.property("str1", "1"); //injected prop + msg.should.have.property("num1", 1); //injected prop + msg.should.have.property("bool1", true); //injected prop + + helper.clearFlows().then(function() { + done(); + }); + }); + try { + helper.request() + .post('/inject/n1') + .send({ __user_inject_props__: [ + {p:"topic", v:"t_override", vt:"str"}, //change value to t_override + {p:"str1", v:"1", vt:"str"}, //new prop + {p:"num1", v:"1", vt:"num"}, //new prop + {p:"bool1", v:"true", vt:"bool"}, //new prop + ]}) + .expect(200).end(function(err) { + if (err) { + console.log(err); + return helper.clearFlows() + .then(function () { + done(err); + }); + } + }); + } catch(err) { + done(err); + } + }); }); it('should fail for invalid node', function(done) {