Add v2 /flows api and deploy-overwrite protection

This commit is contained in:
Nick O'Leary
2016-10-09 22:02:24 +01:00
parent c60e0d389c
commit b4be1184fd
17 changed files with 876 additions and 81 deletions

View File

@@ -116,22 +116,31 @@ describe('flows/index', function() {
flows.setFlows(originalConfig).then(function() {
credentialsClean.called.should.be.true;
storage.hasOwnProperty('conf').should.be.true;
flows.getFlows().should.eql(originalConfig);
flows.getFlows().flows.should.eql(originalConfig);
done();
});
});
it('sets the full flow for type load', function(done) {
it('loads the full flow for type load', function(done) {
var originalConfig = [
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
{id:"t1",type:"tab"}
];
flows.init({settings:{},storage:storage});
var loadStorage = {
saveFlows: function(conf) {
loadStorage.conf = conf;
return when.resolve(456);
},
getFlows: function() {
return when.resolve({flows:originalConfig,rev:123})
}
}
flows.init({settings:{},storage:loadStorage});
flows.setFlows(originalConfig,"load").then(function() {
credentialsClean.called.should.be.false;
// 'load' type does not trigger a save
storage.hasOwnProperty('conf').should.be.false;
flows.getFlows().should.eql(originalConfig);
loadStorage.hasOwnProperty('conf').should.be.false;
flows.getFlows().flows.should.eql(originalConfig);
done();
});
@@ -147,10 +156,10 @@ describe('flows/index', function() {
credentialsClean.called.should.be.true;
storage.hasOwnProperty('conf').should.be.true;
var cleanedFlows = flows.getFlows();
storage.conf.flows.should.eql(cleanedFlows);
cleanedFlows.should.not.eql(originalConfig);
cleanedFlows[0].credentials = {"a":1};
cleanedFlows.should.eql(originalConfig);
storage.conf.flows.should.eql(cleanedFlows.flows);
cleanedFlows.flows.should.not.eql(originalConfig);
cleanedFlows.flows[0].credentials = {"a":1};
cleanedFlows.flows.should.eql(originalConfig);
done();
});
});
@@ -170,7 +179,7 @@ describe('flows/index', function() {
events.once('nodes-started',function() {
flows.setFlows(newConfig,"nodes").then(function() {
flows.getFlows().should.eql(newConfig);
flows.getFlows().flows.should.eql(newConfig);
flowCreate.flows['t1'].update.called.should.be.true;
flowCreate.flows['t2'].start.called.should.be.true;
flowCreate.flows['_GLOBAL_'].update.called.should.be.true;
@@ -199,7 +208,7 @@ describe('flows/index', function() {
events.once('nodes-started',function() {
flows.setFlows(newConfig,"nodes").then(function() {
flows.getFlows().should.eql(newConfig);
flows.getFlows().flows.should.eql(newConfig);
flowCreate.flows['t1'].update.called.should.be.true;
flowCreate.flows['t2'].start.called.should.be.true;
flowCreate.flows['_GLOBAL_'].update.called.should.be.true;
@@ -229,7 +238,7 @@ describe('flows/index', function() {
credentialsLoad.called.should.be.true;
// 'load' type does not trigger a save
storage.hasOwnProperty('conf').should.be.false;
flows.getFlows().should.eql(originalConfig);
flows.getFlows().flows.should.eql(originalConfig);
done();
});
});
@@ -535,7 +544,7 @@ describe('flows/index', function() {
{id:"t2-3",z:"t1",type:"test"}
]
}).then(function(id) {
flows.getFlows().should.have.lengthOf(6);
flows.getFlows().flows.should.have.lengthOf(6);
var createdFlows = Object.keys(flowCreate.flows);
createdFlows.should.have.lengthOf(3);
createdFlows[2].should.eql(id);