diff --git a/test/nodes/core/function/16-range_spec.js b/test/nodes/core/function/16-range_spec.js
index 620d21b12..ca35f8f37 100644
--- a/test/nodes/core/function/16-range_spec.js
+++ b/test/nodes/core/function/16-range_spec.js
@@ -30,13 +30,19 @@ describe('range Node', function() {
helper.stopServer(done);
});
- it('should load some defaults', function(done) {
+ it('should load with defaults', function(done) {
var flow = [{"id":"rangeNode1","type":"range","name":"rangeNode"}];
helper.load(rangeNode, flow, function() {
- var rangeNode1 = helper.getNode("rangeNode1");
- rangeNode1.should.have.property('name', 'rangeNode');
- rangeNode1.should.have.property('round', false);
- done();
+ try {
+ var rangeNode1 = helper.getNode("rangeNode1");
+ rangeNode1.should.have.property('name', 'rangeNode');
+ rangeNode1.should.have.property('round', false);
+ rangeNode1.should.have.property('property', 'payload')
+ rangeNode1.should.have.property('propertyOut', 'payload')
+ done();
+ } catch (error) {
+ done(error);
+ }
});
});
@@ -170,4 +176,23 @@ describe('range Node', function() {
rangeNode1.receive({payload:"NOT A NUMBER"});
});
});
+
+ it('uses configured property to get input value and propertyOut to set output value', function (done) {
+ var flow = [{ "id": "rangeNode1", "type": "range", "minin": 0, "maxin": 10, "minout": 0, "maxout": 100, "action": "scale", "round": true, "name": "rangeNode", "property": "payload.sub.prop", "propertyOut": "result", "wires": [["helperNode1"]] },
+ { id: "helperNode1", type: "helper", wires: [] }]
+ helper.load(rangeNode, flow, function () {
+ var rangeNode1 = helper.getNode("rangeNode1")
+ var helperNode1 = helper.getNode("helperNode1")
+ helperNode1.on("input", function (msg) {
+ try {
+ msg.should.have.property("result")
+ msg.result.should.equal(50)
+ done()
+ } catch (err) {
+ done(err)
+ }
+ })
+ rangeNode1.receive({ payload: { sub: { prop: 5 } } })
+ });
+ })
});
diff --git a/test/nodes/core/function/80-template_spec.js b/test/nodes/core/function/80-template_spec.js
index b4f530d05..de323e6ac 100644
--- a/test/nodes/core/function/80-template_spec.js
+++ b/test/nodes/core/function/80-template_spec.js
@@ -60,6 +60,21 @@ describe('template node', function() {
});
});
+ it('should load with defaults', function (done) {
+ const flow = [{ id: "n1", type: "template", template: "payload={{payload}}" }]
+ helper.load(templateNode, flow, function () {
+ try {
+ const n1 = helper.getNode("n1")
+ n1.should.have.property('syntax', 'mustache')
+ n1.should.have.property('field', 'payload') // `propertyOut` on this node is `field`
+ n1.should.have.property('fieldType', 'msg')
+ n1.should.have.property('outputFormat', 'str')
+ done()
+ } catch (error) {
+ done(error)
+ }
+ })
+ })
it('should modify payload using node-configured template', function(done) {
var flow = [{id:"n1", type:"template", field:"payload", template:"payload={{payload}}",wires:[["n2"]]},{id:"n2",type:"helper"}];
diff --git a/test/nodes/core/network/21-httprequest_spec.js b/test/nodes/core/network/21-httprequest_spec.js
index 6459a2122..a6b734ce9 100644
--- a/test/nodes/core/network/21-httprequest_spec.js
+++ b/test/nodes/core/network/21-httprequest_spec.js
@@ -515,6 +515,45 @@ describe('HTTP Request Node', function() {
});
describe('request', function() {
+ it('should load with defaults', function(done) {
+ const flow = [{id:"n1",type:"http request", name: "my http request",wires:[["n2"]]}]
+ helper.load(httpRequestNode, flow, function() {
+ try {
+ const n1 = helper.getNode("n1")
+ n1.should.have.property('name', 'my http request')
+ n1.should.not.have.property('method')
+ n1.should.have.property('property', 'payload')
+ n1.should.have.property('propertyOut', 'payload')
+ n1.should.have.property('ret', 'txt')
+ n1.should.have.property('reqTimeout', 120000)
+ n1.should.have.property('headers').and.be.an.Array().and.have.length(0)
+ n1.should.have.property('authType', 'basic')
+ done()
+ } catch (error) {
+ done(error)
+ }
+ })
+ })
+
+ it('should get using message properties specified for `property in` and `property out`', function (done) {
+ const flow = [{ id: "n1", type: "http request", wires: [["n2"]], method: "GET", ret: "txt", property: 'body.data.in', propertyOut: 'result', url: getTestURL('/text') },
+ { id: "n2", type: "helper" }]
+ helper.load(httpRequestNode, flow, function () {
+ const n1 = helper.getNode("n1")
+ const n2 = helper.getNode("n2")
+ n2.on("input", function (msg) {
+ try {
+ msg.should.have.property('result', 'hello')
+ msg.should.have.property('statusCode', 200)
+ done()
+ } catch (err) {
+ done(err)
+ }
+ })
+ n1.receive({ body: { data: { in: 'foo' } } })
+ })
+ })
+
it('should get plain text content', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"txt",url:getTestURL('/text')},
{id:"n2", type:"helper"}];
diff --git a/test/nodes/core/parsers/70-CSV_spec.js b/test/nodes/core/parsers/70-CSV_spec.js
index f362ecdbf..d83b5a468 100644
--- a/test/nodes/core/parsers/70-CSV_spec.js
+++ b/test/nodes/core/parsers/70-CSV_spec.js
@@ -23,7 +23,7 @@ const delayNode = require("nr-test-utils").require("@node-red/nodes/core/functio
const helper = require("node-red-node-test-helper");
// const { neq } = require("semver");
-describe('CSV node (Legacy Mode)', function() {
+describe.only('CSV node (Legacy Mode)', function() {
before(function(done) {
helper.startServer(done);
@@ -51,6 +51,8 @@ describe('CSV node (Legacy Mode)', function() {
// n1.should.have.property('lineend', '\n');
n1.should.have.property('multi', 'one');
n1.should.have.property('hdrin', false);
+ n1.should.have.property('property', 'payload');
+ n1.should.have.property('propertyOut', 'payload');
done();
} catch (error) {
done(error);
@@ -788,6 +790,26 @@ describe('CSV node (Legacy Mode)', function() {
});
});
+ it ('should use message properties specified for `property in` and `property out`', function(done) {
+ const flow = [{ id: "n1", type: "csv", spec: "rfc", temp: "a,b,c,d", property: 'payload.sub.prop', propertyOut: 'result.sub_prop', wires: [["n2"]] },
+ { id: "n2", type: "helper" }];
+ helper.load(csvNode, flow, function () {
+ const n1 = helper.getNode("n1");
+ const n2 = helper.getNode("n2");
+ n2.on("input", function (msg) {
+ try {
+ msg.should.have.property('result').and.be.an.Object();
+ msg.result.should.have.property('sub_prop', { a: 1, b: 2, c: 3, d: 4 });
+ msg.should.have.property('columns', "a,b,c,d");
+ check_parts(msg, 0, 1);
+ done();
+ }
+ catch (e) { done(e); }
+ });
+ const testString = "1,2,3,4" + String.fromCharCode(10);
+ n1.emit("input", { payload: { sub: { prop: testString } } });
+ });
+ })
});
describe('json object to csv', function() {
@@ -1101,6 +1123,23 @@ describe('CSV node (Legacy Mode)', function() {
});
});
+ it ('should use message properties specified for `property in` and `property out`', function(done) {
+ const flow = [{ id: "n1", type: "csv", spec: "rfc", temp: "a,b,c,d", ret: '\n', property: 'payload.sub.prop', propertyOut: 'result', wires: [["n2"]] }, // RFC-vs-Legacy difference - use line separator \n to satisfy original test
+ { id: "n2", type: "helper" }];
+ helper.load(csvNode, flow, function() {
+ const n1 = helper.getNode("n1");
+ const n2 = helper.getNode("n2");
+ n2.on("input", function(msg) {
+ try {
+ msg.should.have.property('result', '4,3,2,1\n');
+ done();
+ } catch(e) { done(e); }
+ });
+ const testJson = { d: 1, b: 3, c: 2, a: 4 };
+ n1.emit("input", { payload: { sub: { prop: testJson } } });
+ });
+ })
+
});
it('should just pass through if no payload provided', function(done) {
@@ -1190,7 +1229,7 @@ describe('CSV node (Legacy Mode)', function() {
});
});
-describe('CSV node (RFC Mode)', function () {
+describe.only('CSV node (RFC Mode)', function () {
before(function (done) {
helper.startServer(done);
@@ -1219,6 +1258,8 @@ describe('CSV node (RFC Mode)', function () {
n1.should.have.property('ret', '\r\n'); // RFC-Legacy difference
n1.should.have.property('multi', 'one');
n1.should.have.property('hdrin', false);
+ n1.should.have.property('property', 'payload');
+ n1.should.have.property('propertyOut', 'payload');
done();
} catch (error) {
done(error);
@@ -1997,6 +2038,26 @@ describe('CSV node (RFC Mode)', function () {
});
});
+ it ('should use message properties specified for `property in` and `property out`', function(done) {
+ const flow = [{ id: "n1", type: "csv", spec: "rfc", temp: "a,b,c,d", property: 'payload.sub.prop', propertyOut: 'result.sub_prop', wires: [["n2"]] },
+ { id: "n2", type: "helper" }];
+ helper.load(csvNode, flow, function () {
+ const n1 = helper.getNode("n1");
+ const n2 = helper.getNode("n2");
+ n2.on("input", function (msg) {
+ try {
+ msg.should.have.property('result').and.be.an.Object();
+ msg.result.should.have.property('sub_prop', { a: 1, b: 2, c: 3, d: 4 });
+ msg.should.have.property('columns', "a,b,c,d");
+ check_parts(msg, 0, 1);
+ done();
+ }
+ catch (e) { done(e); }
+ });
+ const testString = "1,2,3,4" + String.fromCharCode(10);
+ n1.emit("input", { payload: { sub: { prop: testString } } });
+ });
+ })
});
describe('json object to csv', function () {
@@ -2336,6 +2397,23 @@ describe('CSV node (RFC Mode)', function () {
});
});
+ it ('should use message properties specified for `property in` and `property out`', function(done) {
+ const flow = [{ id: "n1", type: "csv", spec: "rfc", temp: "a,b,c,d", ret: '\n', property: 'payload.sub.prop', propertyOut: 'result', wires: [["n2"]] }, // RFC-vs-Legacy difference - use line separator \n to satisfy original test
+ { id: "n2", type: "helper" }];
+ helper.load(csvNode, flow, function() {
+ const n1 = helper.getNode("n1");
+ const n2 = helper.getNode("n2");
+ n2.on("input", function(msg) {
+ try {
+ msg.should.have.property('result', '4,3,2,1\n');
+ done();
+ } catch(e) { done(e); }
+ });
+ const testJson = { d: 1, b: 3, c: 2, a: 4 };
+ n1.emit("input", { payload: { sub: { prop: testJson } } });
+ });
+ })
+
});
it('should just pass through if no payload provided', function (done) {
diff --git a/test/nodes/core/parsers/70-JSON_spec.js b/test/nodes/core/parsers/70-JSON_spec.js
index f6bfc99c4..7188aeede 100644
--- a/test/nodes/core/parsers/70-JSON_spec.js
+++ b/test/nodes/core/parsers/70-JSON_spec.js
@@ -32,6 +32,25 @@ describe('JSON node', function() {
helper.unload();
});
+ it('should be loaded with defaults', function(done) {
+ const flow = [{id:"jn1",type:"json", name: 'json node',wires:[["jn2"]]}]
+ helper.load(jsonNode, flow, function() {
+ const n1 = helper.getNode("jn1")
+ try {
+ n1.should.have.property('name', 'json node')
+ n1.should.have.property('property','payload')
+ n1.should.have.property('propertyOut','payload')
+ n1.should.have.property('schema', null)
+ n1.should.have.property('compiledSchema', null)
+ n1.should.have.property('action', '')
+ n1.should.have.property('indent', 0)
+ done();
+ } catch (error) {
+ done(error)
+ }
+ })
+ })
+
it('should convert a valid json string to a javascript object', function(done) {
var flow = [{id:"jn1",type:"json",wires:[["jn2"]]},
{id:"jn2", type:"helper"}];
@@ -587,4 +606,56 @@ describe('JSON node', function() {
jn1.receive({payload:jsonObject, schema:schema});
});
});
+
+ it('should convert a valid json string to a javascript object using message properties specified for `property in` and `property out`', function (done) {
+ const flow = [{ id: "jn1", type: "json", property: "payload.sub.prop", propertyOut: "result", wires: [["jn2"]] },
+ { id: "jn2", type: "helper" }]
+ helper.load(jsonNode, flow, function () {
+ const jn1 = helper.getNode("jn1")
+ const jn2 = helper.getNode("jn2")
+ jn2.on("input", function (msg) {
+ msg.should.have.property('topic', 'bar')
+ msg.should.have.property('result').and.be.an.Object()
+ msg.result.should.have.property('employees')
+ msg.result.employees[0].should.have.property('firstName', 'John')
+ msg.result.employees[0].should.have.property('lastName', 'Smith')
+ done()
+ })
+ const jsonString = ' {"employees":[{"firstName":"John", "lastName":"Smith"}]}\r\n '
+ jn1.receive({ topic: "bar", payload: { sub: { prop: jsonString } } })
+ })
+ })
+
+ it('should convert a javascript object to a json string using message properties specified for `property in` and `property out`', function (done) {
+ const flow = [{ id: "jn1", type: "json", property: "payload.sub.prop", propertyOut: "result", wires: [["jn2"]] },
+ { id: "jn2", type: "helper" }]
+ helper.load(jsonNode, flow, function () {
+ const jn1 = helper.getNode("jn1")
+ const jn2 = helper.getNode("jn2")
+ jn2.on("input", function (msg) {
+ msg.should.have.property('result').and.be.a.String()
+ should.equal(msg.result, '{"employees":[{"firstName":"John","lastName":"Smith"}]}')
+ done()
+ })
+ const obj = { employees: [{ firstName: "John", lastName: "Smith" }] }
+ jn1.receive({ payload: { sub: { prop: obj } } })
+ })
+ })
+
+ it('should pass through if property specified for `property in` is missing', function (done) {
+ const flow = [{ id: "jn1", type: "json", property: "payload.sub.prop", propertyOut: "result", wires: [["jn2"]] },
+ { id: "jn2", type: "helper" }]
+ helper.load(jsonNode, flow, function () {
+ const jn1 = helper.getNode("jn1")
+ const jn2 = helper.getNode("jn2")
+ const obj = { employees: [{ firstName: "John", lastName: "Smith" }] }
+ jn2.on("input", function (msg) {
+ msg.should.not.have.property('result') // never set
+ msg.should.have.propertyByPath('payload', 'sub', 'propBAD').and.be.an.Object() // unchanged
+ msg.payload.sub.propBAD.should.deepEqual(obj)
+ done()
+ })
+ jn1.receive({ payload: { sub: { propBAD: obj } } })
+ })
+ })
});
diff --git a/test/nodes/core/parsers/70-XML_spec.js b/test/nodes/core/parsers/70-XML_spec.js
index c5e13f952..07c9407be 100644
--- a/test/nodes/core/parsers/70-XML_spec.js
+++ b/test/nodes/core/parsers/70-XML_spec.js
@@ -32,12 +32,18 @@ describe('XML node', function() {
helper.unload();
});
- it('should be loaded', function(done) {
+ it('should load with defaults', function(done) {
var flow = [{id:"xmlNode1", type:"xml", name: "xmlNode" }];
helper.load(xmlNode, flow, function() {
- var xmlNode1 = helper.getNode("xmlNode1");
- xmlNode1.should.have.property('name', 'xmlNode');
- done();
+ try {
+ var xmlNode1 = helper.getNode("xmlNode1");
+ xmlNode1.should.have.property('name', 'xmlNode');
+ xmlNode1.should.have.property('property', 'payload')
+ xmlNode1.should.have.property('propertyOut', 'payload')
+ done();
+ } catch (error) {
+ done(error);
+ }
});
});
@@ -195,4 +201,41 @@ describe('XML node', function() {
});
});
+ it('should convert a valid xml string to a javascript object using message properties specified for `property in` and `property out`', function(done) {
+ const flow = [{ id: "n1", type: "xml", property: "payload.sub.prop", propertyOut: 'result', wires: [["n2"]], func: "return msg;" },
+ { id: "n2", type: "helper" }]
+ helper.load(xmlNode, flow, function () {
+ const n1 = helper.getNode("n1")
+ const n2 = helper.getNode("n2")
+ n2.on("input", function (msg) {
+ msg.should.have.property('topic', 'bar')
+ msg.should.have.property('result').and.be.an.Object()
+ msg.result.should.have.property('employees')
+ msg.result.employees.should.have.property('firstName')
+ should.equal(msg.result.employees.firstName[0], 'John')
+ msg.result.employees.should.have.property('lastName')
+ should.equal(msg.result.employees.lastName[0], 'Smith')
+ done()
+ })
+ const string = ' JohnSmith\r\n '
+ n1.receive({ topic: "bar", payload: { sub: { prop: string } } })
+ })
+ })
+
+ it('should convert a javascript object to an xml string using message properties specified for `property in` and `property out`', function (done) {
+ const flow = [{ id: "n1", type: "xml", property: "payload.sub.prop", propertyOut: 'result', wires: [["n2"]], func: "return msg" },
+ { id: "n2", type: "helper" }]
+ helper.load(xmlNode, flow, function () {
+ const n1 = helper.getNode("n1")
+ const n2 = helper.getNode("n2")
+ n2.on("input", function (msg) {
+ msg.should.have.property('topic', 'bar')
+ const index = msg.result.indexOf('JohnSmith')
+ index.should.be.above(-1)
+ done()
+ })
+ const obj = { "employees": { "firstName": ["John"], "lastName": ["Smith"] } }
+ n1.receive({ topic: "bar", payload: { sub: { prop: obj } } })
+ })
+ })
});
diff --git a/test/nodes/core/parsers/70-YAML_spec.js b/test/nodes/core/parsers/70-YAML_spec.js
index 3441e0946..0697dc25a 100644
--- a/test/nodes/core/parsers/70-YAML_spec.js
+++ b/test/nodes/core/parsers/70-YAML_spec.js
@@ -32,12 +32,18 @@ describe('YAML node', function() {
helper.unload();
});
- it('should be loaded', function(done) {
+ it('should load with defaults', function(done) {
var flow = [{id:"yamlNode1", type:"yaml", name: "yamlNode" }];
helper.load(yamlNode, flow, function() {
- var yamlNode1 = helper.getNode("yamlNode1");
- yamlNode1.should.have.property('name', 'yamlNode');
- done();
+ try {
+ var yamlNode1 = helper.getNode("yamlNode1");
+ yamlNode1.should.have.property('name', 'yamlNode');
+ yamlNode1.should.have.property('property', 'payload')
+ yamlNode1.should.have.property('propertyOut', 'payload')
+ done();
+ } catch (error) {
+ done(error);
+ }
});
});
@@ -192,4 +198,36 @@ describe('YAML node', function() {
});
});
+ it('should convert a valid yaml string to a javascript object using message properties specified for `property in` and `property out`', function (done) {
+ const flow = [{ id: "yn1", type: "yaml", property: "payload.sub.prop", propertyOut: "result", wires: [["yn2"]], func: "return msg;" },
+ { id: "yn2", type: "helper" }]
+ helper.load(yamlNode, flow, function () {
+ const yn1 = helper.getNode("yn1")
+ const yn2 = helper.getNode("yn2")
+ yn2.on("input", function (msg) {
+ msg.should.have.property('topic', 'bar')
+ msg.result.should.have.property('employees')
+ msg.result.employees[0].should.have.property('firstName', 'John')
+ msg.result.employees[0].should.have.property('lastName', 'Smith')
+ done()
+ })
+ const yamlString = "employees:\n - firstName: John\n lastName: Smith\n"
+ yn1.receive({ topic: "bar", payload: { sub: { prop: yamlString } } })
+ })
+ })
+
+ it('should convert a javascript object to a yaml string using message properties specified for `property in` and `property out`', function (done) {
+ const flow = [{ id: "yn1", type: "yaml", property: "payload.sub.prop", propertyOut: "result", wires: [["yn2"]], func: "return msg;" },
+ { id: "yn2", type: "helper" }]
+ helper.load(yamlNode, flow, function () {
+ const yn1 = helper.getNode("yn1")
+ const yn2 = helper.getNode("yn2")
+ yn2.on("input", function (msg) {
+ should.equal(msg.result, "employees:\n - firstName: John\n lastName: Smith\n")
+ done()
+ })
+ const obj = { employees: [{ firstName: "John", lastName: "Smith" }] }
+ yn1.receive({ payload: { sub: { prop: obj } } })
+ })
+ })
});
diff --git a/test/nodes/core/storage/10-file_spec.js b/test/nodes/core/storage/10-file_spec.js
index d1a9e1164..7c90749fa 100644
--- a/test/nodes/core/storage/10-file_spec.js
+++ b/test/nodes/core/storage/10-file_spec.js
@@ -1239,11 +1239,12 @@ describe('file Nodes', function() {
});
});
- it('should be loaded', function(done) {
+ it('should load with defaults', function(done) {
var flow = [{id:"fileInNode1", type:"file in", name: "fileInNode", "filename":fileToTest, "format":"utf8"}];
helper.load(fileNode, flow, function() {
var n1 = helper.getNode("fileInNode1");
n1.should.have.property('name', 'fileInNode');
+ n1.should.have.property('propertyOut', 'payload')
done();
});
});
@@ -1530,6 +1531,23 @@ describe('file Nodes', function() {
});
});
+ it('should read in a file and output to the message property specified in `propertyOut`', function (done) {
+ const flow = [{ id: "fileInNode1", type: "file in", name: "fileInNode", "filename": fileToTest, "format": "", propertyOut: "file-data", wires: [["n2"]] },
+ { id: "n2", type: "helper" }]
+ helper.load(fileNode, flow, function () {
+ const n1 = helper.getNode("fileInNode1")
+ const n2 = helper.getNode("n2")
+ n2.on("input", function (msg) {
+ msg.should.have.property('file-data')
+ Buffer.isBuffer(msg['file-data']).should.be.true()
+ msg['file-data'].should.have.length(40)
+ msg['file-data'].toString().should.equal('File message line 1\nFile message line 2\n')
+ done()
+ })
+ n1.receive({ payload: "" })
+ })
+ })
+
describe('encodings', function() {
function checkReadWithEncoding(enc, data, done) {