Merge pull request #289 from zobalogh/storage-interface-dev

Defining storage interface
This commit is contained in:
Nick O'Leary
2014-07-25 15:00:40 +01:00
2 changed files with 164 additions and 16 deletions

View File

@@ -16,9 +16,117 @@
var should = require("should");
describe("red/storage/index", function() {
it('can be required without errors', function() {
var RED = require('../../../red/red');
RED.init({},{});
require("../../../red/storage/index");
it('can be required without errors', function(done) {
var storage = require("../../../red/storage/index");
done();
});
it('rejects the promise when settings suggest loading a bad module', function(done) {
var wrongModule = {
storageModule : "thisaintloading"
};
var storage = require("../../../red/storage/index");
storage.init(wrongModule).then( function() {
var one = 1;
var zero = 0;
try {
zero.should.equal(one, "The initialization promise should never get resolved");
} catch(err) {
done(err);
}
}).catch(function(e) {
done(); //successfully rejected promise
});
});
it('non-string storage module', function(done) {
var initSetsMeToTrue = false;
var moduleWithBooleanSettingInit = {
init : function() {
initSetsMeToTrue = true;
}
};
var setsBooleanModule = {
storageModule : moduleWithBooleanSettingInit
};
var storage = require("../../../red/storage/index");
storage.init(setsBooleanModule);
initSetsMeToTrue.should.be.true;
done();
});
it('respects storage interface', function(done) {
var calledFlagGetFlows = false;
var calledFlagGetCredentials = false;
var calledFlagGetAllFlows = false;
var calledInit = false;
var interfaceCheckerModule = {
init : function (settings) {
settings.should.be.an.Object;
calledInit = true;
},
getFlows : function() {
calledFlagGetFlows = true;
},
saveFlows : function (flows) {
flows.should.be.true;
},
getCredentials : function() {
calledFlagGetCredentials = true;
},
saveCredentials : function(credentials) {
credentials.should.be.true;
},
getAllFlows : function() {
calledFlagGetAllFlows = true;
},
getFlow : function(fn) {
fn.should.be.true;
},
saveFlow : function(fn, data) {
fn.should.be.true;
data.should.be.true;
},
getLibraryEntry : function(type, path) {
type.should.be.true;
path.should.be.true;
},
saveLibraryEntry : function(type, path, meta, body) {
type.should.be.true;
path.should.be.true;
meta.should.be.true;
body.should.be.true;
}
};
var moduleToLoad = {
storageModule : interfaceCheckerModule
};
var storage = require("../../../red/storage/index");
storage.init(moduleToLoad);
storage.getFlows();
storage.saveFlows(true);
storage.getCredentials();
storage.saveCredentials(true);
storage.getAllFlows();
storage.getFlow(true);
storage.saveFlow(true, true);
storage.getLibraryEntry(true, true);
storage.saveLibraryEntry(true, true, true, true);
calledInit.should.be.true;
calledFlagGetFlows.should.be.true;
calledFlagGetCredentials.should.be.true;
calledFlagGetAllFlows.should.be.true;
done();
});
});