2 * Copyright 2014 IBM Corp.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 var should = require("should");
18 describe("red/storage/index", function() {
20 it('rejects the promise when settings suggest loading a bad module', function(done) {
23 storageModule : "thisaintloading"
26 var storage = require("../../../red/storage/index");
27 storage.init(wrongModule).then( function() {
31 zero.should.equal(one, "The initialization promise should never get resolved");
35 }).catch(function(e) {
36 done(); //successfully rejected promise
40 it('non-string storage module', function(done) {
41 var initSetsMeToTrue = false;
43 var moduleWithBooleanSettingInit = {
45 initSetsMeToTrue = true;
49 var setsBooleanModule = {
50 storageModule : moduleWithBooleanSettingInit
53 var storage = require("../../../red/storage/index");
54 storage.init(setsBooleanModule);
55 initSetsMeToTrue.should.be.true;
59 it('respects storage interface', function(done) {
60 var calledFlagGetFlows = false;
61 var calledFlagGetCredentials = false;
62 var calledFlagGetAllFlows = false;
63 var calledInit = false;
65 var interfaceCheckerModule = {
66 init : function (settings) {
67 settings.should.be.an.Object;
70 getFlows : function() {
71 calledFlagGetFlows = true;
73 saveFlows : function (flows) {
76 getCredentials : function() {
77 calledFlagGetCredentials = true;
79 saveCredentials : function(credentials) {
80 credentials.should.be.true;
82 getAllFlows : function() {
83 calledFlagGetAllFlows = true;
85 getFlow : function(fn) {
86 fn.should.equal("name");
88 saveFlow : function(fn, data) {
89 fn.should.equal("name");
92 getLibraryEntry : function(type, path) {
94 path.should.equal("name");
96 saveLibraryEntry : function(type, path, meta, body) {
98 path.should.equal("name");
105 storageModule : interfaceCheckerModule
107 var storage = require("../../../red/storage/index");
109 storage.init(moduleToLoad);
111 storage.saveFlows(true);
112 storage.getCredentials();
113 storage.saveCredentials(true);
114 storage.getAllFlows();
115 storage.getFlow("name");
116 storage.saveFlow("name", true);
117 storage.getLibraryEntry(true, "name");
118 storage.saveLibraryEntry(true, "name", true, true);
120 calledInit.should.be.true;
121 calledFlagGetFlows.should.be.true;
122 calledFlagGetCredentials.should.be.true;
123 calledFlagGetAllFlows.should.be.true;