2015-10-11 21:37:11 +02:00
|
|
|
/**
|
2017-01-11 16:24:33 +01:00
|
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
2015-10-11 21:37:11 +02:00
|
|
|
*
|
|
|
|
* 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 sinon = require("sinon");
|
|
|
|
var when = require("when");
|
|
|
|
var clone = require("clone");
|
2015-11-12 08:56:23 +01:00
|
|
|
var flows = require("../../../../../red/runtime/nodes/flows");
|
|
|
|
var RedNode = require("../../../../../red/runtime/nodes/Node");
|
|
|
|
var RED = require("../../../../../red/runtime/nodes");
|
|
|
|
var events = require("../../../../../red/runtime/events");
|
|
|
|
var credentials = require("../../../../../red/runtime/nodes/credentials");
|
2018-04-26 13:32:05 +02:00
|
|
|
var typeRegistry = require("../../../../../red/runtime-registry");
|
2015-11-12 08:56:23 +01:00
|
|
|
var Flow = require("../../../../../red/runtime/nodes/flows/Flow");
|
2015-10-11 21:37:11 +02:00
|
|
|
|
|
|
|
describe('flows/index', function() {
|
|
|
|
|
|
|
|
var storage;
|
2015-11-02 16:38:16 +01:00
|
|
|
var eventsOn;
|
2015-10-11 21:37:11 +02:00
|
|
|
var credentialsClean;
|
|
|
|
var credentialsLoad;
|
|
|
|
|
|
|
|
var flowCreate;
|
|
|
|
var getType;
|
|
|
|
|
2018-04-23 15:24:51 +02:00
|
|
|
var mockLog = {
|
|
|
|
log: sinon.stub(),
|
|
|
|
debug: sinon.stub(),
|
|
|
|
trace: sinon.stub(),
|
|
|
|
warn: sinon.stub(),
|
|
|
|
info: sinon.stub(),
|
|
|
|
metric: sinon.stub(),
|
|
|
|
_: function() { return "abc"}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-11 21:37:11 +02:00
|
|
|
before(function() {
|
|
|
|
getType = sinon.stub(typeRegistry,"get",function(type) {
|
2015-11-02 16:38:16 +01:00
|
|
|
return type.indexOf('missing') === -1;
|
2015-10-11 21:37:11 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
after(function() {
|
|
|
|
getType.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
beforeEach(function() {
|
2015-11-02 16:38:16 +01:00
|
|
|
eventsOn = sinon.spy(events,"on");
|
2015-10-11 21:37:11 +02:00
|
|
|
credentialsClean = sinon.stub(credentials,"clean",function(conf) {
|
2016-09-21 22:58:50 +02:00
|
|
|
conf.forEach(function(n) {
|
|
|
|
delete n.credentials;
|
|
|
|
});
|
2015-10-11 21:37:11 +02:00
|
|
|
return when.resolve();
|
|
|
|
});
|
|
|
|
credentialsLoad = sinon.stub(credentials,"load",function() {
|
|
|
|
return when.resolve();
|
|
|
|
});
|
|
|
|
flowCreate = sinon.stub(Flow,"create",function(global, flow) {
|
|
|
|
var id;
|
|
|
|
if (typeof flow === 'undefined') {
|
|
|
|
flow = global;
|
|
|
|
id = '_GLOBAL_';
|
|
|
|
} else {
|
|
|
|
id = flow.id;
|
|
|
|
}
|
|
|
|
flowCreate.flows[id] = {
|
2015-11-02 16:38:16 +01:00
|
|
|
flow: flow,
|
|
|
|
global: global,
|
2015-10-11 21:37:11 +02:00
|
|
|
start: sinon.spy(),
|
|
|
|
update: sinon.spy(),
|
2015-11-02 16:38:16 +01:00
|
|
|
stop: sinon.spy(),
|
|
|
|
getActiveNodes: function() {
|
|
|
|
return flow.nodes||{};
|
|
|
|
},
|
|
|
|
handleError: sinon.spy(),
|
|
|
|
handleStatus: sinon.spy()
|
|
|
|
|
2015-10-11 21:37:11 +02:00
|
|
|
}
|
|
|
|
return flowCreate.flows[id];
|
|
|
|
});
|
|
|
|
flowCreate.flows = {};
|
|
|
|
|
|
|
|
storage = {
|
|
|
|
saveFlows: function(conf) {
|
|
|
|
storage.conf = conf;
|
|
|
|
return when.resolve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-11-02 16:38:16 +01:00
|
|
|
afterEach(function(done) {
|
2015-10-11 21:37:11 +02:00
|
|
|
eventsOn.restore();
|
|
|
|
credentialsClean.restore();
|
|
|
|
credentialsLoad.restore();
|
|
|
|
flowCreate.restore();
|
2015-11-02 16:38:16 +01:00
|
|
|
|
|
|
|
flows.stopFlows().then(done);
|
|
|
|
|
2015-10-11 21:37:11 +02:00
|
|
|
});
|
2015-11-02 16:38:16 +01:00
|
|
|
// describe('#init',function() {
|
|
|
|
// it('registers the type-registered handler', function() {
|
|
|
|
// flows.init({},{});
|
2016-10-10 14:27:43 +02:00
|
|
|
// eventsOn.calledOnce.should.be.true();
|
2015-11-02 16:38:16 +01:00
|
|
|
// });
|
|
|
|
// });
|
2015-10-11 21:37:11 +02:00
|
|
|
|
|
|
|
describe('#setFlows', function() {
|
|
|
|
it('sets the full flow', function(done) {
|
|
|
|
var originalConfig = [
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
|
|
|
{id:"t1",type:"tab"}
|
|
|
|
];
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:storage});
|
2015-10-11 21:37:11 +02:00
|
|
|
flows.setFlows(originalConfig).then(function() {
|
2016-10-10 14:27:43 +02:00
|
|
|
credentialsClean.called.should.be.true();
|
|
|
|
storage.hasOwnProperty('conf').should.be.true();
|
2016-10-09 23:02:24 +02:00
|
|
|
flows.getFlows().flows.should.eql(originalConfig);
|
2015-10-11 21:37:11 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2016-10-09 23:02:24 +02:00
|
|
|
it('loads the full flow for type load', function(done) {
|
2015-10-11 21:37:11 +02:00
|
|
|
var originalConfig = [
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
|
|
|
{id:"t1",type:"tab"}
|
|
|
|
];
|
2016-10-09 23:02:24 +02:00
|
|
|
var loadStorage = {
|
|
|
|
saveFlows: function(conf) {
|
|
|
|
loadStorage.conf = conf;
|
|
|
|
return when.resolve(456);
|
|
|
|
},
|
|
|
|
getFlows: function() {
|
|
|
|
return when.resolve({flows:originalConfig,rev:123})
|
|
|
|
}
|
|
|
|
}
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:loadStorage});
|
2015-10-11 21:37:11 +02:00
|
|
|
flows.setFlows(originalConfig,"load").then(function() {
|
2016-10-10 14:27:43 +02:00
|
|
|
credentialsClean.called.should.be.false();
|
2015-10-11 21:37:11 +02:00
|
|
|
// 'load' type does not trigger a save
|
2016-10-10 14:27:43 +02:00
|
|
|
loadStorage.hasOwnProperty('conf').should.be.false();
|
2016-10-09 23:02:24 +02:00
|
|
|
flows.getFlows().flows.should.eql(originalConfig);
|
2015-10-11 21:37:11 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('extracts credentials from the full flow', function(done) {
|
|
|
|
var originalConfig = [
|
2016-09-21 22:58:50 +02:00
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[],credentials:{"a":1}},
|
2015-10-11 21:37:11 +02:00
|
|
|
{id:"t1",type:"tab"}
|
|
|
|
];
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:storage});
|
2015-10-11 21:37:11 +02:00
|
|
|
flows.setFlows(originalConfig).then(function() {
|
2016-10-10 14:27:43 +02:00
|
|
|
credentialsClean.called.should.be.true();
|
|
|
|
storage.hasOwnProperty('conf').should.be.true();
|
2015-10-11 21:37:11 +02:00
|
|
|
var cleanedFlows = flows.getFlows();
|
2016-10-09 23:02:24 +02:00
|
|
|
storage.conf.flows.should.eql(cleanedFlows.flows);
|
|
|
|
cleanedFlows.flows.should.not.eql(originalConfig);
|
|
|
|
cleanedFlows.flows[0].credentials = {"a":1};
|
|
|
|
cleanedFlows.flows.should.eql(originalConfig);
|
2015-10-11 21:37:11 +02:00
|
|
|
done();
|
|
|
|
});
|
2015-11-02 16:38:16 +01:00
|
|
|
});
|
2015-10-11 21:37:11 +02:00
|
|
|
|
2015-11-02 16:38:16 +01:00
|
|
|
it('updates existing flows with partial deployment - nodes', function(done) {
|
|
|
|
var originalConfig = [
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
|
|
|
{id:"t1",type:"tab"}
|
|
|
|
];
|
|
|
|
var newConfig = clone(originalConfig);
|
|
|
|
newConfig.push({id:"t1-2",x:10,y:10,z:"t1",type:"test",wires:[]});
|
|
|
|
newConfig.push({id:"t2",type:"tab"});
|
|
|
|
newConfig.push({id:"t2-1",x:10,y:10,z:"t2",type:"test",wires:[]});
|
|
|
|
storage.getFlows = function() {
|
2016-09-21 22:58:50 +02:00
|
|
|
return when.resolve({flows:originalConfig});
|
2015-11-02 16:38:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
events.once('nodes-started',function() {
|
|
|
|
flows.setFlows(newConfig,"nodes").then(function() {
|
2016-10-09 23:02:24 +02:00
|
|
|
flows.getFlows().flows.should.eql(newConfig);
|
2016-10-10 14:27:43 +02:00
|
|
|
flowCreate.flows['t1'].update.called.should.be.true();
|
|
|
|
flowCreate.flows['t2'].start.called.should.be.true();
|
|
|
|
flowCreate.flows['_GLOBAL_'].update.called.should.be.true();
|
2015-11-02 16:38:16 +01:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:storage});
|
2015-11-02 16:38:16 +01:00
|
|
|
flows.load().then(function() {
|
|
|
|
flows.startFlows();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates existing flows with partial deployment - flows', function(done) {
|
|
|
|
var originalConfig = [
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
|
|
|
{id:"t1",type:"tab"}
|
|
|
|
];
|
|
|
|
var newConfig = clone(originalConfig);
|
|
|
|
newConfig.push({id:"t1-2",x:10,y:10,z:"t1",type:"test",wires:[]});
|
|
|
|
newConfig.push({id:"t2",type:"tab"});
|
|
|
|
newConfig.push({id:"t2-1",x:10,y:10,z:"t2",type:"test",wires:[]});
|
|
|
|
storage.getFlows = function() {
|
2016-09-21 22:58:50 +02:00
|
|
|
return when.resolve({flows:originalConfig});
|
2015-11-02 16:38:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
events.once('nodes-started',function() {
|
|
|
|
flows.setFlows(newConfig,"nodes").then(function() {
|
2016-10-09 23:02:24 +02:00
|
|
|
flows.getFlows().flows.should.eql(newConfig);
|
2016-10-10 14:27:43 +02:00
|
|
|
flowCreate.flows['t1'].update.called.should.be.true();
|
|
|
|
flowCreate.flows['t2'].start.called.should.be.true();
|
|
|
|
flowCreate.flows['_GLOBAL_'].update.called.should.be.true();
|
2015-11-02 16:38:16 +01:00
|
|
|
flows.stopFlows().then(done);
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:storage});
|
2015-11-02 16:38:16 +01:00
|
|
|
flows.load().then(function() {
|
|
|
|
flows.startFlows();
|
|
|
|
});
|
2015-10-11 21:37:11 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#load', function() {
|
|
|
|
it('loads the flow config', function(done) {
|
|
|
|
var originalConfig = [
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
|
|
|
{id:"t1",type:"tab"}
|
|
|
|
];
|
|
|
|
storage.getFlows = function() {
|
2016-09-21 22:58:50 +02:00
|
|
|
return when.resolve({flows:originalConfig});
|
2015-10-11 21:37:11 +02:00
|
|
|
}
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:storage});
|
2015-10-11 21:37:11 +02:00
|
|
|
flows.load().then(function() {
|
2016-10-10 14:27:43 +02:00
|
|
|
credentialsLoad.called.should.be.true();
|
2015-10-11 21:37:11 +02:00
|
|
|
// 'load' type does not trigger a save
|
2016-10-10 14:27:43 +02:00
|
|
|
storage.hasOwnProperty('conf').should.be.false();
|
2016-10-09 23:02:24 +02:00
|
|
|
flows.getFlows().flows.should.eql(originalConfig);
|
2015-10-11 21:37:11 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#startFlows', function() {
|
2015-11-02 16:38:16 +01:00
|
|
|
it('starts the loaded config', function(done) {
|
|
|
|
var originalConfig = [
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
|
|
|
{id:"t1",type:"tab"}
|
|
|
|
];
|
|
|
|
storage.getFlows = function() {
|
2016-09-21 22:58:50 +02:00
|
|
|
return when.resolve({flows:originalConfig});
|
2015-11-02 16:38:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
events.once('nodes-started',function() {
|
|
|
|
Object.keys(flowCreate.flows).should.eql(['_GLOBAL_','t1']);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:storage});
|
2015-11-02 16:38:16 +01:00
|
|
|
flows.load().then(function() {
|
|
|
|
flows.startFlows();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('does not start if nodes missing', function(done) {
|
2015-10-11 21:37:11 +02:00
|
|
|
var originalConfig = [
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
2015-11-02 16:38:16 +01:00
|
|
|
{id:"t1-2",x:10,y:10,z:"t1",type:"missing",wires:[]},
|
2015-10-11 21:37:11 +02:00
|
|
|
{id:"t1",type:"tab"}
|
|
|
|
];
|
|
|
|
storage.getFlows = function() {
|
2016-09-21 22:58:50 +02:00
|
|
|
return when.resolve({flows:originalConfig});
|
2015-10-11 21:37:11 +02:00
|
|
|
}
|
2015-11-02 16:38:16 +01:00
|
|
|
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:storage});
|
2015-10-11 21:37:11 +02:00
|
|
|
flows.load().then(function() {
|
|
|
|
flows.startFlows();
|
2016-10-10 14:27:43 +02:00
|
|
|
flowCreate.called.should.be.false();
|
2015-10-11 21:37:11 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2015-11-02 16:38:16 +01:00
|
|
|
|
|
|
|
it('starts when missing nodes registered', function(done) {
|
|
|
|
var originalConfig = [
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
|
|
|
{id:"t1-2",x:10,y:10,z:"t1",type:"missing",wires:[]},
|
|
|
|
{id:"t1-3",x:10,y:10,z:"t1",type:"missing2",wires:[]},
|
|
|
|
{id:"t1",type:"tab"}
|
|
|
|
];
|
|
|
|
storage.getFlows = function() {
|
2016-09-21 22:58:50 +02:00
|
|
|
return when.resolve({flows:originalConfig});
|
2015-11-02 16:38:16 +01:00
|
|
|
}
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:storage});
|
2015-11-02 16:38:16 +01:00
|
|
|
flows.load().then(function() {
|
|
|
|
flows.startFlows();
|
2016-10-10 14:27:43 +02:00
|
|
|
flowCreate.called.should.be.false();
|
2015-11-02 16:38:16 +01:00
|
|
|
|
|
|
|
events.emit("type-registered","missing");
|
|
|
|
setTimeout(function() {
|
2016-10-10 14:27:43 +02:00
|
|
|
flowCreate.called.should.be.false();
|
2015-11-02 16:38:16 +01:00
|
|
|
events.emit("type-registered","missing2");
|
|
|
|
setTimeout(function() {
|
2016-10-10 14:27:43 +02:00
|
|
|
flowCreate.called.should.be.true();
|
2015-11-02 16:38:16 +01:00
|
|
|
done();
|
|
|
|
},10);
|
|
|
|
},10);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-11 21:37:11 +02:00
|
|
|
});
|
|
|
|
|
2016-09-21 22:58:50 +02:00
|
|
|
describe.skip('#get',function() {
|
2015-10-11 21:37:11 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#eachNode', function() {
|
2015-11-02 16:38:16 +01:00
|
|
|
it('iterates the flow nodes', function(done) {
|
|
|
|
var originalConfig = [
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
|
|
|
{id:"t1",type:"tab"}
|
|
|
|
];
|
|
|
|
storage.getFlows = function() {
|
2016-09-21 22:58:50 +02:00
|
|
|
return when.resolve({flows:originalConfig});
|
2015-11-02 16:38:16 +01:00
|
|
|
}
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:storage});
|
2015-11-02 16:38:16 +01:00
|
|
|
flows.load().then(function() {
|
|
|
|
var c = 0;
|
|
|
|
flows.eachNode(function(node) {
|
|
|
|
c++
|
|
|
|
})
|
|
|
|
c.should.equal(2);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2015-10-11 21:37:11 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('#stopFlows', function() {
|
|
|
|
|
|
|
|
});
|
|
|
|
describe('#handleError', function() {
|
2015-11-02 16:38:16 +01:00
|
|
|
it('passes error to correct flow', function(done) {
|
|
|
|
var originalConfig = [
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
|
|
|
{id:"t1",type:"tab"}
|
|
|
|
];
|
|
|
|
storage.getFlows = function() {
|
2016-09-21 22:58:50 +02:00
|
|
|
return when.resolve({flows:originalConfig});
|
2015-11-02 16:38:16 +01:00
|
|
|
}
|
2015-10-11 21:37:11 +02:00
|
|
|
|
2015-11-02 16:38:16 +01:00
|
|
|
events.once('nodes-started',function() {
|
|
|
|
flows.handleError(originalConfig[0],"message",{});
|
2016-10-10 14:27:43 +02:00
|
|
|
flowCreate.flows['t1'].handleError.called.should.be.true();
|
2015-11-02 16:38:16 +01:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:storage});
|
2015-11-02 21:41:59 +01:00
|
|
|
flows.load().then(function() {
|
|
|
|
flows.startFlows();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('passes error to flows that use the originating global config', function(done) {
|
|
|
|
var originalConfig = [
|
|
|
|
{id:"configNode",type:"test"},
|
|
|
|
{id:"t1",type:"tab"},
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",config:"configNode",wires:[]},
|
|
|
|
{id:"t2",type:"tab"},
|
|
|
|
{id:"t2-1",x:10,y:10,z:"t2",type:"test",wires:[]},
|
|
|
|
{id:"t3",type:"tab"},
|
|
|
|
{id:"t3-1",x:10,y:10,z:"t3",type:"test",config:"configNode",wires:[]}
|
|
|
|
];
|
|
|
|
storage.getFlows = function() {
|
2016-09-21 22:58:50 +02:00
|
|
|
return when.resolve({flows:originalConfig});
|
2015-11-02 21:41:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
events.once('nodes-started',function() {
|
|
|
|
flows.handleError(originalConfig[0],"message",{});
|
|
|
|
try {
|
2016-10-10 14:27:43 +02:00
|
|
|
flowCreate.flows['t1'].handleError.called.should.be.true();
|
|
|
|
flowCreate.flows['t2'].handleError.called.should.be.false();
|
|
|
|
flowCreate.flows['t3'].handleError.called.should.be.true();
|
2015-11-02 21:41:59 +01:00
|
|
|
done();
|
|
|
|
} catch(err) {
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:storage});
|
2015-11-02 16:38:16 +01:00
|
|
|
flows.load().then(function() {
|
|
|
|
flows.startFlows();
|
|
|
|
});
|
|
|
|
});
|
2015-10-11 21:37:11 +02:00
|
|
|
});
|
|
|
|
describe('#handleStatus', function() {
|
2015-11-02 16:38:16 +01:00
|
|
|
it('passes status to correct flow', function(done) {
|
|
|
|
var originalConfig = [
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
|
|
|
{id:"t1",type:"tab"}
|
|
|
|
];
|
|
|
|
storage.getFlows = function() {
|
2016-09-21 22:58:50 +02:00
|
|
|
return when.resolve({flows:originalConfig});
|
2015-11-02 16:38:16 +01:00
|
|
|
}
|
2015-10-11 21:37:11 +02:00
|
|
|
|
2015-11-02 16:38:16 +01:00
|
|
|
events.once('nodes-started',function() {
|
|
|
|
flows.handleStatus(originalConfig[0],"message");
|
2016-10-10 14:27:43 +02:00
|
|
|
flowCreate.flows['t1'].handleStatus.called.should.be.true();
|
2015-11-02 16:38:16 +01:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:storage});
|
2015-11-02 16:38:16 +01:00
|
|
|
flows.load().then(function() {
|
|
|
|
flows.startFlows();
|
|
|
|
});
|
|
|
|
});
|
2015-10-11 21:37:11 +02:00
|
|
|
|
2015-11-02 21:41:59 +01:00
|
|
|
it('passes status to flows that use the originating global config', function(done) {
|
|
|
|
var originalConfig = [
|
|
|
|
{id:"configNode",type:"test"},
|
|
|
|
{id:"t1",type:"tab"},
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",config:"configNode",wires:[]},
|
|
|
|
{id:"t2",type:"tab"},
|
|
|
|
{id:"t2-1",x:10,y:10,z:"t2",type:"test",wires:[]},
|
|
|
|
{id:"t3",type:"tab"},
|
|
|
|
{id:"t3-1",x:10,y:10,z:"t3",type:"test",config:"configNode",wires:[]}
|
|
|
|
];
|
|
|
|
storage.getFlows = function() {
|
2016-09-21 22:58:50 +02:00
|
|
|
return when.resolve({flows:originalConfig});
|
2015-11-02 21:41:59 +01:00
|
|
|
}
|
2015-10-11 21:37:11 +02:00
|
|
|
|
2015-11-02 21:41:59 +01:00
|
|
|
events.once('nodes-started',function() {
|
|
|
|
flows.handleStatus(originalConfig[0],"message");
|
|
|
|
try {
|
2016-10-10 14:27:43 +02:00
|
|
|
flowCreate.flows['t1'].handleStatus.called.should.be.true();
|
|
|
|
flowCreate.flows['t2'].handleStatus.called.should.be.false();
|
|
|
|
flowCreate.flows['t3'].handleStatus.called.should.be.true();
|
2015-11-02 21:41:59 +01:00
|
|
|
done();
|
|
|
|
} catch(err) {
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:storage});
|
2015-11-02 21:41:59 +01:00
|
|
|
flows.load().then(function() {
|
|
|
|
flows.startFlows();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2015-11-09 12:29:48 +01:00
|
|
|
|
|
|
|
describe('#checkTypeInUse', function() {
|
|
|
|
|
|
|
|
before(function() {
|
|
|
|
sinon.stub(typeRegistry,"getNodeInfo",function(id) {
|
|
|
|
if (id === 'unused-module') {
|
|
|
|
return {types:['one','two','three']}
|
|
|
|
} else {
|
|
|
|
return {types:['one','test','three']}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function() {
|
|
|
|
typeRegistry.getNodeInfo.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns cleanly if type not is use', function(done) {
|
|
|
|
var originalConfig = [
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
|
|
|
{id:"t1",type:"tab"}
|
|
|
|
];
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:storage});
|
2015-11-09 12:29:48 +01:00
|
|
|
flows.setFlows(originalConfig).then(function() {
|
|
|
|
flows.checkTypeInUse("unused-module");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('throws error if type is in use', function(done) {
|
|
|
|
var originalConfig = [
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
|
|
|
{id:"t1",type:"tab"}
|
|
|
|
];
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:storage});
|
2015-11-09 12:29:48 +01:00
|
|
|
flows.setFlows(originalConfig).then(function() {
|
|
|
|
/*jshint immed: false */
|
|
|
|
try {
|
|
|
|
flows.checkTypeInUse("used-module");
|
|
|
|
done("type_in_use error not thrown");
|
|
|
|
} catch(err) {
|
|
|
|
err.code.should.eql("type_in_use");
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2015-12-06 23:49:51 +01:00
|
|
|
|
|
|
|
describe('#addFlow', function() {
|
|
|
|
it("rejects duplicate node id",function(done) {
|
|
|
|
var originalConfig = [
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
|
|
|
{id:"t1",type:"tab"}
|
|
|
|
];
|
|
|
|
storage.getFlows = function() {
|
2016-09-21 22:58:50 +02:00
|
|
|
return when.resolve({flows:originalConfig});
|
2015-12-06 23:49:51 +01:00
|
|
|
}
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:storage});
|
2015-12-06 23:49:51 +01:00
|
|
|
flows.load().then(function() {
|
|
|
|
flows.addFlow({
|
|
|
|
label:'new flow',
|
|
|
|
nodes:[
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]}
|
|
|
|
]
|
|
|
|
}).then(function() {
|
|
|
|
done(new Error('failed to reject duplicate node id'));
|
2018-04-24 16:01:49 +02:00
|
|
|
}).catch(function(err) {
|
2015-12-06 23:49:51 +01:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("addFlow",function(done) {
|
|
|
|
var originalConfig = [
|
|
|
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
|
|
|
{id:"t1",type:"tab"}
|
|
|
|
];
|
|
|
|
storage.getFlows = function() {
|
2016-09-21 22:58:50 +02:00
|
|
|
return when.resolve({flows:originalConfig});
|
2015-12-06 23:49:51 +01:00
|
|
|
}
|
2015-12-09 22:51:46 +01:00
|
|
|
storage.setFlows = function() {
|
|
|
|
return when.resolve();
|
|
|
|
}
|
2018-04-23 15:24:51 +02:00
|
|
|
flows.init({log:mockLog, settings:{},storage:storage});
|
2015-12-06 23:49:51 +01:00
|
|
|
flows.load().then(function() {
|
|
|
|
return flows.startFlows();
|
|
|
|
}).then(function() {
|
|
|
|
flows.addFlow({
|
|
|
|
label:'new flow',
|
|
|
|
nodes:[
|
|
|
|
{id:"t2-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
2018-04-23 15:24:51 +02:00
|
|
|
{id:"t2-2",x:10,y:10,z:"t1",type:"test",wires:[]},
|
2015-12-06 23:49:51 +01:00
|
|
|
{id:"t2-3",z:"t1",type:"test"}
|
|
|
|
]
|
|
|
|
}).then(function(id) {
|
2016-10-09 23:02:24 +02:00
|
|
|
flows.getFlows().flows.should.have.lengthOf(6);
|
2015-12-06 23:49:51 +01:00
|
|
|
var createdFlows = Object.keys(flowCreate.flows);
|
|
|
|
createdFlows.should.have.lengthOf(3);
|
|
|
|
createdFlows[2].should.eql(id);
|
|
|
|
done();
|
2018-04-24 16:01:49 +02:00
|
|
|
}).catch(function(err) {
|
2015-12-06 23:49:51 +01:00
|
|
|
done(err);
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
})
|
|
|
|
describe('#updateFlow', function() {
|
|
|
|
it.skip("updateFlow");
|
|
|
|
})
|
|
|
|
describe('#removeFlow', function() {
|
|
|
|
it.skip("removeFlow");
|
|
|
|
})
|
|
|
|
describe('#disableFlow', function() {
|
|
|
|
it.skip("disableFlow");
|
|
|
|
})
|
|
|
|
describe('#enableFlow', function() {
|
|
|
|
it.skip("enableFlow");
|
|
|
|
})
|
2015-11-02 21:41:59 +01:00
|
|
|
});
|