1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #1847 from node-red-hitachi/update-uitest

Add UItest for http endpoints
This commit is contained in:
Nick O'Leary 2018-07-27 13:21:20 +01:00 committed by GitHub
commit 2000cadb17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 665 additions and 22 deletions

View File

@ -50,14 +50,23 @@ var timeType = {
"atASpecificTime": 4, "atASpecificTime": 4,
}; };
var timeType = {
"none": 1,
"interval": 2,
"intervalBetweenTimes": 3,
"atASpecificTime": 4,
};
injectNode.prototype.setPayload = function(type, value) { injectNode.prototype.setPayload = function(type, value) {
// Open a payload type list. // Open a payload type list.
browser.clickWithWait('//*[contains(@class, "red-ui-typedInput-container")]'); browser.clickWithWait('//*[contains(@class, "red-ui-typedInput-container")]');
// Select a payload type. // Select a payload type.
var payloadTypeXPath = '//*[@class="red-ui-typedInput-options"]/a[' + payloadType[type] + ']'; var payloadTypeXPath = '//*[@class="red-ui-typedInput-options"]/a[' + payloadType[type] + ']';
browser.clickWithWait(payloadTypeXPath); browser.clickWithWait(payloadTypeXPath);
// Input a value. if (value) {
browser.setValue('//*[@class="red-ui-typedInput-input"]/input', value); // Input a value.
browser.setValue('//*[@class="red-ui-typedInput-input"]/input', value);
}
} }
injectNode.prototype.setTopic = function(value) { injectNode.prototype.setTopic = function(value) {

View File

@ -0,0 +1,44 @@
/**
* 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 util = require("util");
var nodePage = require("../../node_page");
function fileinNode(id) {
nodePage.call(this, id);
}
util.inherits(fileinNode, nodePage);
var formatType = {
"utf8": 1,
"lines": 2,
"": 3, // a single Buffer object
"stream": 4
};
fileinNode.prototype.setFilename = function(value) {
browser.setValue('#node-input-filename', value);
}
fileinNode.prototype.setFormat = function(type) {
browser.clickWithWait('#node-input-format');
var formatTypeXPath = '//*[@id="node-input-format"]/option[' + formatType[type] + ']';
browser.clickWithWait(formatTypeXPath);
}
module.exports = fileinNode;

View File

@ -24,6 +24,7 @@ var changeNode = require('./core/logic/15-change_page');
var rangeNode = require('./core/logic/16-range_page'); var rangeNode = require('./core/logic/16-range_page');
var httpRequestNode = require('./core/io/21-httprequest_page'); var httpRequestNode = require('./core/io/21-httprequest_page');
var htmlNode = require('./core/parsers/70-HTML_page'); var htmlNode = require('./core/parsers/70-HTML_page');
var fileinNode = require('./core/storage/50-filein_page');
var nodeCatalog = { var nodeCatalog = {
@ -40,6 +41,8 @@ var nodeCatalog = {
"range": rangeNode, "range": rangeNode,
"httpRequest": httpRequestNode, "httpRequest": httpRequestNode,
"html": htmlNode, "html": htmlNode,
// storage
"filein": fileinNode,
} }
function create(type, id) { function create(type, id) {

View File

@ -28,6 +28,8 @@ var idMap = {
"range": "#palette_node_range", "range": "#palette_node_range",
"httpRequest": "#palette_node_http_request", "httpRequest": "#palette_node_http_request",
"html": "#palette_node_html", "html": "#palette_node_html",
// storage
"filein": "#palette_node_file_in",
}; };
function getId(type) { function getId(type) {

View File

@ -0,0 +1,584 @@
/**
* 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");
var debugTab = require('../../pageobjects/workspace/debugTab_page');
var workspace = require('../../pageobjects/workspace/workspace_page');
var nodeWidth = 200;
var nodeHeight = 100;
var httpNodeRoot = "/api";
// https://cookbook.nodered.org/
describe('cookbook', function() {
beforeEach(function() {
workspace.deleteAllNodes();
});
before(function() {
helper.startServer();
});
after(function() {
helper.stopServer();
});
describe('HTTP endpoints', function () {
it('create an HTTP endpoint', function () {
var httpinNode = workspace.addNode("httpin");
var templateNode = workspace.addNode("template", nodeWidth);
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 2);
httpinNode.edit();
httpinNode.setMethod("get");
httpinNode.setUrl("/hello");
httpinNode.clickOk();
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();
httpinNode.connect(templateNode);
templateNode.connect(httpResponseNode);
// The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight);
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth, nodeHeight);
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight);
httpRequestNode.edit();
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello');
httpRequestNode.setMethod("get");
httpRequestNode.clickOk();
injectNode.connect(httpRequestNode);
httpRequestNode.connect(debugNode);
// The code for confirmation ends here.
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
debugTab.getMessage().indexOf('Hello World!').should.not.eql(-1);
});
it('handle query parameters passed to an HTTP endpoint', function () {
var httpinNode = workspace.addNode("httpin");
var templateNode = workspace.addNode("template", nodeWidth);
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 2);
httpinNode.edit();
httpinNode.setMethod("get");
httpinNode.setUrl("/hello-query");
httpinNode.clickOk();
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();
httpinNode.connect(templateNode);
templateNode.connect(httpResponseNode);
// The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight);
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth, nodeHeight);
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight);
httpRequestNode.edit();
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-query?name=Nick');
httpRequestNode.setMethod("get");
httpRequestNode.clickOk();
injectNode.connect(httpRequestNode);
httpRequestNode.connect(debugNode);
// The code for confirmation ends here.
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1);
});
it('handle url parameters in an HTTP endpoint', function () {
var httpinNode = workspace.addNode("httpin");
var templateNode = workspace.addNode("template", nodeWidth * 2);
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 3);
httpinNode.edit();
httpinNode.setMethod("get");
httpinNode.setUrl("/hello-param/:name");
httpinNode.clickOk();
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();
httpinNode.connect(templateNode);
templateNode.connect(httpResponseNode);
// The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight);
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth, nodeHeight);
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight);
httpRequestNode.edit();
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-param/Dave');
httpRequestNode.setMethod("get");
httpRequestNode.clickOk();
injectNode.connect(httpRequestNode);
httpRequestNode.connect(debugNode);
// The code for confirmation ends here.
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
debugTab.getMessage().indexOf('Hello Dave!').should.not.eql(-1);
});
it('access HTTP request headers', function () {
var httpinNode = workspace.addNode("httpin");
var templateNode = workspace.addNode("template", nodeWidth * 1.5);
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 2.5);
httpinNode.edit();
httpinNode.setMethod("get");
httpinNode.setUrl("/hello-headers");
httpinNode.clickOk();
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();
httpinNode.connect(templateNode);
templateNode.connect(httpResponseNode);
// The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight);
var changeNode = workspace.addNode("change", nodeWidth, nodeHeight);
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth * 2, nodeHeight);
var debugNode = workspace.addNode("debug", nodeWidth * 3, nodeHeight);
changeNode.edit();
changeNode.ruleSet("headers", "msg", "{\"user-agent\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64)\"}", "json");
changeNode.clickOk();
httpRequestNode.edit();
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-headers');
httpRequestNode.setMethod("get");
httpRequestNode.clickOk();
injectNode.connect(changeNode);
changeNode.connect(httpRequestNode);
httpRequestNode.connect(debugNode);
// The code for confirmation ends here.
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
debugTab.getMessage().indexOf('Mozilla').should.not.eql(-1);
});
it('include data captured in another flow', function () {
var injectNodeTimestamp = workspace.addNode("inject");
var changeNodeStore = workspace.addNode("change", nodeWidth);
var httpinNode = workspace.addNode("httpin", 0, nodeHeight);
var changeNodeCopy = workspace.addNode("change", nodeWidth * 2, nodeHeight);
var templateNode = workspace.addNode("template", nodeWidth * 3, nodeHeight);
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 4, nodeHeight);
injectNodeTimestamp.edit();
injectNodeTimestamp.setPayload("date");
injectNodeTimestamp.clickOk();
changeNodeStore.edit();
changeNodeStore.ruleSet("timestamp", "flow", "payload", "msg");
changeNodeStore.clickOk();
injectNodeTimestamp.connect(changeNodeStore);
httpinNode.edit();
httpinNode.setMethod("get");
httpinNode.setUrl("/hello-data");
httpinNode.clickOk();
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();
httpinNode.connect(changeNodeCopy);
changeNodeCopy.connect(templateNode);
templateNode.connect(httpResponseNode);
// The code for confirmation starts from here.
var injectNodeCheck = workspace.addNode("inject", 0, nodeHeight * 2);
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth, nodeHeight * 2);
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight * 2);
httpRequestNode.edit();
httpRequestNode.setMethod("get");
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();
debugTab.clearMessage();
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 () {
var httpinNode = workspace.addNode("httpin");
var templateNode = workspace.addNode("template", nodeWidth);
var changeNode = workspace.addNode("change", nodeWidth * 2);
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 3);
httpinNode.edit();
httpinNode.setMethod("get");
httpinNode.setUrl("/hello-json");
httpinNode.clickOk();
templateNode.edit();
templateNode.setSyntax("mustache");
templateNode.setFormat("handlebars");
templateNode.setTemplate("{ \"Hello\": \"World\" }");
templateNode.clickOk();
changeNode.edit();
changeNode.ruleSet("headers", "msg", "{}", "json", "1");
changeNode.addRule();
changeNode.ruleSet("headers.content-type", "msg", "application/json", "str", "2");
changeNode.clickOk();
httpinNode.connect(templateNode);
templateNode.connect(changeNode);
changeNode.connect(httpResponseNode);
// The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight);
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth, nodeHeight);
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight);
httpRequestNode.edit();
httpRequestNode.setMethod("get");
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-json');
httpRequestNode.clickOk();
debugNode.edit();
debugNode.setTarget("msg", "headers");
debugNode.clickOk();
injectNode.connect(httpRequestNode);
httpRequestNode.connect(debugNode);
// The code for confirmation ends here.
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
var message = debugTab.getMessage();
message[1].indexOf('application/json').should.not.eql(-1);
});
it('serve a local file', function () {
var httpinNode = workspace.addNode("httpin");
var fileinNode = workspace.addNode("filein", nodeWidth);
var changeNode = workspace.addNode("change", nodeWidth * 2, nodeHeight);
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 3.5, nodeHeight);
httpinNode.edit();
httpinNode.setMethod("get");
httpinNode.setUrl("/hello-file");
httpinNode.clickOk();
fileinNode.edit();
fileinNode.setFilename("test/resources/file-in-node/test.txt");
fileinNode.setFormat("");
fileinNode.clickOk();
changeNode.edit();
changeNode.ruleSet("headers", "msg", "{}", "json");
changeNode.addRule();
changeNode.ruleSet("headers.content-type", "msg", "text/plain", "str", "2");
changeNode.clickOk();
httpinNode.connect(fileinNode);
fileinNode.connect(changeNode);
changeNode.connect(httpResponseNode);
// The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight * 2);
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth, nodeHeight * 2);
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight * 2);
httpRequestNode.edit();
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-file');
httpRequestNode.setMethod("get");
httpRequestNode.clickOk();
injectNode.connect(httpRequestNode);
httpRequestNode.connect(debugNode);
// The code for confirmation ends here.
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
debugTab.getMessage().indexOf('Text file').should.not.eql(-1);
});
it('post raw data to a flow', function() {
var httpinNode = workspace.addNode("httpin");
var templateNode = workspace.addNode("template", nodeWidth * 2);
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 3);
httpinNode.edit();
httpinNode.setMethod("post");
httpinNode.setUrl("/hello-raw");
httpinNode.clickOk();
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();
httpinNode.connect(templateNode);
templateNode.connect(httpResponseNode);
// The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight);
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth, nodeHeight);
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight);
injectNode.edit()
injectNode.setPayload("str", "Nick");
injectNode.clickOk();
httpRequestNode.edit();
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-raw');
httpRequestNode.setMethod("post");
httpRequestNode.clickOk();
injectNode.connect(httpRequestNode);
httpRequestNode.connect(debugNode);
// The code for confirmation ends here.
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1);
});
it('post form data to a flow', function () {
var httpinNode = workspace.addNode("httpin");
var templateNode = workspace.addNode("template", nodeWidth * 1.5);
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 2.5);
httpinNode.edit();
httpinNode.setMethod("post");
httpinNode.setUrl("/hello-form");
httpinNode.clickOk();
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();
httpinNode.connect(templateNode);
templateNode.connect(httpResponseNode);
// The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight);
var changeNode = workspace.addNode("change", nodeWidth, nodeHeight);
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth * 2, nodeHeight);
var debugNode = workspace.addNode("debug", nodeWidth * 3, nodeHeight);
injectNode.edit()
injectNode.setPayload("str", "name=Nick");
injectNode.clickOk();
changeNode.edit();
changeNode.ruleSet("headers", "msg", "{\"content-type\":\"application/x-www-form-urlencoded\"}", "json");
changeNode.clickOk();
httpRequestNode.edit();
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-form');
httpRequestNode.setMethod("post");
httpRequestNode.clickOk();
injectNode.connect(changeNode);
changeNode.connect(httpRequestNode);
httpRequestNode.connect(debugNode);
// The code for confirmation ends here.
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1);
});
it('post JSON data to a flow', function() {
var httpinNode = workspace.addNode("httpin");
var templateNode = workspace.addNode("template", nodeWidth * 2);
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 3);
httpinNode.edit();
httpinNode.setMethod("post");
httpinNode.setUrl("/hello-json");
httpinNode.clickOk();
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();
httpinNode.connect(templateNode);
templateNode.connect(httpResponseNode);
// The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight);
var changeNode = workspace.addNode("change", nodeWidth, nodeHeight);
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth * 2, nodeHeight);
var debugNode = workspace.addNode("debug", nodeWidth * 3, nodeHeight);
injectNode.edit()
injectNode.setPayload("json", "{\"name\":\"Nick\"}");
injectNode.clickOk();
changeNode.edit();
changeNode.ruleSet("headers", "msg", "{\"content-type\":\"application/json\"}", "json");
changeNode.clickOk();
httpRequestNode.edit();
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-json');
httpRequestNode.setMethod("post");
httpRequestNode.clickOk();
injectNode.connect(changeNode);
changeNode.connect(httpRequestNode);
httpRequestNode.connect(debugNode);
// The code for confirmation ends here.
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1);
});
it('work with cookies', function () {
this.timeout(60000);
var httpinNodeFormat = workspace.addNode("httpin");
var functionNodeFormat = workspace.addNode("function", nodeWidth * 1.5);
var templateNode = workspace.addNode("template", nodeWidth * 2.5);
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 3.5);
var httpinNodeAdd = workspace.addNode("httpin", 0, nodeHeight);
var functionNodeAdd = workspace.addNode("function", nodeWidth * 1.5, nodeHeight);
var changeNode = workspace.addNode("change", nodeWidth * 2.5, nodeHeight * 1.5);
var httpinNodeClear = workspace.addNode("httpin", 0, nodeHeight * 2);
var functionNodeClear = workspace.addNode("function", nodeWidth * 1.5, nodeHeight * 2);
httpinNodeFormat.edit();
httpinNodeFormat.setMethod("get");
httpinNodeFormat.setUrl("/hello-cookie");
httpinNodeFormat.clickOk();
functionNodeFormat.edit();
functionNodeFormat.setCode("msg.payload = JSON.stringify(msg.req.cookies,null,4);");
functionNodeFormat.clickOk();
templateNode.edit();
templateNode.setSyntax("mustache");
templateNode.setFormat("handlebars");
templateNode.setTemplate("<html>\n<head></head>\n<body>\n<h1>Cookies</h1>\n<p></p><a href=\"hello-cookie/add\">Add a cookie</a> &bull; <a href=\"hello-cookie/clear\">Clear cookies</a></p>\n<pre>{{ payload }}</pre>\n</body>\n</html>");
templateNode.clickOk();
httpinNodeFormat.connect(functionNodeFormat);
functionNodeFormat.connect(templateNode);
templateNode.connect(httpResponseNode);
httpinNodeAdd.edit();
httpinNodeAdd.setMethod("get");
httpinNodeAdd.setUrl("/hello-cookie/add");
httpinNodeAdd.clickOk();
functionNodeAdd.edit();
functionNodeAdd.setCode("msg.cookies = { };\n msg.cookies[\"demo-\"+(Math.floor(Math.random()*1000))] = Date.now();");
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();
httpinNodeAdd.connect(functionNodeAdd);
functionNodeAdd.connect(changeNode);
changeNode.connect(httpResponseNode);
httpinNodeClear.edit();
httpinNodeClear.setMethod("get");
httpinNodeClear.setUrl("/hello-cookie/clear");
httpinNodeClear.clickOk();
functionNodeClear.edit();
functionNodeClear.setCode("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});\n\n");
functionNodeClear.clickOk();
httpinNodeClear.connect(functionNodeClear);
functionNodeClear.connect(changeNode);
workspace.deploy();
// This case cannot be checked since http request node does not transfer cookies when redirected.
});
});
});

View File

@ -59,7 +59,7 @@ describe('cookbook', function() {
debugTab.open(); debugTab.open();
debugTab.clearMessage(); debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.be.equal('"Hello World!"'); debugTab.getMessage().should.eql('"Hello World!"');
}); });
it('delete a message property', function() { it('delete a message property', function() {
@ -79,7 +79,7 @@ describe('cookbook', function() {
debugTab.open(); debugTab.open();
debugTab.clearMessage(); debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.be.equal("undefined"); debugTab.getMessage().should.eql("undefined");
}); });
it('move a message property', function() { it('move a message property', function() {
@ -103,7 +103,7 @@ describe('cookbook', function() {
debugTab.open(); debugTab.open();
debugTab.clearMessage(); debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.be.equal('"Hello"'); debugTab.getMessage().should.eql('"Hello"');
}); });
it('map a property between different numeric ranges', function() { it('map a property between different numeric ranges', function() {
@ -138,11 +138,11 @@ describe('cookbook', function() {
debugTab.open(); debugTab.open();
debugTab.clearMessage(); debugTab.clearMessage();
injectNode1.clickLeftButton(); injectNode1.clickLeftButton();
debugTab.getMessage(1).should.be.equal('0'); debugTab.getMessage(1).should.eql('0');
injectNode2.clickLeftButton(); injectNode2.clickLeftButton();
debugTab.getMessage(2).should.be.equal('2.5024437927663734'); debugTab.getMessage(2).should.eql('2.5024437927663734');
injectNode3.clickLeftButton(); injectNode3.clickLeftButton();
debugTab.getMessage(3).should.be.equal('5'); debugTab.getMessage(3).should.eql('5');
}); });
}); });
@ -160,7 +160,7 @@ describe('cookbook', function() {
debugTab.open(); debugTab.open();
debugTab.clearMessage(); debugTab.clearMessage();
workspace.deploy(); workspace.deploy();
debugTab.getMessage().should.be.equal('"Started!"'); debugTab.getMessage().should.eql('"Started!"');
}); });
it('trigger a flow at regular intervals', function() { it('trigger a flow at regular intervals', function() {
@ -213,7 +213,7 @@ describe('cookbook', function() {
debugTab.open(); debugTab.open();
debugTab.clearMessage(); debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.be.equal('"Node-RED"'); debugTab.getMessage().should.eql('"Node-RED"');
}); });
it('set the URL of a request', function() { it('set the URL of a request', function() {
@ -323,7 +323,7 @@ describe('cookbook', function() {
it('get a parsed JSON response', function() { it('get a parsed JSON response', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var changeNode_setPost = workspace.addNode("change", nodeWidth); var changeNodeSetPost = workspace.addNode("change", nodeWidth);
var httpRequetNode = workspace.addNode("httpRequest", nodeWidth * 2); var httpRequetNode = workspace.addNode("httpRequest", nodeWidth * 2);
var debugNode = workspace.addNode("debug", nodeWidth * 3); var debugNode = workspace.addNode("debug", nodeWidth * 3);
@ -331,9 +331,9 @@ describe('cookbook', function() {
injectNode.setPayload("str", "json-response"); injectNode.setPayload("str", "json-response");
injectNode.clickOk(); injectNode.clickOk();
changeNode_setPost.edit(); changeNodeSetPost.edit();
changeNode_setPost.ruleSet("post", "msg", "payload", "msg"); changeNodeSetPost.ruleSet("post", "msg", "payload", "msg");
changeNode_setPost.clickOk(); changeNodeSetPost.clickOk();
httpRequetNode.edit(); httpRequetNode.edit();
httpRequetNode.setMethod("get"); httpRequetNode.setMethod("get");
@ -346,14 +346,14 @@ describe('cookbook', function() {
debugNode.setTarget("msg", "payload.title"); debugNode.setTarget("msg", "payload.title");
debugNode.clickOk(); debugNode.clickOk();
injectNode.connect(changeNode_setPost); injectNode.connect(changeNodeSetPost);
changeNode_setPost.connect(httpRequetNode); changeNodeSetPost.connect(httpRequetNode);
httpRequetNode.connect(debugNode); httpRequetNode.connect(debugNode);
// The code for confirmation starts from here. // The code for confirmation starts from here.
var httpinNode = workspace.addNode("httpin", 0, nodeHeight); var httpinNode = workspace.addNode("httpin", 0, nodeHeight);
var templateNode = workspace.addNode("template", nodeWidth * 1.5, nodeHeight); var templateNode = workspace.addNode("template", nodeWidth * 1.5, nodeHeight);
var changeNode_setHeader = workspace.addNode("change", nodeWidth * 2.5, nodeHeight); var changeNodeSetHeader = workspace.addNode("change", nodeWidth * 2.5, nodeHeight);
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 3.5, nodeHeight); var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 3.5, nodeHeight);
httpinNode.edit(); httpinNode.edit();
@ -367,13 +367,13 @@ describe('cookbook', function() {
templateNode.setTemplate("{\"title\": \"Hello\"}"); templateNode.setTemplate("{\"title\": \"Hello\"}");
templateNode.clickOk(); templateNode.clickOk();
changeNode_setHeader.edit(); changeNodeSetHeader.edit();
changeNode_setHeader.ruleSet("headers", "msg", "{\"content-type\":\"application/json\"}", "json"); changeNodeSetHeader.ruleSet("headers", "msg", "{\"content-type\":\"application/json\"}", "json");
changeNode_setHeader.clickOk(); changeNodeSetHeader.clickOk();
httpinNode.connect(templateNode); httpinNode.connect(templateNode);
templateNode.connect(changeNode_setHeader); templateNode.connect(changeNodeSetHeader);
changeNode_setHeader.connect(httpResponseNode); changeNodeSetHeader.connect(httpResponseNode);
// The code for confirmation ends here. // The code for confirmation ends here.
workspace.deploy(); workspace.deploy();

View File

@ -0,0 +1 @@
Text file