From 2f4e8936d3d1fbda18a1e5bc5c678feec3c611ef Mon Sep 17 00:00:00 2001 From: Kazuhito Yokoi Date: Thu, 14 Jun 2018 15:10:01 +0900 Subject: [PATCH] Add test case for function node template --- Gruntfile.js | 3 + samples/pass-through-topic.js | 3 + .../node_spec.js | 58 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 samples/pass-through-topic.js create mode 100644 test/nodegen/node-red-contrib-pass-through-topic/node_spec.js diff --git a/Gruntfile.js b/Gruntfile.js index d0c7b0d..dcbe1f6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -7,6 +7,9 @@ module.exports = function (grunt) { generateNode_sendReturnedMessage: { command: 'node bin/node-red-nodegen.js samples/send-returned-message.js -o ./nodegen' }, + generateNode_passThroughTopic: { + command: 'node bin/node-red-nodegen.js samples/pass-through-topic.js -o ./nodegen' + }, generateNode_setNodeContext: { command: 'node bin/node-red-nodegen.js samples/set-node-context.js -o ./nodegen' }, diff --git a/samples/pass-through-topic.js b/samples/pass-through-topic.js new file mode 100644 index 0000000..b8eaed2 --- /dev/null +++ b/samples/pass-through-topic.js @@ -0,0 +1,3 @@ +// name: pass through _topic +// outputs: 1 +return msg; \ No newline at end of file diff --git a/test/nodegen/node-red-contrib-pass-through-topic/node_spec.js b/test/nodegen/node-red-contrib-pass-through-topic/node_spec.js new file mode 100644 index 0000000..dd6f5c5 --- /dev/null +++ b/test/nodegen/node-red-contrib-pass-through-topic/node_spec.js @@ -0,0 +1,58 @@ +/** + * Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var should = require("should"); +var helper = require("node-red-node-test-helper"); +var functionNode = require("../../../nodegen/node-red-contrib-pass-through-topic"); + +describe('node-red-contrib-pass-through-topic', function () { + + before(function (done) { + helper.startServer(done); + }); + + after(function (done) { + helper.stopServer(done); + }); + + afterEach(function () { + helper.unload(); + }); + + it('should be loaded', function (done) { + var flow = [{id: "n1", type: "pass-through-topic", name: "pass-through-topic" }]; + helper.load(functionNode, flow, function () { + var n1 = helper.getNode('n1'); + n1.should.have.property('name', 'pass-through-topic'); + done(); + }); + }); + it('should pass through _topic', function (done) { + var flow = [{id: "n1", type: "pass-through-topic", wires: [["n2"]]}, + {id: "n2", type: "helper"}]; + helper.load(functionNode, 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('_topic', 'baz'); + done(); + }); + n1.receive({payload: "foo", topic: "bar", _topic: "baz"}); + }); + }); +});