Merge tag '1.2.7' into release/1.2.7

This commit is contained in:
martinb
2021-01-14 15:46:22 +01:00
88 changed files with 5212 additions and 124 deletions

View File

@@ -261,15 +261,15 @@ describe('CSV node', function() {
var n2 = helper.getNode("n2");
var c = 0;
n2.on("input", function(msg) {
if (c == 0) {
if (c == 0) {
c = 1;
msg.should.have.property('payload', { a: "with,an", b: "odd,number", c: "ofquotes\n" });
check_parts(msg, 0, 1);
}
else {
else {
msg.should.have.property('payload', { a: "this is", b: "a normal", c: "line" });
check_parts(msg, 0, 1);
done();
done();
}
});
var testString = '"with,a"n,odd","num"ber","of"qu"ot"es"'+String.fromCharCode(10);
@@ -287,15 +287,15 @@ describe('CSV node', function() {
var c = 0;
n2.on("input", function(msg) {
//console.log(msg)
if (c == 0) {
if (c == 0) {
c = 1;
msg.should.have.property('payload', { a: "with,an", b: "odd,number", c: "ofquotes\nthis is,a normal,line" });
check_parts(msg, 0, 1);
}
else {
else {
msg.should.have.property('payload', { a: "this is", b: "another", c: "line" });
check_parts(msg, 0, 1);
done();
done();
}
});
var testString = '"with,a"n,odd","num"ber","of"qu"ot"es"'+String.fromCharCode(10)+'"this is","a normal","line"'+String.fromCharCode(10);
@@ -555,14 +555,68 @@ describe('CSV node', function() {
});
it('should convert an array of objects to a multi-line csv', function(done) {
var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", wires:[["n2"]] },
var flow = [ { id:"n1", type:"csv", temp:"a,d,c,b", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(csvNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('payload', '4,3,2,1\n1,2,3,4\n');
msg.should.have.property('payload', '4,1,2,3\n1,4,3,2\n');
done();
}
catch(e) { done(e); }
});
var testJson = [{ d: 1, b: 3, c: 2, a: 4 },{d:4,a:1,c:3,b:2}];
n1.emit("input", {payload:testJson});
});
});
it('should convert an array of objects to a multi-line csv and add a header', function(done) {
var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", hdrout:"all", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(csvNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('payload', 'a,b,c,d\n4,3,2,1\n1,2,3,4\n');
done();
}
catch(e) { done(e); }
});
var testJson = [{ d: 1, b: 3, c: 2, a: 4 },{d:4,a:1,c:3,b:2}];
n1.emit("input", {payload:testJson});
});
});
it('should convert an array of objects to a multi-line csv without a template', function(done) {
var flow = [ { id:"n1", type:"csv", temp:"", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(csvNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('payload', '1,3,2,4\n4,2,3,1\n');
done();
}
catch(e) { done(e); }
});
var testJson = [{ d: 1, b: 3, c: 2, a: 4 },{d:4,a:1,c:3,b:2}];
n1.emit("input", {payload:testJson});
});
});
it('should convert an array of objects to a multi-line csv without a template and with a header', function(done) {
var flow = [ { id:"n1", type:"csv", temp:"", hdrout:"all", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(csvNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('payload', 'd,b,c,a\n1,3,2,4\n4,2,3,1\n');
done();
}
catch(e) { done(e); }

View File

@@ -143,4 +143,19 @@ describe("api/editor/theme", function () {
settings.projects.should.have.a.property("enabled", false);
});
it("test explicit userMenu set to true in theme setting", function () {
theme.init({
editorTheme: {
userMenu: true,
}
});
theme.app();
var settings = theme.settings();
settings.should.have.a.property("userMenu");
settings.userMenu.should.be.eql(true);
});
});

View File

@@ -18,11 +18,9 @@ var should = require("should");
var sinon = require("sinon");
var request = require("supertest");
var express = require("express");
var when = require("when");
var fs = require("fs");
var path = require("path");
var NR_TEST_UTILS = require("nr-test-utils");
const auth = require("basic-auth");
var api = NR_TEST_UTILS.require("@node-red/editor-api");
@@ -96,4 +94,89 @@ describe("api/index", function() {
request(api.httpAdmin).get("/auth/login").expect(200).end(done)
})
});
describe('initialises api with admin middleware', function(done) {
it('ignores non-function values',function(done) {
api.init({ httpAdminRoot: true, httpAdminMiddleware: undefined },{},{},{});
const middlewareFound = api.httpAdmin._router.stack.filter((layer) => layer.name === 'testMiddleware')
should(middlewareFound).be.empty();
done();
});
it('only accepts functions as middleware',function(done) {
const testMiddleware = function(req, res, next){ next(); };
api.init({ httpAdminRoot: true, httpAdminMiddleware: testMiddleware },{},{},{});
const middlewareFound = api.httpAdmin._router.stack.filter((layer) => layer.name === 'testMiddleware')
should(middlewareFound).be.length(1);
done();
});
});
describe('initialises api with authentication enabled', function(done) {
it('enables an oauth/openID based authentication mechanism',function(done) {
const stub = sinon.stub(apiAuth, 'genericStrategy', function(){});
const adminAuth = { type: 'strategy', strategy: {} }
api.init({ httpAdminRoot: true, adminAuth },{},{},{});
should(stub.called).be.ok();
stub.restore();
done();
});
it('enables password protection',function(done) {
const adminAuth = { type: 'credentials' }
api.init({ httpAdminRoot: true, adminAuth },{},{},{});
// is the name ("initialize") of the passport middleware present
const middlewareFound = api.httpAdmin._router.stack.filter((layer) => layer.name === 'initialize')
should(middlewareFound).be.length(1);
done();
});
});
describe('initialises api with custom cors config', function (done) {
const httpAdminCors = {
origin: "*",
methods: "GET,PUT,POST,DELETE"
};
it('uses default cors middleware when user settings absent', function(done){
api.init({ httpAdminRoot: true }, {}, {}, {});
const middlewareFound = api.httpAdmin._router.stack.filter((layer) => layer.name === 'corsMiddleware')
should(middlewareFound).be.length(1);
done();
})
it('enables custom cors middleware when settings present', function(done){
api.init({ httpAdminRoot: true, httpAdminCors }, {}, {}, {});
const middlewareFound = api.httpAdmin._router.stack.filter((layer) => layer.name === 'corsMiddleware')
should(middlewareFound).be.length(2);
done();
})
});
describe('editor start', function (done) {
it('cannot be started when editor is disabled', function (done) {
const stub = sinon.stub(apiEditor, 'start', function () {
return Promise.resolve(true);
});
api.init({ httpAdminRoot: true, disableEditor: true }, {}, {}, {});
should(api.start()).resolvedWith(true);
stub.restore();
done();
});
it('can be started when editor enabled', function (done) {
const stub = sinon.stub(apiEditor, 'start');
api.init({ httpAdminRoot: true, disableEditor: false }, {}, {}, {});
api.start();
should(stub.called).be.true();
stub.restore();
done();
});
});
});

View File

@@ -211,6 +211,82 @@ describe("runtime-api/comms", function() {
});
}).catch(done);
})
it('retains non-blank status message',function(done){
eventHandlers['node-status']({
id: "node1234",
status: {text:"hello"}
})
messages.should.have.length(0);
comms.addConnection({client: clientConnection}).then(function() {
return comms.subscribe({client: clientConnection, topic: "status/#"}).then(function() {
messages.should.have.length(1);
messages[0].should.have.property("topic","status/node1234");
messages[0].should.have.property("data",{text:"hello", fill: undefined, shape: undefined});
done();
});
}).catch(done);
})
it('does not retain blank status message',function(done){
eventHandlers['node-status']({
id: "node1234",
status: {}
})
messages.should.have.length(0);
comms.addConnection({client: clientConnection}).then(function() {
return comms.subscribe({client: clientConnection, topic: "status/#"}).then(function() {
messages.should.have.length(0);
done();
});
}).catch(done);
})
it('does not send blank status if first status',function(done){
messages.should.have.length(0);
comms.addConnection({client: clientConnection}).then(function() {
return comms.subscribe({client: clientConnection, topic: "status/#"}).then(function() {
eventHandlers['node-status']({
id: "node5678",
status: {}
})
messages.should.have.length(0);
done()
})
}).catch(done);
});
it('sends blank status if replacing retained',function(done){
eventHandlers['node-status']({
id: "node5678",
status: {text:"hello"}
})
messages.should.have.length(0);
comms.addConnection({client: clientConnection}).then(function() {
return comms.subscribe({client: clientConnection, topic: "status/#"}).then(function() {
messages.should.have.length(1);
eventHandlers['node-status']({
id: "node5678",
status: {}
})
messages.should.have.length(2);
done()
})
}).catch(done);
});
it('does not retain initial status blank message',function(done){
eventHandlers['node-status']({
id: "my-event",
status: {}
})
messages.should.have.length(0);
comms.addConnection({client: clientConnection}).then(function() {
return comms.subscribe({client: clientConnection, topic: "my-event"}).then(function() {
messages.should.have.length(1);
messages[0].should.have.property("topic","my-event");
messages[0].should.have.property("data","my-payload");
done();
});
}).catch(done);
})
it('retained messages get cleared',function(done) {
eventHandlers['comms']({
topic: "my-event",