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

Merge pull request #2464 from kazuhitoyokoi/master-adduitests

Add UI test cases for data formats
This commit is contained in:
Nick O'Leary 2020-02-24 16:20:13 +00:00 committed by GitHub
commit 6d98b93135
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 1090 additions and 470 deletions

View File

@ -15,22 +15,29 @@
**/ **/
var idMap = { var idMap = {
// input // common
"inject": ".red-ui-palette-node[data-palette-type='inject']", "inject": ".red-ui-palette-node[data-palette-type='inject']",
"httpIn": ".red-ui-palette-node[data-palette-type='http in']",
"mqttIn": ".red-ui-palette-node[data-palette-type='mqtt in']",
// output
"debug": ".red-ui-palette-node[data-palette-type='debug']", "debug": ".red-ui-palette-node[data-palette-type='debug']",
"httpResponse": ".red-ui-palette-node[data-palette-type='http response']",
"mqttOut": ".red-ui-palette-node[data-palette-type='mqtt out']",
// function // function
"function": ".red-ui-palette-node[data-palette-type='function']", "function": ".red-ui-palette-node[data-palette-type='function']",
"template": ".red-ui-palette-node[data-palette-type='template']",
"change": ".red-ui-palette-node[data-palette-type='change']", "change": ".red-ui-palette-node[data-palette-type='change']",
"range": ".red-ui-palette-node[data-palette-type='range']", "range": ".red-ui-palette-node[data-palette-type='range']",
"template": ".red-ui-palette-node[data-palette-type='template']",
// network
"mqttIn": ".red-ui-palette-node[data-palette-type='mqtt in']",
"mqttOut": ".red-ui-palette-node[data-palette-type='mqtt out']",
"httpIn": ".red-ui-palette-node[data-palette-type='http in']",
"httpResponse": ".red-ui-palette-node[data-palette-type='http response']",
"httpRequest": ".red-ui-palette-node[data-palette-type='http request']", "httpRequest": ".red-ui-palette-node[data-palette-type='http request']",
// sequence
"join": ".red-ui-palette-node[data-palette-type='join']",
"split": ".red-ui-palette-node[data-palette-type='split']",
// parser
"csv": ".red-ui-palette-node[data-palette-type='csv']",
"html": ".red-ui-palette-node[data-palette-type='html']", "html": ".red-ui-palette-node[data-palette-type='html']",
"json": ".red-ui-palette-node[data-palette-type='json']", "json": ".red-ui-palette-node[data-palette-type='json']",
"xml": ".red-ui-palette-node[data-palette-type='xml']",
"yaml": ".red-ui-palette-node[data-palette-type='yaml']",
// storage // storage
"fileIn": ".red-ui-palette-node[data-palette-type='file in']", "fileIn": ".red-ui-palette-node[data-palette-type='file in']",
}; };

View File

@ -42,7 +42,7 @@ function addNode(type, x, y) {
} }
} }
browser.waitForVisible('#red-ui-palette-search'); browser.waitForVisible('#red-ui-palette-search');
browser.setValue('//*[@id="red-ui-palette-search"]/div/input', type.replace(/([A-Z])/g,' $1').toLowerCase()); browser.setValue('//*[@id="red-ui-palette-search"]/div/form/input', type.replace(/([A-Z])/g, ' $1').toLowerCase());
browser.pause(300); browser.pause(300);
browser.waitForVisible(palette.getId(type)); browser.waitForVisible(palette.getId(type));
browser.moveToObject(palette.getId(type)); browser.moveToObject(palette.getId(type));
@ -66,8 +66,8 @@ function deleteAllNodes() {
function deploy() { function deploy() {
browser.call(function () { browser.call(function () {
return when.promise(function(resolve, reject) { return when.promise(function (resolve, reject) {
events.on("runtime-event", function(event) { events.on("runtime-event", function (event) {
if (event.id === 'runtime-deploy') { if (event.id === 'runtime-deploy') {
events.removeListener("runtime-event", arguments.callee); events.removeListener("runtime-event", arguments.callee);
resolve(); resolve();

View File

@ -14,9 +14,9 @@
* limitations under the License. * limitations under the License.
**/ **/
var util = require("util"); var util = require('util');
var nodePage = require("../../node_page"); var nodePage = require('../../node_page');
function changeNode(id) { function changeNode(id) {
nodePage.call(this, id); nodePage.call(this, id);
@ -85,7 +85,7 @@ changeNode.prototype.ruleMove = function (p, to, index) {
} }
changeNode.prototype.addRule = function () { changeNode.prototype.addRule = function () {
browser.clickWithWait('//*[@id="dialog-form"]/div[3]/div/a'); browser.clickWithWait('//*[@id="dialog-form"]/div[5]/div/a');
} }
module.exports = changeNode; module.exports = changeNode;

View File

@ -0,0 +1,51 @@
/**
* 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 csvNode(id) {
nodePage.call(this, id);
}
util.inherits(csvNode, nodePage);
csvNode.prototype.setColumns = function (columns) {
browser.setValue('#node-input-temp', columns);
}
csvNode.prototype.setSkipLines = function (skip) {
browser.setValue('#node-input-skip', skip);
}
csvNode.prototype.setFirstRow4Names = function (checkbox) {
if (browser.isSelected('#node-input-hdrin') !== checkbox) {
browser.click('#node-input-hdrin');
}
}
csvNode.prototype.setOutput = function (output) {
browser.selectWithWait('#node-input-multi', output);
}
csvNode.prototype.setIncludeRow = function (checkbox) {
if (browser.isSelected('#node-input-hdrout') !== checkbox) {
browser.click('#node-input-hdrout');
}
}
module.exports = csvNode;

View File

@ -14,9 +14,9 @@
* limitations under the License. * limitations under the License.
**/ **/
var util = require("util"); var util = require('util');
var nodePage = require("../../node_page"); var nodePage = require('../../node_page');
function htmlNode(id) { function htmlNode(id) {
nodePage.call(this, id); nodePage.call(this, id);
@ -24,7 +24,7 @@ function htmlNode(id) {
util.inherits(htmlNode, nodePage); util.inherits(htmlNode, nodePage);
htmlNode.prototype.setSelector = function(tag) { htmlNode.prototype.setSelector = function (tag) {
browser.setValue('#node-input-tag', tag); browser.setValue('#node-input-tag', tag);
} }

View File

@ -14,9 +14,9 @@
* limitations under the License. * limitations under the License.
**/ **/
var util = require("util"); var util = require('util');
var nodePage = require("../../node_page"); var nodePage = require('../../node_page');
function jsonNode(id) { function jsonNode(id) {
nodePage.call(this, id); nodePage.call(this, id);
@ -28,8 +28,8 @@ jsonNode.prototype.setAction = function (action) {
browser.setValue('node-input-action', action); browser.setValue('node-input-action', action);
} }
jsonNode.prototype.setProperty = function(property) { jsonNode.prototype.setProperty = function (property) {
browser.setValue('//*[@id="dialog-form"]/div[2]/div/div/input', property); browser.setValue('//*[@id="dialog-form"]/div[4]/div/div[1]/input', property);
} }
module.exports = jsonNode; module.exports = jsonNode;

View File

@ -0,0 +1,35 @@
/**
* 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 xmlNode(id) {
nodePage.call(this, id);
}
util.inherits(xmlNode, nodePage);
xmlNode.prototype.setAction = function (action) {
browser.setValue('node-input-action', action);
}
xmlNode.prototype.setProperty = function (property) {
browser.setValue('//*[@id="dialog-form"]/div[3]/div/div[1]/input', property);
}
module.exports = xmlNode;

View File

@ -0,0 +1,35 @@
/**
* 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 yamlNode(id) {
nodePage.call(this, id);
}
util.inherits(yamlNode, nodePage);
yamlNode.prototype.setAction = function (action) {
browser.setValue('node-input-action', action);
}
yamlNode.prototype.setProperty = function (property) {
browser.setValue('//*[@id="dialog-form"]/div[3]/div/div[1]/input', property);
}
module.exports = yamlNode;

View File

@ -0,0 +1,35 @@
/**
* 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 joinNode(id) {
nodePage.call(this, id);
}
util.inherits(joinNode, nodePage);
module.exports = joinNode;
function joinNode(id) {
nodePage.call(this, id);
}
util.inherits(joinNode, nodePage);
module.exports = joinNode;

View File

@ -25,8 +25,13 @@ var mqttOutNode = require('./core/network/10-mqttout_page');
var httpInNode = require('./core/network/21-httpin_page'); var httpInNode = require('./core/network/21-httpin_page');
var httpResponseNode = require('./core/network/21-httpresponse_page'); var httpResponseNode = require('./core/network/21-httpresponse_page');
var httpRequestNode = require('./core/network/21-httprequest_page'); var httpRequestNode = require('./core/network/21-httprequest_page');
var splitNode = require('./core/sequence/17-split_page');
var joinNode = require('./core/sequence/17-split_page');
var csvNode = require('./core/parsers/70-CSV_page');
var htmlNode = require('./core/parsers/70-HTML_page'); var htmlNode = require('./core/parsers/70-HTML_page');
var jsonNode = require('./core/parsers/70-JSON_page'); var jsonNode = require('./core/parsers/70-JSON_page');
var xmlNode = require('./core/parsers/70-XML_page');
var yamlNode = require('./core/parsers/70-YAML_page');
var fileInNode = require('./core/storage/10-filein_page'); var fileInNode = require('./core/storage/10-filein_page');
var nodeCatalog = { var nodeCatalog = {
@ -44,9 +49,15 @@ var nodeCatalog = {
"httpIn": httpInNode, "httpIn": httpInNode,
"httpResponse": httpResponseNode, "httpResponse": httpResponseNode,
"httpRequest": httpRequestNode, "httpRequest": httpRequestNode,
// sequence
"split": splitNode,
"join": joinNode,
// parser // parser
"csv": csvNode,
"html": htmlNode, "html": htmlNode,
"json": jsonNode, "json": jsonNode,
"xml": xmlNode,
"yaml": yamlNode,
// storage // storage
"fileIn": fileInNode "fileIn": fileInNode
}; };

View File

@ -0,0 +1,364 @@
/**
* 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 when = require('when');
var should = require('should');
var fs = require('fs-extra');
var helper = require('../../editor_helper');
var debugTab = require('../../pageobjects/editor/debugTab_page');
var workspace = require('../../pageobjects/editor/workspace_page');
var specUtil = require('../../pageobjects/util/spec_util_page');
var httpNodeRoot = '/api';
// https://cookbook.nodered.org/
describe('cookbook', function () {
beforeEach(function () {
workspace.init();
});
before(function () {
helper.startServer();
});
after(function () {
helper.stopServer();
});
describe('working with data formats', function () {
it('convert to/from JSON', function () {
var injectNode1 = workspace.addNode('inject');
var jsonNode1 = workspace.addNode('json');
var debugNode1 = workspace.addNode('debug');
injectNode1.edit();
injectNode1.setPayload('str', '{"a":1}');
injectNode1.clickOk();
jsonNode1.edit();
jsonNode1.setProperty('payload');
jsonNode1.clickOk();
injectNode1.connect(jsonNode1);
jsonNode1.connect(debugNode1);
var injectNode2 = workspace.addNode('inject');
var jsonNode2 = workspace.addNode('json');
var debugNode2 = workspace.addNode('debug');
injectNode2.edit();
injectNode2.setPayload('json', '{"a":1}');
injectNode2.clickOk();
jsonNode2.edit();
jsonNode2.setProperty('payload');
jsonNode2.clickOk();
injectNode2.connect(jsonNode2);
jsonNode2.connect(debugNode2);
workspace.deploy();
debugTab.open();
injectNode1.clickLeftButton();
debugTab.getMessage().should.eql('1');
debugTab.clearMessage();
injectNode2.clickLeftButton();
debugTab.getMessage().should.eql('"{"a":1}"');
});
it('convert to/from XML', function () {
var injectNode1 = workspace.addNode('inject', 0);
var templateNode1 = workspace.addNode('template', 200);
var xmlNode1 = workspace.addNode('xml', 400);
var debugNode1 = workspace.addNode('debug', 600);
injectNode1.edit();
injectNode1.setPayload('str', '{"a":1}');
injectNode1.clickOk();
templateNode1.edit();
templateNode1.setFormat('text');
templateNode1.setSyntax('plain');
templateNode1.setTemplate('<note priority="high">'
+ ' <to>Nick</to>'
+ ' <from>Dave</from>'
+ ' <heading>Reminder</heading>'
+ ' <body>Update the website</body>'
+ '</note>');
templateNode1.clickOk();
xmlNode1.edit();
xmlNode1.setProperty('payload');
xmlNode1.clickOk();
injectNode1.connect(templateNode1);
templateNode1.connect(xmlNode1);
xmlNode1.connect(debugNode1);
var injectNode2 = workspace.addNode('inject');
var xmlNode2 = workspace.addNode('xml');
var debugNode2 = workspace.addNode('debug');
injectNode2.edit();
injectNode2.setPayload('json', '{'
+ ' "note": {'
+ ' "$": { "priority": "high" },'
+ ' "to": [ "Nick" ],'
+ ' "from": [ "Dave" ],'
+ ' "heading": [ "Reminder" ],'
+ ' "body": [ "Update the website" ]'
+ ' }'
+ '}');
injectNode2.clickOk();
xmlNode2.edit();
xmlNode2.setProperty('payload');
xmlNode2.clickOk();
injectNode2.connect(xmlNode2);
xmlNode2.connect(debugNode2);
workspace.deploy();
debugTab.open();
injectNode1.clickLeftButton();
debugTab.getMessage().should.eql('object');
debugTab.clearMessage();
injectNode2.clickLeftButton();
debugTab.getMessage().should.eql('"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
+ '<note priority="high">'
+ '<to>Nick</to>'
+ '<from>Dave</from>'
+ '<heading>Reminder</heading>'
+ '<body>Update the website</body>'
+ '</note>"');
});
it('convert to/from YAML', function () {
var injectNode1 = workspace.addNode('inject', 0);
var templateNode1 = workspace.addNode('template', 200);
var yamlNode1 = workspace.addNode('yaml', 400);
var debugNode1 = workspace.addNode('debug', 600);
injectNode1.edit();
injectNode1.setPayload('str', '{"a":1}');
injectNode1.clickOk();
templateNode1.edit();
templateNode1.setFormat('yaml');
templateNode1.setSyntax('plain');
templateNode1.setTemplate('a: 1\n'
+ 'b:\n'
+ ' - 1\n'
+ '- 2\n'
+ '- 3');
templateNode1.clickOk();
yamlNode1.edit();
yamlNode1.setProperty('payload');
yamlNode1.clickOk();
injectNode1.connect(templateNode1);
templateNode1.connect(yamlNode1);
yamlNode1.connect(debugNode1);
var injectNode2 = workspace.addNode('inject');
var yamlNode2 = workspace.addNode('yaml');
var debugNode2 = workspace.addNode('debug');
injectNode2.edit();
injectNode2.setPayload('json', '{"a":1, "b":[1,2,3]}');
injectNode2.clickOk();
yamlNode2.edit();
yamlNode2.setProperty('payload');
yamlNode2.clickOk();
injectNode2.connect(yamlNode2);
yamlNode2.connect(debugNode2);
workspace.deploy();
debugTab.open();
injectNode1.clickLeftButton();
debugTab.getMessage().should.eql([ '1', 'array[3]' ]);
debugTab.clearMessage();
injectNode2.clickLeftButton();
debugTab.getMessage().should.eql('"a: 1↵b:↵ - 1↵ - 2↵ - 3↵"');
});
it('generate CSV output', function () {
var injectNode1 = workspace.addNode('inject', 0);
var changeNode1 = workspace.addNode('change', 200);
var csvNode1 = workspace.addNode('csv', 400);
var debugNode1 = workspace.addNode('debug', 600);
changeNode1.edit();
changeNode1.ruleSet('payload', 'msg', '{'
+ ' "a": $floor(100*$random()),'
+ ' "b": $floor(100*$random()),'
+ ' "c": $floor(100*$random())'
+ '}', 'jsonata');
changeNode1.clickOk();
csvNode1.edit();
csvNode1.setColumns('a,b,c');
csvNode1.clickOk();
injectNode1.connect(changeNode1);
changeNode1.connect(csvNode1);
csvNode1.connect(debugNode1);
var injectNode2 = workspace.addNode('inject', 0, 80);
var changeNode2 = workspace.addNode('change', 200, 80);
var csvNode2 = workspace.addNode('csv', 400, 80);
var debugNode2 = workspace.addNode('debug', 600, 80);
changeNode2.edit();
changeNode2.ruleSet('payload', 'msg', '['
+ ' {'
+ ' "a": $floor(100*$random()),'
+ ' "b": $floor(100*$random()),'
+ ' "c": $floor(100*$random())'
+ ' }, {'
+ ' "a": $floor(100*$random()),'
+ ' "b": $floor(100*$random()),'
+ ' "c": $floor(100*$random())'
+ ' }, {'
+ ' "a": $floor(100*$random()),'
+ ' "b": $floor(100*$random()),'
+ ' "c": $floor(100*$random())'
+ ' }, {'
+ ' "a": $floor(100*$random()),'
+ ' "b": $floor(100*$random()),'
+ ' "c": $floor(100*$random())'
+ ' }'
+ ']', 'jsonata');
changeNode2.clickOk();
csvNode2.edit();
csvNode2.setColumns('a,b,c');
csvNode2.setIncludeRow(true);
csvNode2.clickOk();
injectNode2.connect(changeNode2);
changeNode2.connect(csvNode2);
csvNode2.connect(debugNode2);
workspace.deploy();
debugTab.open();
injectNode1.clickLeftButton();
debugTab.getMessage().should.match(/^"([1-9]?[0-9],){2}[1-9]?[0-9]↵"$/);
debugTab.clearMessage();
injectNode2.clickLeftButton();
debugTab.getMessage().should.match(/^"a,b,c↵(([1-9]?[0-9],){2}[1-9]?[0-9]↵){4}"$/);
});
it('parse CSV input', function () {
var injectNode = workspace.addNode('inject');
var templateNode = workspace.addNode('template');
var csvNode = workspace.addNode('csv');
var debugNode = workspace.addNode('debug');
templateNode.edit();
templateNode.setFormat('handlebars');
templateNode.setSyntax('mustache');
templateNode.setTemplate('# This is some random data\n'
+ 'a,b,c\n'
+ '80,18,2\n'
+ '52,36,10\n'
+ '91,18,61\n'
+ '32,47,65');
templateNode.clickOk();
csvNode.edit();
csvNode.setSkipLines(1);
csvNode.setFirstRow4Names(true);
csvNode.setOutput('mult');
csvNode.clickOk();
injectNode.connect(templateNode);
templateNode.connect(csvNode);
csvNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql([ 'object', 'object', 'object', 'object' ]);
});
it('simple GET request', function () {
var injectNode = workspace.addNode('inject');
var httpRequestNode = workspace.addNode('httpRequest');
var htmlNode = workspace.addNode('html');
var debugNode = workspace.addNode('debug');
httpRequestNode.edit();
httpRequestNode.setMethod('GET');
httpRequestNode.setUrl('https://nodered.org');
httpRequestNode.clickOk();
htmlNode.edit();
htmlNode.setSelector('.node-red-latest-version');
htmlNode.clickOk();
injectNode.connect(httpRequestNode);
httpRequestNode.connect(htmlNode);
htmlNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.match(/^"v[0-9]+\.[0-9]+\.[0-9]"$/);
});
it('split text into one message per line', function () {
var injectNode = workspace.addNode('inject');
var templateNode = workspace.addNode('template');
var splitNode = workspace.addNode('split');
var changeNode = workspace.addNode('change');
var joinNode = workspace.addNode('join');
var debugNode = workspace.addNode('debug');
templateNode.edit();
templateNode.setFormat('handlebars');
templateNode.setSyntax('mustache');
templateNode.setTemplate('one\ntwo\nthree\nfour\nfive');
templateNode.clickOk();
changeNode.edit();
changeNode.ruleSet('payload', 'msg', '(parts.index+1) & ": " & payload', 'jsonata');
changeNode.clickOk();
injectNode.connect(templateNode);
templateNode.connect(splitNode);
splitNode.connect(changeNode);
changeNode.connect(joinNode);
joinNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"1: one↵2: two↵3: three↵4: four↵5: five"');
});
});
});

View File

@ -0,0 +1,81 @@
/**
* 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 when = require('when');
var should = require('should');
var fs = require('fs-extra');
var helper = require('../../editor_helper');
var debugTab = require('../../pageobjects/editor/debugTab_page');
var workspace = require('../../pageobjects/editor/workspace_page');
var specUtil = require('../../pageobjects/util/spec_util_page');
var httpNodeRoot = '/api';
// https://cookbook.nodered.org/
describe('cookbook', function () {
beforeEach(function () {
workspace.init();
});
before(function () {
helper.startServer();
});
after(function () {
helper.stopServer();
});
describe('flow control', function () {
it('trigger a flow whenever Node-RED starts', function () {
var injectNode = workspace.addNode('inject');
var debugNode = workspace.addNode('debug');
injectNode.edit();
injectNode.setPayload('str', 'Started!');
injectNode.setOnce(true);
injectNode.clickOk();
injectNode.connect(debugNode);
debugTab.open();
workspace.deploy();
debugTab.getMessage().should.eql('"Started!"');
});
it('trigger a flow at regular intervals', function () {
var injectNode = workspace.addNode('inject');
var debugNode = workspace.addNode('debug');
injectNode.edit();
injectNode.setRepeat('interval');
injectNode.setRepeatInterval(1);
injectNode.clickOk();
injectNode.connect(debugNode);
workspace.deploy();
debugTab.open();
specUtil.pause(1000);
var t1 = Number(debugTab.getMessage(1));
t1.should.within(1500000000000, 3000000000000);
specUtil.pause(1000);
debugTab.getMessage(2).should.within(t1 + 900, 3000000000000);
});
// skip this case since it needs up to one minite.
it.skip('trigger a flow at a specific time');
});
});

View File

@ -23,16 +23,16 @@ var workspace = require('../../pageobjects/editor/workspace_page');
var httpNodeRoot = "/api"; var httpNodeRoot = "/api";
// https://cookbook.nodered.org/ // https://cookbook.nodered.org/
describe('cookbook', function() { describe('cookbook', function () {
beforeEach(function() { beforeEach(function () {
workspace.init(); workspace.init();
}); });
before(function() { before(function () {
helper.startServer(); helper.startServer();
}); });
after(function() { after(function () {
helper.stopServer(); helper.stopServer();
}); });
@ -359,7 +359,7 @@ describe('cookbook', function() {
debugTab.getMessage().indexOf('Text file').should.not.eql(-1); debugTab.getMessage().indexOf('Text file').should.not.eql(-1);
}); });
it('post raw data to a flow', function() { it('post raw data to a flow', function () {
var httpInNode = workspace.addNode("httpIn"); var httpInNode = workspace.addNode("httpIn");
var templateNode = workspace.addNode("template"); var templateNode = workspace.addNode("template");
var httpResponseNode = workspace.addNode("httpResponse"); var httpResponseNode = workspace.addNode("httpResponse");
@ -383,7 +383,7 @@ describe('cookbook', function() {
var httpRequestNode = workspace.addNode("httpRequest"); var httpRequestNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug"); var debugNode = workspace.addNode("debug");
injectNode.edit() injectNode.edit();
injectNode.setPayload("str", "Nick"); injectNode.setPayload("str", "Nick");
injectNode.clickOk(); injectNode.clickOk();
@ -427,7 +427,7 @@ describe('cookbook', function() {
var httpRequestNode = workspace.addNode("httpRequest"); var httpRequestNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug"); var debugNode = workspace.addNode("debug");
injectNode.edit() injectNode.edit();
injectNode.setPayload("str", "name=Nick"); injectNode.setPayload("str", "name=Nick");
injectNode.clickOk(); injectNode.clickOk();
@ -451,7 +451,7 @@ describe('cookbook', function() {
debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1); debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1);
}); });
it('post JSON data to a flow', function() { it('post JSON data to a flow', function () {
var httpInNode = workspace.addNode("httpIn"); var httpInNode = workspace.addNode("httpIn");
var templateNode = workspace.addNode("template"); var templateNode = workspace.addNode("template");
var httpResponseNode = workspace.addNode("httpResponse"); var httpResponseNode = workspace.addNode("httpResponse");
@ -476,7 +476,7 @@ describe('cookbook', function() {
var httpRequestNode = workspace.addNode("httpRequest"); var httpRequestNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug"); var debugNode = workspace.addNode("debug");
injectNode.edit() injectNode.edit();
injectNode.setPayload("json", '{"name":"Nick"}'); injectNode.setPayload("json", '{"name":"Nick"}');
injectNode.clickOk(); injectNode.clickOk();

View File

@ -0,0 +1,300 @@
/**
* 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 when = require('when');
var should = require('should');
var fs = require('fs-extra');
var helper = require('../../editor_helper');
var debugTab = require('../../pageobjects/editor/debugTab_page');
var workspace = require('../../pageobjects/editor/workspace_page');
var specUtil = require('../../pageobjects/util/spec_util_page');
var httpNodeRoot = '/api';
// https://cookbook.nodered.org/
describe('cookbook', function () {
beforeEach(function () {
workspace.init();
});
before(function () {
helper.startServer();
});
after(function () {
helper.stopServer();
});
describe('HTTP requests', function () {
it('simple get request', function () {
var injectNode = workspace.addNode('inject');
var httpRequestNode = workspace.addNode('httpRequest');
var htmlNode = workspace.addNode('html');
var debugNode = workspace.addNode('debug');
httpRequestNode.edit();
httpRequestNode.setMethod('GET');
httpRequestNode.setUrl(helper.url());
httpRequestNode.clickOk();
htmlNode.edit();
htmlNode.setSelector('title');
htmlNode.clickOk();
injectNode.connect(httpRequestNode);
httpRequestNode.connect(htmlNode);
htmlNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Node-RED"');
});
it('set the URL of a request', function () {
var injectNode = workspace.addNode('inject');
var changeNode = workspace.addNode('change');
var httpRequestNode = workspace.addNode('httpRequest');
var debugNode = workspace.addNode('debug');
injectNode.edit();
injectNode.setPayload('str', helper.url());
injectNode.clickOk();
changeNode.edit();
changeNode.ruleSet('url', 'msg', 'payload', 'msg');
changeNode.clickOk();
injectNode.connect(changeNode);
changeNode.connect(httpRequestNode);
httpRequestNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.containEql('<title>Node-RED</title>');
});
it('set the URL of a request using a template', function () {
var injectNode = workspace.addNode('inject');
var changeNode = workspace.addNode('change');
var httpRequestNode = workspace.addNode('httpRequest');
var debugNode = workspace.addNode('debug');
injectNode.edit();
injectNode.setPayload('str', 'settings');
injectNode.clickOk();
changeNode.edit();
changeNode.ruleSet('query', 'msg', 'payload', 'msg');
changeNode.clickOk();
httpRequestNode.edit();
httpRequestNode.setUrl(helper.url() + '/{{{query}}}');
httpRequestNode.clickOk();
injectNode.connect(changeNode);
changeNode.connect(httpRequestNode);
httpRequestNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.containEql('httpNodeRoot');
});
it('set the query string parameters', function () {
var injectNode = workspace.addNode('inject');
var changeNode = workspace.addNode('change');
var httpRequestNode = workspace.addNode('httpRequest');
var debugNode = workspace.addNode('debug');
injectNode.edit();
injectNode.setPayload('str', 'Nick');
injectNode.clickOk();
changeNode.edit();
changeNode.ruleSet('query', 'msg', 'payload', 'msg');
changeNode.clickOk();
httpRequestNode.edit();
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/set-query?q={{{query}}}');
httpRequestNode.clickOk();
injectNode.connect(changeNode);
changeNode.connect(httpRequestNode);
httpRequestNode.connect(debugNode);
// The code for confirmation starts from here.
var httpInNode = workspace.addNode('httpIn', 0, 200);
var templateNode = workspace.addNode('template');
var httpResponseNode = workspace.addNode('httpResponse');
httpInNode.edit();
httpInNode.setMethod('get');
httpInNode.setUrl('/set-query');
httpInNode.clickOk();
templateNode.edit();
templateNode.setSyntax('mustache');
templateNode.setFormat('handlebars');
templateNode.setTemplate('Hello {{req.query.q}}');
templateNode.clickOk();
httpInNode.connect(templateNode);
templateNode.connect(httpResponseNode);
// The code for confirmation ends here.
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Hello Nick"');
});
it('get a parsed JSON response', function () {
var injectNode = workspace.addNode('inject');
var changeNodeSetPost = workspace.addNode('change');
var httpRequestNode = workspace.addNode('httpRequest');
var debugNode = workspace.addNode('debug');
injectNode.edit();
injectNode.setPayload('str', 'json-response');
injectNode.clickOk();
changeNodeSetPost.edit();
changeNodeSetPost.ruleSet('post', 'msg', 'payload', 'msg');
changeNodeSetPost.clickOk();
httpRequestNode.edit();
httpRequestNode.setMethod('GET');
var url = helper.url() + httpNodeRoot + '/{{post}}';
httpRequestNode.setUrl(url);
httpRequestNode.setReturn('obj');
httpRequestNode.clickOk();
debugNode.edit();
debugNode.setOutput('.title');
debugNode.clickOk();
injectNode.connect(changeNodeSetPost);
changeNodeSetPost.connect(httpRequestNode);
httpRequestNode.connect(debugNode);
// The code for confirmation starts from here.
var httpInNode = workspace.addNode('httpIn', 0, 200);
var templateNode = workspace.addNode('template');
var changeNodeSetHeader = workspace.addNode('change');
var httpResponseNode = workspace.addNode('httpResponse');
httpInNode.edit();
httpInNode.setMethod('get');
httpInNode.setUrl('/json-response');
httpInNode.clickOk();
templateNode.edit();
templateNode.setSyntax('mustache');
templateNode.setFormat('handlebars');
templateNode.setTemplate('{"title": "Hello"}');
templateNode.clickOk();
changeNodeSetHeader.edit();
changeNodeSetHeader.ruleSet('headers', 'msg', '{"content-type":"application/json"}', 'json');
changeNodeSetHeader.clickOk();
httpInNode.connect(templateNode);
templateNode.connect(changeNodeSetHeader);
changeNodeSetHeader.connect(httpResponseNode);
// The code for confirmation ends here.
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Hello"');
});
it('get a binary response', function () {
var injectNode = workspace.addNode('inject');
var httpRequestNode = workspace.addNode('httpRequest');
var debugNode = workspace.addNode('debug');
httpRequestNode.edit();
httpRequestNode.setMethod('GET');
httpRequestNode.setUrl(helper.url() + '/settings');
httpRequestNode.setReturn('bin');
httpRequestNode.clickOk();
injectNode.connect(httpRequestNode);
httpRequestNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql(['123', '34', '104', '116', '116', '112', '78', '111', '100', '101']);
});
it('set a request header', function () {
var injectNode = workspace.addNode('inject');
var functionNode = workspace.addNode('function');
var httpRequestNode = workspace.addNode('httpRequest');
var debugNode = workspace.addNode('debug');
functionNode.edit();
functionNode.setFunction('msg.payload = "data to post";\nreturn msg;');
functionNode.clickOk();
httpRequestNode.edit();
httpRequestNode.setMethod('POST');
var url = helper.url() + httpNodeRoot + '/set-header';
httpRequestNode.setUrl(url);
httpRequestNode.clickOk();
injectNode.connect(functionNode);
functionNode.connect(httpRequestNode);
httpRequestNode.connect(debugNode);
// The code for confirmation starts from here.
var httpInNode = workspace.addNode('httpIn', 0, 200);
var templateNode = workspace.addNode('template');
var httpResponseNode = workspace.addNode('httpResponse');
httpInNode.edit();
httpInNode.setMethod('post');
httpInNode.setUrl('/set-header');
httpInNode.clickOk();
templateNode.edit();
templateNode.setSyntax('mustache');
templateNode.setFormat('handlebars');
templateNode.setTemplate('{{ payload }}');
templateNode.clickOk();
httpInNode.connect(templateNode);
templateNode.connect(httpResponseNode);
// The code for confirmation ends here.
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"data to post"');
});
});
});

View File

@ -0,0 +1,142 @@
/**
* 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 when = require('when');
var should = require('should');
var fs = require('fs-extra');
var helper = require('../../editor_helper');
var debugTab = require('../../pageobjects/editor/debugTab_page');
var workspace = require('../../pageobjects/editor/workspace_page');
var specUtil = require('../../pageobjects/util/spec_util_page');
var httpNodeRoot = '/api';
// https://cookbook.nodered.org/
describe('cookbook', function () {
beforeEach(function () {
workspace.init();
});
before(function () {
helper.startServer();
});
after(function () {
helper.stopServer();
});
describe('messages', function () {
it('set a message property to a fixed value', function () {
var injectNode = workspace.addNode('inject');
var changeNode = workspace.addNode('change');
var debugNode = workspace.addNode('debug');
changeNode.edit();
changeNode.ruleSet('payload', 'msg', 'Hello World!');
changeNode.clickOk();
injectNode.connect(changeNode);
changeNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Hello World!"');
});
it('delete a message property', function () {
var injectNode = workspace.addNode('inject');
var changeNode = workspace.addNode('change');
var debugNode = workspace.addNode('debug');
changeNode.edit();
changeNode.ruleDelete();
changeNode.clickOk();
injectNode.connect(changeNode);
changeNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('undefined');
});
it('move a message property', function () {
var injectNode = workspace.addNode('inject');
var changeNode = workspace.addNode('change');
var debugNode = workspace.addNode('debug');
injectNode.edit();
injectNode.setTopic('Hello');
injectNode.clickOk();
changeNode.edit();
changeNode.ruleMove('topic', 'payload');
changeNode.clickOk();
injectNode.connect(changeNode);
changeNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Hello"');
});
it('map a property between different numeric ranges', function () {
var injectNode1 = workspace.addNode('inject');
var injectNode2 = workspace.addNode('inject', 0, 100);
var injectNode3 = workspace.addNode('inject', 0, 200);
var rangeNode = workspace.addNode('range', 200, 100);
var debugNode = workspace.addNode('debug', 400);
injectNode1.edit();
injectNode1.setPayload('num', 0);
injectNode1.clickOk();
injectNode2.edit();
injectNode2.setPayload('num', 512);
injectNode2.clickOk();
injectNode3.edit();
injectNode3.setPayload('num', 1023);
injectNode3.clickOk();
rangeNode.edit();
rangeNode.setAction('clamp');
rangeNode.setRange(0, 1023, 0, 5);
rangeNode.clickOk();
injectNode1.connect(rangeNode);
injectNode2.connect(rangeNode);
injectNode3.connect(rangeNode);
rangeNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode1.clickLeftButton();
debugTab.getMessage(1).should.eql('0');
injectNode2.clickLeftButton();
debugTab.getMessage(2).should.eql('2.5024437927663734');
injectNode3.clickLeftButton();
debugTab.getMessage(3).should.eql('5');
});
});
});

View File

@ -1,441 +0,0 @@
/**
* 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 when = require('when');
var should = require("should");
var fs = require('fs-extra');
var helper = require("../../editor_helper");
var debugTab = require('../../pageobjects/editor/debugTab_page');
var workspace = require('../../pageobjects/editor/workspace_page');
var specUtil = require('../../pageobjects/util/spec_util_page');
var httpNodeRoot = "/api";
// https://cookbook.nodered.org/
describe('cookbook', function() {
beforeEach(function() {
workspace.init();
});
before(function() {
helper.startServer();
});
after(function() {
helper.stopServer();
});
describe('messages', function() {
it('set a message property to a fixed value', function() {
var injectNode = workspace.addNode("inject");
var changeNode = workspace.addNode("change");
var debugNode = workspace.addNode("debug");
changeNode.edit();
changeNode.ruleSet("payload", "msg", "Hello World!");
changeNode.clickOk();
injectNode.connect(changeNode);
changeNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Hello World!"');
});
it('delete a message property', function() {
var injectNode = workspace.addNode("inject");
var changeNode = workspace.addNode("change");
var debugNode = workspace.addNode("debug");
changeNode.edit();
changeNode.ruleDelete();
changeNode.clickOk();
injectNode.connect(changeNode);
changeNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql("undefined");
});
it('move a message property', function() {
var injectNode = workspace.addNode("inject");
var changeNode = workspace.addNode("change");
var debugNode = workspace.addNode("debug");
injectNode.edit();
injectNode.setTopic("Hello");
injectNode.clickOk();
changeNode.edit();
changeNode.ruleMove("topic", "payload");
changeNode.clickOk();
injectNode.connect(changeNode);
changeNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Hello"');
});
it('map a property between different numeric ranges', function() {
var injectNode1 = workspace.addNode("inject");
var injectNode2 = workspace.addNode("inject", 0, 100);
var injectNode3 = workspace.addNode("inject", 0, 200);
var rangeNode = workspace.addNode("range", 200, 100);
var debugNode = workspace.addNode("debug", 400);
injectNode1.edit();
injectNode1.setPayload("num", 0);
injectNode1.clickOk();
injectNode2.edit();
injectNode2.setPayload("num", 512);
injectNode2.clickOk();
injectNode3.edit();
injectNode3.setPayload("num", 1023);
injectNode3.clickOk();
rangeNode.edit();
rangeNode.setAction("clamp");
rangeNode.setRange(0, 1023, 0, 5);
rangeNode.clickOk();
injectNode1.connect(rangeNode);
injectNode2.connect(rangeNode);
injectNode3.connect(rangeNode);
rangeNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode1.clickLeftButton();
debugTab.getMessage(1).should.eql('0');
injectNode2.clickLeftButton();
debugTab.getMessage(2).should.eql('2.5024437927663734');
injectNode3.clickLeftButton();
debugTab.getMessage(3).should.eql('5');
});
});
describe('flow control', function() {
it('trigger a flow whenever Node-RED starts', function() {
var injectNode = workspace.addNode("inject");
var debugNode = workspace.addNode("debug");
injectNode.edit();
injectNode.setPayload("str", "Started!")
injectNode.setOnce(true);
injectNode.clickOk();
injectNode.connect(debugNode);
debugTab.open();
workspace.deploy();
debugTab.getMessage().should.eql('"Started!"');
});
it('trigger a flow at regular intervals', function() {
var injectNode = workspace.addNode("inject");
var debugNode = workspace.addNode("debug");
injectNode.edit();
injectNode.setRepeat("interval");
injectNode.setRepeatInterval(1);
injectNode.clickOk();
injectNode.connect(debugNode);
workspace.deploy();
debugTab.open();
specUtil.pause(1000);
var t1 = Number(debugTab.getMessage(1));
t1.should.within(1500000000000, 3000000000000);
specUtil.pause(1000);
debugTab.getMessage(2).should.within(t1 + 900, 3000000000000);
});
// skip this case since it needs up to one minite.
it.skip('trigger a flow at a specific time');
});
describe('HTTP requests', function() {
it('simple get request', function() {
var injectNode = workspace.addNode("inject");
var httpRequetNode = workspace.addNode("httpRequest");
var htmlNode = workspace.addNode("html");
var debugNode = workspace.addNode("debug");
httpRequetNode.edit();
httpRequetNode.setMethod("GET");
httpRequetNode.setUrl(helper.url());
httpRequetNode.clickOk();
htmlNode.edit();
htmlNode.setSelector("title");
htmlNode.clickOk();
injectNode.connect(httpRequetNode);
httpRequetNode.connect(htmlNode);
htmlNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Node-RED"');
});
it('set the URL of a request', function() {
var injectNode = workspace.addNode("inject");
var changeNode = workspace.addNode("change");
var httpRequetNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug");
injectNode.edit();
injectNode.setPayload("str", helper.url());
injectNode.clickOk();
changeNode.edit();
changeNode.ruleSet("url", "msg", "payload", "msg");
changeNode.clickOk();
injectNode.connect(changeNode);
changeNode.connect(httpRequetNode);
httpRequetNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.containEql('<title>Node-RED</title>');
});
it('set the URL of a request using a template', function() {
var injectNode = workspace.addNode("inject");
var changeNode = workspace.addNode("change");
var httpRequetNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug");
injectNode.edit();
injectNode.setPayload("str", 'settings');
injectNode.clickOk();
changeNode.edit();
changeNode.ruleSet("query", "msg", "payload", "msg");
changeNode.clickOk();
httpRequetNode.edit();
httpRequetNode.setUrl(helper.url() + "/{{{query}}}");
httpRequetNode.clickOk();
injectNode.connect(changeNode);
changeNode.connect(httpRequetNode);
httpRequetNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.containEql('httpNodeRoot');
});
it('set the query string parameters', function() {
var injectNode = workspace.addNode("inject");
var changeNode = workspace.addNode("change");
var httpRequetNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug");
injectNode.edit();
injectNode.setPayload("str", 'Nick');
injectNode.clickOk();
changeNode.edit();
changeNode.ruleSet("query", "msg", "payload", "msg");
changeNode.clickOk();
httpRequetNode.edit();
httpRequetNode.setUrl(helper.url() + httpNodeRoot + '/set-query?q={{{query}}}');
httpRequetNode.clickOk();
injectNode.connect(changeNode);
changeNode.connect(httpRequetNode);
httpRequetNode.connect(debugNode);
// The code for confirmation starts from here.
var httpInNode = workspace.addNode("httpIn", 0, 200);
var templateNode = workspace.addNode("template");
var httpResponseNode = workspace.addNode("httpResponse");
httpInNode.edit();
httpInNode.setMethod("get");
httpInNode.setUrl("/set-query");
httpInNode.clickOk();
templateNode.edit();
templateNode.setSyntax("mustache");
templateNode.setFormat("handlebars");
templateNode.setTemplate("Hello {{req.query.q}}");
templateNode.clickOk();
httpInNode.connect(templateNode);
templateNode.connect(httpResponseNode);
// The code for confirmation ends here.
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Hello Nick"');
});
it('get a parsed JSON response', function() {
var injectNode = workspace.addNode("inject");
var changeNodeSetPost = workspace.addNode("change");
var httpRequetNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug");
injectNode.edit();
injectNode.setPayload("str", "json-response");
injectNode.clickOk();
changeNodeSetPost.edit();
changeNodeSetPost.ruleSet("post", "msg", "payload", "msg");
changeNodeSetPost.clickOk();
httpRequetNode.edit();
httpRequetNode.setMethod("GET");
var url = helper.url() + httpNodeRoot + "/{{post}}";
httpRequetNode.setUrl(url);
httpRequetNode.setReturn("obj");
httpRequetNode.clickOk();
debugNode.edit();
debugNode.setOutput(".title");
debugNode.clickOk();
injectNode.connect(changeNodeSetPost);
changeNodeSetPost.connect(httpRequetNode);
httpRequetNode.connect(debugNode);
// The code for confirmation starts from here.
var httpInNode = workspace.addNode("httpIn", 0, 200);
var templateNode = workspace.addNode("template");
var changeNodeSetHeader = workspace.addNode("change");
var httpResponseNode = workspace.addNode("httpResponse");
httpInNode.edit();
httpInNode.setMethod("get");
httpInNode.setUrl("/json-response");
httpInNode.clickOk();
templateNode.edit();
templateNode.setSyntax("mustache");
templateNode.setFormat("handlebars");
templateNode.setTemplate('{"title": "Hello"}');
templateNode.clickOk();
changeNodeSetHeader.edit();
changeNodeSetHeader.ruleSet("headers", "msg", '{"content-type":"application/json"}', "json");
changeNodeSetHeader.clickOk();
httpInNode.connect(templateNode);
templateNode.connect(changeNodeSetHeader);
changeNodeSetHeader.connect(httpResponseNode);
// The code for confirmation ends here.
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Hello"');
});
it('get a binary response', function() {
var injectNode = workspace.addNode("inject");
var httpRequetNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug");
httpRequetNode.edit();
httpRequetNode.setMethod("GET");
httpRequetNode.setUrl(helper.url() + "/settings");
httpRequetNode.setReturn("bin");
httpRequetNode.clickOk();
injectNode.connect(httpRequetNode);
httpRequetNode.connect(debugNode);
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql(['123', '34', '104', '116', '116', '112', '78', '111', '100', '101']);
});
it('set a request header', function() {
var injectNode = workspace.addNode("inject");
var functionNode = workspace.addNode("function");
var httpRequetNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug");
functionNode.edit();
functionNode.setFunction('msg.payload = "data to post";\nreturn msg;');
functionNode.clickOk();
httpRequetNode.edit();
httpRequetNode.setMethod("POST");
var url = helper.url() + httpNodeRoot + "/set-header";
httpRequetNode.setUrl(url);
httpRequetNode.clickOk();
injectNode.connect(functionNode);
functionNode.connect(httpRequetNode);
httpRequetNode.connect(debugNode);
// The code for confirmation starts from here.
var httpInNode = workspace.addNode("httpIn", 0, 200);
var templateNode = workspace.addNode("template");
var httpResponseNode = workspace.addNode("httpResponse");
httpInNode.edit();
httpInNode.setMethod("post");
httpInNode.setUrl("/set-header");
httpInNode.clickOk();
templateNode.edit();
templateNode.setSyntax("mustache");
templateNode.setFormat("handlebars");
templateNode.setTemplate("{{ payload }}");
templateNode.clickOk();
httpInNode.connect(templateNode);
templateNode.connect(httpResponseNode);
// The code for confirmation ends here.
workspace.deploy();
debugTab.open();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"data to post"');
});
});
});