2 * Copyright 2014 IBM Corp.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 var should = require("should");
18 var injectNode = require("../../../../nodes/core/core/20-inject.js");
19 var helper = require("../../helper.js");
21 describe('inject node', function() {
23 before(function(done) {
24 helper.startServer(done);
27 afterEach(function() {
31 it('should inject once', function(done) {
33 helper.load(injectNode, [{id:"n1", type:"inject",
34 payload:"payload", topic: "t1",
35 once: true, wires:[["n2"]] },
36 {id:"n2", type:"helper"}],
38 var n2 = helper.getNode("n2");
39 n2.on("input", function(msg) {
40 msg.should.have.property('topic', 't1');
41 msg.should.have.property('payload', 'payload');
47 it('should inject repeatedly', function(done) {
49 helper.load(injectNode, [{id:"n1", type:"inject",
50 payload:"payload", topic: "t2",
51 repeat: 0.2, wires:[["n2"]] },
52 {id:"n2", type:"helper"}],
54 var n2 = helper.getNode("n2");
56 n2.on("input", function(msg) {
57 msg.should.have.property('topic', 't2');
58 msg.should.have.property('payload', 'payload');
61 helper.clearFlows().then(function() {
69 it('should inject with cron', function(done) {
70 helper.load(injectNode, [{id:"n1", type:"inject",
71 payloadType:"date", topic: "t3",
72 crontab: "* * * * * *", wires:[["n3"]] },
73 {id:"n3", type:"helper"}],
75 var n3 = helper.getNode("n3");
76 n3.on("input", function(msg) {
77 msg.should.have.property('topic', 't3');
78 msg.should.have.property('payload').be.a.Number;
79 helper.clearFlows().then(function() {
86 describe('post', function() {
87 it('should inject message', function(done) {
88 helper.load(injectNode,
89 [{id:"n1", type:"inject",
90 payloadType:"some type", topic: "t4",
92 { id:"n4", type:"helper"}], function() {
93 var n4 = helper.getNode("n4");
94 n4.on("input", function(msg) {
95 msg.should.have.property('topic', 't4');
96 msg.should.have.property('payload', '');
97 helper.clearFlows().then(function() {
103 .expect(200).end(function(err) {
105 return helper.clearFlows()
114 it('should fail for invalid node', function(done) {
115 helper.request().post('/inject/invalid').expect(404).end(done);