mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Increase flows test coverage
This commit is contained in:
parent
500e9a4010
commit
153fa7478f
@ -35,10 +35,9 @@ var activeConfigNodes = {};
|
|||||||
|
|
||||||
events.on('type-registered',function(type) {
|
events.on('type-registered',function(type) {
|
||||||
if (activeFlow) {
|
if (activeFlow) {
|
||||||
if (activeFlow.typeRegistered(type)) {
|
activeFlow.typeRegistered(type);
|
||||||
log.info("Missing type registered: "+type);
|
log.info("Missing type registered: "+type);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var flowNodes = module.exports = {
|
var flowNodes = module.exports = {
|
||||||
@ -113,7 +112,6 @@ var flowNodes = module.exports = {
|
|||||||
} else {
|
} else {
|
||||||
credentialSavePromise = when.resolve();
|
credentialSavePromise = when.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type=="full") {
|
if (type=="full") {
|
||||||
return credentialSavePromise
|
return credentialSavePromise
|
||||||
.then(function() { return storage.saveFlows(cleanConfig);})
|
.then(function() { return storage.saveFlows(cleanConfig);})
|
||||||
|
@ -17,11 +17,14 @@
|
|||||||
var should = require("should");
|
var should = require("should");
|
||||||
var sinon = require("sinon");
|
var sinon = require("sinon");
|
||||||
var when = require("when");
|
var when = require("when");
|
||||||
|
var clone = require("clone");
|
||||||
var flows = require("../../../red/nodes/flows");
|
var flows = require("../../../red/nodes/flows");
|
||||||
var RedNode = require("../../../red/nodes/Node");
|
var RedNode = require("../../../red/nodes/Node");
|
||||||
var RED = require("../../../red/nodes");
|
var RED = require("../../../red/nodes");
|
||||||
var events = require("../../../red/events");
|
var events = require("../../../red/events");
|
||||||
|
var credentials = require("../../../red/nodes/credentials");
|
||||||
var typeRegistry = require("../../../red/nodes/registry");
|
var typeRegistry = require("../../../red/nodes/registry");
|
||||||
|
var Flow = require("../../../red/nodes/Flow");
|
||||||
|
|
||||||
|
|
||||||
var settings = {
|
var settings = {
|
||||||
@ -141,24 +144,87 @@ describe('flows', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#setFlows',function() {
|
describe('#setFlows',function() {
|
||||||
it('should save and start an empty tab flow',function(done) {
|
var credentialsExtact;
|
||||||
var saved = 0;
|
var credentialsSave;
|
||||||
var testFlows = [{"type":"tab","id":"tab1","label":"Sheet 1"}];
|
var stopFlows;
|
||||||
var storage = {
|
var startFlows;
|
||||||
saveFlows: function(conf) {
|
var credentialsExtractNode;
|
||||||
var defer = when.defer();
|
beforeEach(function() {
|
||||||
defer.resolve();
|
credentialsExtact = sinon.stub(credentials,"extract",function(node) {credentialsExtractNode = clone(node);delete node.credentials;});
|
||||||
should.deepEqual(testFlows, conf);
|
credentialsSave = sinon.stub(credentials,"save",function() { return when.resolve();});
|
||||||
return defer.promise;
|
stopFlows = sinon.stub(flows,"stopFlows",function() {return when.resolve();});
|
||||||
},
|
startFlows = sinon.stub(flows,"startFlows",function() {});
|
||||||
saveCredentials: function (creds) {
|
});
|
||||||
return when(true);
|
afterEach(function() {
|
||||||
|
credentialsExtact.restore();
|
||||||
|
credentialsSave.restore();
|
||||||
|
startFlows.restore();
|
||||||
|
stopFlows.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should extract credentials from nodes', function(done) {
|
||||||
|
var testFlow = [{"type":"testNode","credentials":{"a":1}},{"type":"testNode2"}];
|
||||||
|
var resultFlow = clone(testFlow);
|
||||||
|
var storage = { saveFlows: sinon.spy() };
|
||||||
|
flows.init(storage);
|
||||||
|
flows.setFlows(testFlow,"full").then(function() {
|
||||||
|
try {
|
||||||
|
credentialsExtact.calledOnce.should.be.true;
|
||||||
|
// credential property stripped
|
||||||
|
testFlow.should.not.have.property("credentials");
|
||||||
|
credentialsExtractNode.should.eql(resultFlow[0]);
|
||||||
|
credentialsExtractNode.should.not.equal(resultFlow[0]);
|
||||||
|
|
||||||
|
credentialsSave.calledOnce.should.be.true;
|
||||||
|
|
||||||
|
storage.saveFlows.calledOnce.should.be.true;
|
||||||
|
storage.saveFlows.args[0][0].should.eql(testFlow);
|
||||||
|
|
||||||
|
stopFlows.calledOnce.should.be.true;
|
||||||
|
startFlows.calledOnce.should.be.true;
|
||||||
|
|
||||||
|
done();
|
||||||
|
} catch(err) {
|
||||||
|
done(err);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
RED.init(settings, storage);
|
|
||||||
flows.setFlows(testFlows);
|
|
||||||
events.once('nodes-started', function() { done(); });
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should apply diff on partial deployment', function(done) {
|
||||||
|
var testFlow = [{"type":"testNode"},{"type":"testNode2"}];
|
||||||
|
var testFlow2 = [{"type":"testNode3"},{"type":"testNode4"}];
|
||||||
|
var storage = { saveFlows: sinon.spy() };
|
||||||
|
flows.init(storage);
|
||||||
|
|
||||||
|
flows.setFlows(testFlow,"full").then(function() {
|
||||||
|
flows.setFlows(testFlow2,"nodes").then(function() {
|
||||||
|
try {
|
||||||
|
credentialsExtact.called.should.be.false;
|
||||||
|
|
||||||
|
storage.saveFlows.calledTwice.should.be.true;
|
||||||
|
storage.saveFlows.args[1][0].should.eql(testFlow2);
|
||||||
|
|
||||||
|
stopFlows.calledTwice.should.be.true;
|
||||||
|
startFlows.calledTwice.should.be.true;
|
||||||
|
|
||||||
|
var configDiff = {
|
||||||
|
type: 'nodes',
|
||||||
|
stop: [],
|
||||||
|
rewire: [],
|
||||||
|
config: testFlow2
|
||||||
|
}
|
||||||
|
stopFlows.args[1][0].should.eql(configDiff);
|
||||||
|
startFlows.args[1][0].should.eql(configDiff);
|
||||||
|
|
||||||
|
done();
|
||||||
|
} catch(err) {
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user