[CCSDK-28] populated the seed code for dgbuilder
[ccsdk/distribution.git] / dgbuilder / test / nodes / core / core / 80-template_spec.js
1 /**
2  * Copyright 2014 IBM Corp.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  **/
16
17 var should = require("should");
18 var templateNode = require("../../../../nodes/core/core/80-template.js");
19 var helper = require("../../helper.js");
20
21 describe('template node', function() {
22
23     before(function(done) {
24         helper.startServer(done);
25     });
26     
27     afterEach(function() {
28         helper.unload();
29     });
30
31
32     it('should modify payload', function(done) {
33         var flow = [{id:"n1", type:"template", field: "payload", template: "payload={{payload}}",wires:[["n2"]]},{id:"n2",type:"helper"}];
34         helper.load(templateNode, flow, function() {
35             var n1 = helper.getNode("n1");
36             var n2 = helper.getNode("n2");
37             n2.on("input", function(msg) {
38                 msg.should.have.property('topic', 'bar');
39                 msg.should.have.property('payload', 'payload=foo');
40                 done();
41             });
42             n1.receive({payload:"foo",topic: "bar"});
43         });
44     });
45
46 });