2018-07-27 06:48:43 +02:00
|
|
|
/**
|
|
|
|
* 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("../../editor_helper");
|
2018-08-22 07:36:30 +02:00
|
|
|
var debugTab = require('../../pageobjects/editor/debugTab_page');
|
|
|
|
var workspace = require('../../pageobjects/editor/workspace_page');
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
var httpNodeRoot = "/api";
|
|
|
|
|
|
|
|
// https://cookbook.nodered.org/
|
|
|
|
describe('cookbook', function() {
|
|
|
|
beforeEach(function() {
|
2018-10-23 07:01:23 +02:00
|
|
|
workspace.init();
|
2018-07-27 06:48:43 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
before(function() {
|
|
|
|
helper.startServer();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function() {
|
|
|
|
helper.stopServer();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('HTTP endpoints', function () {
|
|
|
|
it('create an HTTP endpoint', function () {
|
2019-12-02 04:43:13 +01:00
|
|
|
var httpInNode = workspace.addNode("httpIn");
|
2018-10-23 07:01:23 +02:00
|
|
|
var templateNode = workspace.addNode("template");
|
|
|
|
var httpResponseNode = workspace.addNode("httpResponse");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.edit();
|
|
|
|
httpInNode.setMethod("get");
|
|
|
|
httpInNode.setUrl("/hello");
|
|
|
|
httpInNode.clickOk();
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
templateNode.edit();
|
|
|
|
templateNode.setSyntax("mustache");
|
|
|
|
templateNode.setFormat("handlebars");
|
|
|
|
templateNode.setTemplate("<html>\n<head></head>\n<body>\n<h1>Hello World!</h1>\n</body>\n</html>");
|
|
|
|
templateNode.clickOk();
|
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.connect(templateNode);
|
2018-07-27 06:48:43 +02:00
|
|
|
templateNode.connect(httpResponseNode);
|
|
|
|
|
|
|
|
// The code for confirmation starts from here.
|
2018-10-23 07:01:23 +02:00
|
|
|
var injectNode = workspace.addNode("inject");
|
|
|
|
var httpRequestNode = workspace.addNode("httpRequest");
|
|
|
|
var debugNode = workspace.addNode("debug");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
httpRequestNode.edit();
|
|
|
|
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello');
|
2018-08-22 07:36:30 +02:00
|
|
|
httpRequestNode.setMethod("GET");
|
2018-07-27 06:48:43 +02:00
|
|
|
httpRequestNode.clickOk();
|
|
|
|
|
|
|
|
injectNode.connect(httpRequestNode);
|
|
|
|
httpRequestNode.connect(debugNode);
|
|
|
|
// The code for confirmation ends here.
|
|
|
|
|
|
|
|
workspace.deploy();
|
|
|
|
debugTab.open();
|
|
|
|
injectNode.clickLeftButton();
|
|
|
|
debugTab.getMessage().indexOf('Hello World!').should.not.eql(-1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handle query parameters passed to an HTTP endpoint', function () {
|
2019-12-02 04:43:13 +01:00
|
|
|
var httpInNode = workspace.addNode("httpIn");
|
2018-10-23 07:01:23 +02:00
|
|
|
var templateNode = workspace.addNode("template");
|
|
|
|
var httpResponseNode = workspace.addNode("httpResponse");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.edit();
|
|
|
|
httpInNode.setMethod("get");
|
|
|
|
httpInNode.setUrl("/hello-query");
|
|
|
|
httpInNode.clickOk();
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
templateNode.edit();
|
|
|
|
templateNode.setSyntax("mustache");
|
|
|
|
templateNode.setFormat("handlebars");
|
|
|
|
templateNode.setTemplate("<html>\n<head></head>\n<body>\n<h1>Hello {{req.query.name}}!</h1>\n</body>\n</html>");
|
|
|
|
templateNode.clickOk();
|
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.connect(templateNode);
|
2018-07-27 06:48:43 +02:00
|
|
|
templateNode.connect(httpResponseNode);
|
|
|
|
|
|
|
|
// The code for confirmation starts from here.
|
2018-10-23 07:01:23 +02:00
|
|
|
var injectNode = workspace.addNode("inject");
|
|
|
|
var httpRequestNode = workspace.addNode("httpRequest");
|
|
|
|
var debugNode = workspace.addNode("debug");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
httpRequestNode.edit();
|
|
|
|
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-query?name=Nick');
|
2018-08-22 07:36:30 +02:00
|
|
|
httpRequestNode.setMethod("GET");
|
2018-07-27 06:48:43 +02:00
|
|
|
httpRequestNode.clickOk();
|
|
|
|
|
|
|
|
injectNode.connect(httpRequestNode);
|
|
|
|
httpRequestNode.connect(debugNode);
|
|
|
|
// The code for confirmation ends here.
|
|
|
|
|
|
|
|
workspace.deploy();
|
|
|
|
debugTab.open();
|
|
|
|
injectNode.clickLeftButton();
|
|
|
|
debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handle url parameters in an HTTP endpoint', function () {
|
2019-12-02 04:43:13 +01:00
|
|
|
var httpInNode = workspace.addNode("httpIn");
|
2018-10-23 07:01:23 +02:00
|
|
|
var templateNode = workspace.addNode("template");
|
|
|
|
var httpResponseNode = workspace.addNode("httpResponse");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.edit();
|
|
|
|
httpInNode.setMethod("get");
|
|
|
|
httpInNode.setUrl("/hello-param/:name");
|
|
|
|
httpInNode.clickOk();
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
templateNode.edit();
|
|
|
|
templateNode.setSyntax("mustache");
|
|
|
|
templateNode.setFormat("handlebars");
|
|
|
|
templateNode.setTemplate("<html>\n<head></head>\n<body>\n<h1>Hello {{req.params.name}}!</h1>\n</body>\n</html>");
|
|
|
|
templateNode.clickOk();
|
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.connect(templateNode);
|
2018-07-27 06:48:43 +02:00
|
|
|
templateNode.connect(httpResponseNode);
|
|
|
|
|
|
|
|
// The code for confirmation starts from here.
|
2018-10-23 07:01:23 +02:00
|
|
|
var injectNode = workspace.addNode("inject");
|
|
|
|
var httpRequestNode = workspace.addNode("httpRequest");
|
|
|
|
var debugNode = workspace.addNode("debug");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
httpRequestNode.edit();
|
|
|
|
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-param/Dave');
|
2018-08-22 07:36:30 +02:00
|
|
|
httpRequestNode.setMethod("GET");
|
2018-07-27 06:48:43 +02:00
|
|
|
httpRequestNode.clickOk();
|
|
|
|
|
|
|
|
injectNode.connect(httpRequestNode);
|
|
|
|
httpRequestNode.connect(debugNode);
|
|
|
|
// The code for confirmation ends here.
|
|
|
|
|
|
|
|
workspace.deploy();
|
|
|
|
debugTab.open();
|
|
|
|
injectNode.clickLeftButton();
|
|
|
|
debugTab.getMessage().indexOf('Hello Dave!').should.not.eql(-1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('access HTTP request headers', function () {
|
2019-12-02 04:43:13 +01:00
|
|
|
var httpInNode = workspace.addNode("httpIn");
|
2018-10-23 07:01:23 +02:00
|
|
|
var templateNode = workspace.addNode("template");
|
|
|
|
var httpResponseNode = workspace.addNode("httpResponse");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.edit();
|
|
|
|
httpInNode.setMethod("get");
|
|
|
|
httpInNode.setUrl("/hello-headers");
|
|
|
|
httpInNode.clickOk();
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
templateNode.edit();
|
|
|
|
templateNode.setSyntax("mustache");
|
|
|
|
templateNode.setFormat("handlebars");
|
|
|
|
templateNode.setTemplate("<html>\n<head></head>\n<body>\n<h1>User agent: {{req.headers.user-agent}}</h1>\n</body>\n</html>");
|
|
|
|
templateNode.clickOk();
|
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.connect(templateNode);
|
2018-07-27 06:48:43 +02:00
|
|
|
templateNode.connect(httpResponseNode);
|
|
|
|
|
|
|
|
// The code for confirmation starts from here.
|
2018-10-23 07:01:23 +02:00
|
|
|
var injectNode = workspace.addNode("inject", 0, 100);
|
|
|
|
var changeNode = workspace.addNode("change");
|
|
|
|
var httpRequestNode = workspace.addNode("httpRequest");
|
|
|
|
var debugNode = workspace.addNode("debug");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
changeNode.edit();
|
2018-08-27 10:34:04 +02:00
|
|
|
changeNode.ruleSet("headers", "msg", '{"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64)"}', "json");
|
2018-07-27 06:48:43 +02:00
|
|
|
changeNode.clickOk();
|
|
|
|
|
|
|
|
httpRequestNode.edit();
|
|
|
|
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-headers');
|
2018-08-22 07:36:30 +02:00
|
|
|
httpRequestNode.setMethod("GET");
|
2018-07-27 06:48:43 +02:00
|
|
|
httpRequestNode.clickOk();
|
|
|
|
|
|
|
|
injectNode.connect(changeNode);
|
|
|
|
changeNode.connect(httpRequestNode);
|
|
|
|
httpRequestNode.connect(debugNode);
|
|
|
|
// The code for confirmation ends here.
|
|
|
|
|
|
|
|
workspace.deploy();
|
|
|
|
debugTab.open();
|
|
|
|
injectNode.clickLeftButton();
|
|
|
|
debugTab.getMessage().indexOf('Mozilla').should.not.eql(-1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('include data captured in another flow', function () {
|
|
|
|
var injectNodeTimestamp = workspace.addNode("inject");
|
2018-10-23 07:01:23 +02:00
|
|
|
var changeNodeStore = workspace.addNode("change");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
var httpInNode = workspace.addNode("httpIn", 0, 100);
|
2018-10-23 07:01:23 +02:00
|
|
|
var changeNodeCopy = workspace.addNode("change");
|
|
|
|
var templateNode = workspace.addNode("template");
|
|
|
|
var httpResponseNode = workspace.addNode("httpResponse");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
injectNodeTimestamp.edit();
|
|
|
|
injectNodeTimestamp.setPayload("date");
|
|
|
|
injectNodeTimestamp.clickOk();
|
|
|
|
|
|
|
|
changeNodeStore.edit();
|
|
|
|
changeNodeStore.ruleSet("timestamp", "flow", "payload", "msg");
|
|
|
|
changeNodeStore.clickOk();
|
|
|
|
|
|
|
|
injectNodeTimestamp.connect(changeNodeStore);
|
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.edit();
|
|
|
|
httpInNode.setMethod("get");
|
|
|
|
httpInNode.setUrl("/hello-data");
|
|
|
|
httpInNode.clickOk();
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
changeNodeCopy.edit();
|
|
|
|
changeNodeCopy.ruleSet("timestamp", "msg", "timestamp", "flow");
|
|
|
|
changeNodeCopy.clickOk();
|
|
|
|
|
|
|
|
templateNode.edit();
|
|
|
|
templateNode.setSyntax("mustache");
|
|
|
|
templateNode.setFormat("handlebars");
|
|
|
|
templateNode.setTemplate("<html>\n<head></head>\n<body>\n<h1>Time: {{ timestamp }}</h1>\n</body>\n</html>");
|
|
|
|
templateNode.clickOk();
|
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.connect(changeNodeCopy);
|
2018-07-27 06:48:43 +02:00
|
|
|
changeNodeCopy.connect(templateNode);
|
|
|
|
templateNode.connect(httpResponseNode);
|
|
|
|
|
|
|
|
// The code for confirmation starts from here.
|
2018-10-23 07:01:23 +02:00
|
|
|
var injectNodeCheck = workspace.addNode("inject", 0, 300);
|
|
|
|
var httpRequestNode = workspace.addNode("httpRequest");
|
|
|
|
var debugNode = workspace.addNode("debug");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
httpRequestNode.edit();
|
2018-08-22 07:36:30 +02:00
|
|
|
httpRequestNode.setMethod("GET");
|
2018-07-27 06:48:43 +02:00
|
|
|
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-data');
|
|
|
|
httpRequestNode.clickOk();
|
|
|
|
|
|
|
|
injectNodeCheck.connect(httpRequestNode);
|
|
|
|
httpRequestNode.connect(debugNode);
|
|
|
|
// The code for confirmation ends here.
|
|
|
|
|
|
|
|
workspace.deploy();
|
|
|
|
debugTab.open();
|
|
|
|
injectNodeTimestamp.clickLeftButton();
|
|
|
|
injectNodeCheck.clickLeftButton();
|
|
|
|
var index = debugTab.getMessage().indexOf('Time: ') + 6;
|
|
|
|
debugTab.getMessage().substring(index, index + 13).should.within(1500000000000, 3000000000000);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('serve JSON content', function () {
|
2019-12-02 04:43:13 +01:00
|
|
|
var httpInNode = workspace.addNode("httpIn");
|
2018-10-23 07:01:23 +02:00
|
|
|
var templateNode = workspace.addNode("template");
|
|
|
|
var changeNode = workspace.addNode("change");
|
|
|
|
var httpResponseNode = workspace.addNode("httpResponse");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.edit();
|
|
|
|
httpInNode.setMethod("get");
|
|
|
|
httpInNode.setUrl("/hello-json");
|
|
|
|
httpInNode.clickOk();
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
templateNode.edit();
|
|
|
|
templateNode.setSyntax("mustache");
|
|
|
|
templateNode.setFormat("handlebars");
|
2018-08-27 10:34:04 +02:00
|
|
|
templateNode.setTemplate('{ "Hello": "World" }');
|
2018-07-27 06:48:43 +02:00
|
|
|
templateNode.clickOk();
|
|
|
|
|
|
|
|
changeNode.edit();
|
|
|
|
changeNode.ruleSet("headers", "msg", "{}", "json", "1");
|
|
|
|
changeNode.addRule();
|
|
|
|
changeNode.ruleSet("headers.content-type", "msg", "application/json", "str", "2");
|
|
|
|
changeNode.clickOk();
|
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.connect(templateNode);
|
2018-07-27 06:48:43 +02:00
|
|
|
templateNode.connect(changeNode);
|
|
|
|
changeNode.connect(httpResponseNode);
|
|
|
|
|
|
|
|
// The code for confirmation starts from here.
|
2018-10-23 07:01:23 +02:00
|
|
|
var injectNode = workspace.addNode("inject", 0, 200);
|
|
|
|
var httpRequestNode = workspace.addNode("httpRequest");
|
2018-10-31 01:27:33 +01:00
|
|
|
var changeNodeCheck = workspace.addNode("change");
|
2018-10-23 07:01:23 +02:00
|
|
|
var debugNode = workspace.addNode("debug");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
httpRequestNode.edit();
|
2018-08-22 07:36:30 +02:00
|
|
|
httpRequestNode.setMethod("GET");
|
2018-07-27 06:48:43 +02:00
|
|
|
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-json');
|
|
|
|
httpRequestNode.clickOk();
|
|
|
|
|
2018-10-31 01:27:33 +01:00
|
|
|
changeNodeCheck.edit();
|
|
|
|
changeNodeCheck.ruleSet("payload", "msg", "headers.content-type", "msg", "1");
|
|
|
|
changeNodeCheck.clickOk();
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
injectNode.connect(httpRequestNode);
|
2018-10-31 01:27:33 +01:00
|
|
|
httpRequestNode.connect(changeNodeCheck);
|
|
|
|
changeNodeCheck.connect(debugNode);
|
2018-07-27 06:48:43 +02:00
|
|
|
// The code for confirmation ends here.
|
|
|
|
|
|
|
|
workspace.deploy();
|
|
|
|
debugTab.open();
|
|
|
|
injectNode.clickLeftButton();
|
2018-10-11 11:16:08 +02:00
|
|
|
var messages = debugTab.getMessage();
|
2018-10-31 01:27:33 +01:00
|
|
|
messages.indexOf('application/json').should.not.eql(-1);
|
2018-07-27 06:48:43 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('serve a local file', function () {
|
2019-12-02 04:43:13 +01:00
|
|
|
var httpInNode = workspace.addNode("httpIn");
|
|
|
|
var fileInNode = workspace.addNode("fileIn");
|
2018-10-23 07:01:23 +02:00
|
|
|
var changeNode = workspace.addNode("change", 200, 100);
|
|
|
|
var httpResponseNode = workspace.addNode("httpResponse");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.edit();
|
|
|
|
httpInNode.setMethod("get");
|
|
|
|
httpInNode.setUrl("/hello-file");
|
|
|
|
httpInNode.clickOk();
|
2018-07-27 06:48:43 +02:00
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
fileInNode.edit();
|
|
|
|
fileInNode.setFilename("test/resources/file-in-node/test.txt");
|
|
|
|
fileInNode.setOutput("");
|
|
|
|
fileInNode.clickOk();
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
changeNode.edit();
|
|
|
|
changeNode.ruleSet("headers", "msg", "{}", "json");
|
|
|
|
changeNode.addRule();
|
|
|
|
changeNode.ruleSet("headers.content-type", "msg", "text/plain", "str", "2");
|
|
|
|
changeNode.clickOk();
|
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.connect(fileInNode);
|
|
|
|
fileInNode.connect(changeNode);
|
2018-07-27 06:48:43 +02:00
|
|
|
changeNode.connect(httpResponseNode);
|
|
|
|
|
|
|
|
// The code for confirmation starts from here.
|
2018-10-23 07:01:23 +02:00
|
|
|
var injectNode = workspace.addNode("inject", 0, 200);
|
|
|
|
var httpRequestNode = workspace.addNode("httpRequest");
|
|
|
|
var debugNode = workspace.addNode("debug");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
httpRequestNode.edit();
|
|
|
|
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-file');
|
2018-08-22 07:36:30 +02:00
|
|
|
httpRequestNode.setMethod("GET");
|
2018-07-27 06:48:43 +02:00
|
|
|
httpRequestNode.clickOk();
|
|
|
|
|
|
|
|
injectNode.connect(httpRequestNode);
|
|
|
|
httpRequestNode.connect(debugNode);
|
|
|
|
// The code for confirmation ends here.
|
|
|
|
|
|
|
|
workspace.deploy();
|
|
|
|
debugTab.open();
|
|
|
|
injectNode.clickLeftButton();
|
|
|
|
debugTab.getMessage().indexOf('Text file').should.not.eql(-1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('post raw data to a flow', function() {
|
2019-12-02 04:43:13 +01:00
|
|
|
var httpInNode = workspace.addNode("httpIn");
|
2018-10-23 07:01:23 +02:00
|
|
|
var templateNode = workspace.addNode("template");
|
|
|
|
var httpResponseNode = workspace.addNode("httpResponse");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.edit();
|
|
|
|
httpInNode.setMethod("post");
|
|
|
|
httpInNode.setUrl("/hello-raw");
|
|
|
|
httpInNode.clickOk();
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
templateNode.edit();
|
|
|
|
templateNode.setSyntax("mustache");
|
|
|
|
templateNode.setFormat("handlebars");
|
|
|
|
templateNode.setTemplate("<html>\n<head></head>\n<body>\n<h1>Hello {{ payload }}!</h1>\n</body>\n</html>");
|
|
|
|
templateNode.clickOk();
|
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.connect(templateNode);
|
2018-07-27 06:48:43 +02:00
|
|
|
templateNode.connect(httpResponseNode);
|
|
|
|
|
|
|
|
// The code for confirmation starts from here.
|
2018-10-23 07:01:23 +02:00
|
|
|
var injectNode = workspace.addNode("inject");
|
|
|
|
var httpRequestNode = workspace.addNode("httpRequest");
|
|
|
|
var debugNode = workspace.addNode("debug");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
injectNode.edit()
|
|
|
|
injectNode.setPayload("str", "Nick");
|
|
|
|
injectNode.clickOk();
|
|
|
|
|
|
|
|
httpRequestNode.edit();
|
|
|
|
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-raw');
|
2018-08-22 07:36:30 +02:00
|
|
|
httpRequestNode.setMethod("POST");
|
2018-07-27 06:48:43 +02:00
|
|
|
httpRequestNode.clickOk();
|
|
|
|
|
|
|
|
injectNode.connect(httpRequestNode);
|
|
|
|
httpRequestNode.connect(debugNode);
|
|
|
|
// The code for confirmation ends here.
|
|
|
|
|
|
|
|
workspace.deploy();
|
|
|
|
debugTab.open();
|
|
|
|
injectNode.clickLeftButton();
|
|
|
|
debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('post form data to a flow', function () {
|
2019-12-02 04:43:13 +01:00
|
|
|
var httpInNode = workspace.addNode("httpIn");
|
2018-10-23 07:01:23 +02:00
|
|
|
var templateNode = workspace.addNode("template");
|
|
|
|
var httpResponseNode = workspace.addNode("httpResponse");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.edit();
|
|
|
|
httpInNode.setMethod("post");
|
|
|
|
httpInNode.setUrl("/hello-form");
|
|
|
|
httpInNode.clickOk();
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
templateNode.edit();
|
|
|
|
templateNode.setSyntax("mustache");
|
|
|
|
templateNode.setFormat("handlebars");
|
|
|
|
templateNode.setTemplate("<html>\n<head></head>\n<body>\n<h1>Hello {{ payload.name }}!</h1>\n</body>\n</html>");
|
|
|
|
templateNode.clickOk();
|
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.connect(templateNode);
|
2018-07-27 06:48:43 +02:00
|
|
|
templateNode.connect(httpResponseNode);
|
|
|
|
|
|
|
|
// The code for confirmation starts from here.
|
2018-10-23 07:01:23 +02:00
|
|
|
var injectNode = workspace.addNode("inject", 0, 100);
|
|
|
|
var changeNode = workspace.addNode("change");
|
|
|
|
var httpRequestNode = workspace.addNode("httpRequest");
|
|
|
|
var debugNode = workspace.addNode("debug");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
injectNode.edit()
|
|
|
|
injectNode.setPayload("str", "name=Nick");
|
|
|
|
injectNode.clickOk();
|
|
|
|
|
|
|
|
changeNode.edit();
|
2018-08-27 10:34:04 +02:00
|
|
|
changeNode.ruleSet("headers", "msg", '{"content-type":"application/x-www-form-urlencoded"}', "json");
|
2018-07-27 06:48:43 +02:00
|
|
|
changeNode.clickOk();
|
|
|
|
|
|
|
|
httpRequestNode.edit();
|
|
|
|
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-form');
|
2018-08-22 07:36:30 +02:00
|
|
|
httpRequestNode.setMethod("POST");
|
2018-07-27 06:48:43 +02:00
|
|
|
httpRequestNode.clickOk();
|
|
|
|
|
|
|
|
injectNode.connect(changeNode);
|
|
|
|
changeNode.connect(httpRequestNode);
|
|
|
|
httpRequestNode.connect(debugNode);
|
|
|
|
// The code for confirmation ends here.
|
|
|
|
|
|
|
|
workspace.deploy();
|
|
|
|
debugTab.open();
|
|
|
|
injectNode.clickLeftButton();
|
|
|
|
debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('post JSON data to a flow', function() {
|
2019-12-02 04:43:13 +01:00
|
|
|
var httpInNode = workspace.addNode("httpIn");
|
2018-10-23 07:01:23 +02:00
|
|
|
var templateNode = workspace.addNode("template");
|
|
|
|
var httpResponseNode = workspace.addNode("httpResponse");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.edit();
|
|
|
|
httpInNode.setMethod("post");
|
|
|
|
httpInNode.setUrl("/hello-json");
|
|
|
|
httpInNode.clickOk();
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
templateNode.edit();
|
|
|
|
templateNode.setSyntax("mustache");
|
|
|
|
templateNode.setFormat("handlebars");
|
|
|
|
templateNode.setTemplate("<html>\n<head></head>\n<body>\n<h1>Hello {{ payload.name }}!</h1>\n</body>\n</html>");
|
|
|
|
templateNode.clickOk();
|
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNode.connect(templateNode);
|
2018-07-27 06:48:43 +02:00
|
|
|
templateNode.connect(httpResponseNode);
|
|
|
|
|
|
|
|
// The code for confirmation starts from here.
|
2018-10-23 07:01:23 +02:00
|
|
|
var injectNode = workspace.addNode("inject", 0, 100);
|
|
|
|
var changeNode = workspace.addNode("change");
|
|
|
|
var httpRequestNode = workspace.addNode("httpRequest");
|
|
|
|
var debugNode = workspace.addNode("debug");
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
injectNode.edit()
|
2018-08-27 10:34:04 +02:00
|
|
|
injectNode.setPayload("json", '{"name":"Nick"}');
|
2018-07-27 06:48:43 +02:00
|
|
|
injectNode.clickOk();
|
|
|
|
|
|
|
|
changeNode.edit();
|
2018-08-27 10:34:04 +02:00
|
|
|
changeNode.ruleSet("headers", "msg", '{"content-type":"application/json"}', "json");
|
2018-07-27 06:48:43 +02:00
|
|
|
changeNode.clickOk();
|
|
|
|
|
|
|
|
httpRequestNode.edit();
|
|
|
|
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-json');
|
2018-08-22 07:36:30 +02:00
|
|
|
httpRequestNode.setMethod("POST");
|
2018-07-27 06:48:43 +02:00
|
|
|
httpRequestNode.clickOk();
|
|
|
|
|
|
|
|
injectNode.connect(changeNode);
|
|
|
|
changeNode.connect(httpRequestNode);
|
|
|
|
httpRequestNode.connect(debugNode);
|
|
|
|
// The code for confirmation ends here.
|
|
|
|
|
|
|
|
workspace.deploy();
|
|
|
|
debugTab.open();
|
|
|
|
injectNode.clickLeftButton();
|
|
|
|
debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('work with cookies', function () {
|
2019-12-02 04:43:13 +01:00
|
|
|
var httpInNodeFormat = workspace.addNode("httpIn");
|
2018-10-23 07:01:23 +02:00
|
|
|
var functionNodeFormat = workspace.addNode("function", 240);
|
|
|
|
var templateNode = workspace.addNode("template", 400);
|
|
|
|
var httpResponseNode = workspace.addNode("httpResponse", 600);
|
2018-07-27 06:48:43 +02:00
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
var httpInNodeAdd = workspace.addNode("httpIn", 0, 100);
|
2018-10-23 07:01:23 +02:00
|
|
|
var functionNodeAdd = workspace.addNode("function", 240);
|
|
|
|
var changeNode = workspace.addNode("change", 400);
|
2018-07-27 06:48:43 +02:00
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
var httpInNodeClear = workspace.addNode("httpIn", 0, 200);
|
2018-12-18 01:29:46 +01:00
|
|
|
var functionNodeClear = workspace.addNode("function", 250);
|
2018-07-27 06:48:43 +02:00
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNodeFormat.edit();
|
|
|
|
httpInNodeFormat.setMethod("get");
|
|
|
|
httpInNodeFormat.setUrl("/hello-cookie");
|
|
|
|
httpInNodeFormat.clickOk();
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
functionNodeFormat.edit();
|
2018-08-27 10:34:04 +02:00
|
|
|
functionNodeFormat.setFunction("msg.payload = JSON.stringify(msg.req.cookies,null,4);\nreturn msg;");
|
2018-07-27 06:48:43 +02:00
|
|
|
functionNodeFormat.clickOk();
|
|
|
|
|
|
|
|
templateNode.edit();
|
|
|
|
templateNode.setSyntax("mustache");
|
|
|
|
templateNode.setFormat("handlebars");
|
2018-08-27 10:34:04 +02:00
|
|
|
templateNode.setTemplate('<html>\n<head></head>\n<body>\n<h1>Cookies</h1>\n<p></p><a href="hello-cookie/add">Add a cookie</a> • <a href="hello-cookie/clear">Clear cookies</a></p>\n<pre>{{ payload }}</pre>\n</body>\n</html>');
|
2018-07-27 06:48:43 +02:00
|
|
|
templateNode.clickOk();
|
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNodeFormat.connect(functionNodeFormat);
|
2018-07-27 06:48:43 +02:00
|
|
|
functionNodeFormat.connect(templateNode);
|
|
|
|
templateNode.connect(httpResponseNode);
|
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNodeAdd.edit();
|
|
|
|
httpInNodeAdd.setMethod("get");
|
|
|
|
httpInNodeAdd.setUrl("/hello-cookie/add");
|
|
|
|
httpInNodeAdd.clickOk();
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
functionNodeAdd.edit();
|
2018-08-27 10:34:04 +02:00
|
|
|
functionNodeAdd.setFunction('msg.cookies = { };\n msg.cookies["demo-"+(Math.floor(Math.random()*1000))] = Date.now();\nreturn msg;');
|
2018-07-27 06:48:43 +02:00
|
|
|
functionNodeAdd.clickOk();
|
|
|
|
|
|
|
|
changeNode.edit();
|
|
|
|
changeNode.ruleSet("statusCode", "msg", "302", "num");
|
|
|
|
changeNode.addRule();
|
|
|
|
changeNode.ruleSet("headers", "msg", "{}", "json", "2");
|
|
|
|
changeNode.addRule();
|
|
|
|
changeNode.ruleSet("headers.location", "msg", httpNodeRoot + "/hello-cookie", "str", "3");
|
|
|
|
changeNode.clickOk();
|
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNodeAdd.connect(functionNodeAdd);
|
2018-07-27 06:48:43 +02:00
|
|
|
functionNodeAdd.connect(changeNode);
|
|
|
|
changeNode.connect(httpResponseNode);
|
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNodeClear.edit();
|
|
|
|
httpInNodeClear.setMethod("get");
|
|
|
|
httpInNodeClear.setUrl("/hello-cookie/clear");
|
|
|
|
httpInNodeClear.clickOk();
|
2018-07-27 06:48:43 +02:00
|
|
|
|
|
|
|
functionNodeClear.edit();
|
2018-08-27 10:34:04 +02:00
|
|
|
functionNodeClear.setFunction("var cookieNames = Object.keys(msg.req.cookies).filter(function(cookieName) { return /^demo-/.test(cookieName);});\nmsg.cookies = {};\n\ncookieNames.forEach(function(cookieName) {\n msg.cookies[cookieName] = null;\n});\nreturn msg;\n");
|
2018-07-27 06:48:43 +02:00
|
|
|
functionNodeClear.clickOk();
|
|
|
|
|
2019-12-02 04:43:13 +01:00
|
|
|
httpInNodeClear.connect(functionNodeClear);
|
2018-07-27 06:48:43 +02:00
|
|
|
functionNodeClear.connect(changeNode);
|
|
|
|
|
|
|
|
workspace.deploy();
|
|
|
|
// This case cannot be checked since http request node does not transfer cookies when redirected.
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|