enable template config via msg.template for stored or generated templates (#1503)

* updates to 80-template to allow setting template with msg.template

* updated 80-template_spec test for msg.template support

* fixed 80-template.js test
This commit is contained in:
Ross Cruickshank
2017-12-05 12:24:06 +00:00
committed by Dave Conway-Jones
parent 3988a648d6
commit f21c8154ed
3 changed files with 45 additions and 1 deletions

View File

@@ -37,9 +37,40 @@ describe('template node', function() {
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', 'payload=foo');
msg.should.have.property('template', '{{payload}}');
done();
});
n1.receive({payload:"foo",topic: "bar"});
n1.receive({payload:"foo",topic: "bar", template: "{{payload}}"});
});
});
it('should modify template from msg.template', function(done) {
var flow = [{id:"n1", type:"template", field:"template", template:"",wires:[["n2"]]},{id:"n2",type:"helper"}];
helper.load(templateNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', 'foo');
msg.should.have.property('template', 'payload=foo');
done();
});
n1.receive({payload:"foo", topic: "bar", template: "payload={{payload}}"});
});
});
it('should modify payload from msg.template', function(done) {
var flow = [{id:"n1", type:"template", field:"payload", template:"",wires:[["n2"]]},{id:"n2",type:"helper"}];
helper.load(templateNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload', 'topic=bar');
msg.should.have.property('template', 'topic={{topic}}');
done();
});
n1.receive({payload:"foo", topic: "bar", template: "topic={{topic}}"});
});
});