mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Fix type checking in unit tests
This commit is contained in:
@@ -56,11 +56,11 @@ describe("red/storage/index", function() {
|
||||
};
|
||||
|
||||
storage.init(setsBooleanModule);
|
||||
initSetsMeToTrue.should.be.true;
|
||||
initSetsMeToTrue.should.be.true();
|
||||
done();
|
||||
});
|
||||
|
||||
it('respects storage interface', function() {
|
||||
it('respects storage interface', function(done) {
|
||||
var calledFlagGetFlows = false;
|
||||
var calledFlagGetCredentials = false;
|
||||
var calledFlagGetAllFlows = false;
|
||||
@@ -70,7 +70,7 @@ describe("red/storage/index", function() {
|
||||
|
||||
var interfaceCheckerModule = {
|
||||
init : function (settings) {
|
||||
settings.should.be.an.Object;
|
||||
settings.should.be.an.Object();
|
||||
calledInit = true;
|
||||
},
|
||||
getFlows : function() {
|
||||
@@ -78,7 +78,8 @@ describe("red/storage/index", function() {
|
||||
return when.resolve([]);
|
||||
},
|
||||
saveFlows : function (flows) {
|
||||
flows.should.be.true;
|
||||
flows.should.be.an.Array();
|
||||
flows.should.have.lengthOf(0);
|
||||
return when.resolve("");
|
||||
},
|
||||
getCredentials : function() {
|
||||
@@ -86,19 +87,19 @@ describe("red/storage/index", function() {
|
||||
return when.resolve({});
|
||||
},
|
||||
saveCredentials : function(credentials) {
|
||||
credentials.should.be.true;
|
||||
credentials.should.be.true();
|
||||
},
|
||||
getSettings : function() {
|
||||
calledFlagGetSettings = true;
|
||||
},
|
||||
saveSettings : function(settings) {
|
||||
settings.should.be.true;
|
||||
settings.should.be.true();
|
||||
},
|
||||
getSessions : function() {
|
||||
calledFlagGetSessions = true;
|
||||
},
|
||||
saveSessions : function(sessions) {
|
||||
sessions.should.be.true;
|
||||
sessions.should.be.true();
|
||||
},
|
||||
getAllFlows : function() {
|
||||
calledFlagGetAllFlows = true;
|
||||
@@ -108,17 +109,17 @@ describe("red/storage/index", function() {
|
||||
},
|
||||
saveFlow : function(fn, data) {
|
||||
fn.should.equal("name");
|
||||
data.should.be.true;
|
||||
data.should.be.true();
|
||||
},
|
||||
getLibraryEntry : function(type, path) {
|
||||
type.should.be.true;
|
||||
type.should.be.true();
|
||||
path.should.equal("name");
|
||||
},
|
||||
saveLibraryEntry : function(type, path, meta, body) {
|
||||
type.should.be.true;
|
||||
type.should.be.true();
|
||||
path.should.equal("name");
|
||||
meta.should.be.true;
|
||||
body.should.be.true;
|
||||
meta.should.be.true();
|
||||
body.should.be.true();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -128,9 +129,10 @@ describe("red/storage/index", function() {
|
||||
}
|
||||
};
|
||||
|
||||
var promises = [];
|
||||
storage.init(moduleToLoad);
|
||||
storage.getFlows();
|
||||
storage.saveFlows({flows:[],credentials:{}});
|
||||
promises.push(storage.getFlows());
|
||||
promises.push(storage.saveFlows({flows:[],credentials:{}}));
|
||||
storage.getSettings();
|
||||
storage.saveSettings(true);
|
||||
storage.getSessions();
|
||||
@@ -141,10 +143,17 @@ describe("red/storage/index", function() {
|
||||
storage.getLibraryEntry(true, "name");
|
||||
storage.saveLibraryEntry(true, "name", true, true);
|
||||
|
||||
calledInit.should.be.true;
|
||||
calledFlagGetFlows.should.be.true;
|
||||
calledFlagGetCredentials.should.be.true;
|
||||
calledFlagGetAllFlows.should.be.true;
|
||||
when.settle(promises).then(function() {
|
||||
try {
|
||||
calledInit.should.be.true();
|
||||
calledFlagGetFlows.should.be.true();
|
||||
calledFlagGetCredentials.should.be.true();
|
||||
calledFlagGetAllFlows.should.be.true();
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('respects deprecated flow library functions', function() {
|
||||
@@ -156,7 +165,7 @@ describe("red/storage/index", function() {
|
||||
|
||||
var interfaceCheckerModule = {
|
||||
init : function (settings) {
|
||||
settings.should.be.an.Object;
|
||||
settings.should.be.an.Object();
|
||||
},
|
||||
getLibraryEntry : function(type, path) {
|
||||
if (type === "flows") {
|
||||
|
@@ -34,8 +34,8 @@ describe('LocalFileSystem', function() {
|
||||
|
||||
it('should initialise the user directory',function(done) {
|
||||
localfilesystem.init({userDir:userDir}).then(function() {
|
||||
fs.existsSync(path.join(userDir,"lib")).should.be.true;
|
||||
fs.existsSync(path.join(userDir,"lib",'flows')).should.be.true;
|
||||
fs.existsSync(path.join(userDir,"lib")).should.be.true();
|
||||
fs.existsSync(path.join(userDir,"lib",'flows')).should.be.true();
|
||||
done();
|
||||
}).otherwise(function(err) {
|
||||
done(err);
|
||||
@@ -51,8 +51,8 @@ describe('LocalFileSystem', function() {
|
||||
var settings = {};
|
||||
localfilesystem.init(settings).then(function() {
|
||||
try {
|
||||
fs.existsSync(path.join(process.env.NODE_RED_HOME,"lib")).should.be.true;
|
||||
fs.existsSync(path.join(process.env.NODE_RED_HOME,"lib",'flows')).should.be.true;
|
||||
fs.existsSync(path.join(process.env.NODE_RED_HOME,"lib")).should.be.true();
|
||||
fs.existsSync(path.join(process.env.NODE_RED_HOME,"lib",'flows')).should.be.true();
|
||||
settings.userDir.should.equal(process.env.NODE_RED_HOME);
|
||||
done();
|
||||
} catch(err) {
|
||||
@@ -75,8 +75,8 @@ describe('LocalFileSystem', function() {
|
||||
var settings = {};
|
||||
localfilesystem.init(settings).then(function() {
|
||||
try {
|
||||
fs.existsSync(path.join(process.env.HOME,".node-red","lib")).should.be.true;
|
||||
fs.existsSync(path.join(process.env.HOME,".node-red","lib",'flows')).should.be.true;
|
||||
fs.existsSync(path.join(process.env.HOME,".node-red","lib")).should.be.true();
|
||||
fs.existsSync(path.join(process.env.HOME,".node-red","lib",'flows')).should.be.true();
|
||||
settings.userDir.should.equal(path.join(process.env.HOME,".node-red"));
|
||||
done();
|
||||
} catch(err) {
|
||||
@@ -94,7 +94,7 @@ describe('LocalFileSystem', function() {
|
||||
localfilesystem.init({userDir:userDir}).then(function() {
|
||||
var flowFile = 'flows_'+require('os').hostname()+'.json';
|
||||
var flowFilePath = path.join(userDir,flowFile);
|
||||
fs.existsSync(flowFilePath).should.be.false;
|
||||
fs.existsSync(flowFilePath).should.be.false();
|
||||
localfilesystem.getFlows().then(function(flows) {
|
||||
flows.should.eql([]);
|
||||
done();
|
||||
@@ -112,7 +112,7 @@ describe('LocalFileSystem', function() {
|
||||
var flowFilePath = path.join(userDir,flowFile);
|
||||
var flowFileBackupPath = path.join(userDir,"."+flowFile+".backup");
|
||||
fs.closeSync(fs.openSync(flowFilePath, 'w'));
|
||||
fs.existsSync(flowFilePath).should.be.true;
|
||||
fs.existsSync(flowFilePath).should.be.true();
|
||||
localfilesystem.getFlows().then(function(flows) {
|
||||
flows.should.eql([]);
|
||||
done();
|
||||
@@ -130,10 +130,10 @@ describe('LocalFileSystem', function() {
|
||||
var flowFilePath = path.join(userDir,flowFile);
|
||||
var flowFileBackupPath = path.join(userDir,"."+flowFile+".backup");
|
||||
fs.closeSync(fs.openSync(flowFilePath, 'w'));
|
||||
fs.existsSync(flowFilePath).should.be.true;
|
||||
fs.existsSync(flowFileBackupPath).should.be.false;
|
||||
fs.existsSync(flowFilePath).should.be.true();
|
||||
fs.existsSync(flowFileBackupPath).should.be.false();
|
||||
fs.writeFileSync(flowFileBackupPath,JSON.stringify(testFlow));
|
||||
fs.existsSync(flowFileBackupPath).should.be.true;
|
||||
fs.existsSync(flowFileBackupPath).should.be.true();
|
||||
localfilesystem.getFlows().then(function(flows) {
|
||||
flows.should.eql(testFlow);
|
||||
done();
|
||||
@@ -150,11 +150,11 @@ describe('LocalFileSystem', function() {
|
||||
var flowFile = 'flows_'+require('os').hostname()+'.json';
|
||||
var flowFilePath = path.join(userDir,flowFile);
|
||||
var flowFileBackupPath = path.join(userDir,"."+flowFile+".backup");
|
||||
fs.existsSync(flowFilePath).should.be.false;
|
||||
fs.existsSync(flowFileBackupPath).should.be.false;
|
||||
fs.existsSync(flowFilePath).should.be.false();
|
||||
fs.existsSync(flowFileBackupPath).should.be.false();
|
||||
localfilesystem.saveFlows(testFlow).then(function() {
|
||||
fs.existsSync(flowFilePath).should.be.true;
|
||||
fs.existsSync(flowFileBackupPath).should.be.false;
|
||||
fs.existsSync(flowFilePath).should.be.true();
|
||||
fs.existsSync(flowFileBackupPath).should.be.false();
|
||||
localfilesystem.getFlows().then(function(flows) {
|
||||
flows.should.eql(testFlow);
|
||||
done();
|
||||
@@ -176,12 +176,12 @@ describe('LocalFileSystem', function() {
|
||||
var flowFilePath = path.join(userDir,flowFile);
|
||||
|
||||
localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() {
|
||||
fs.existsSync(defaultFlowFilePath).should.be.false;
|
||||
fs.existsSync(flowFilePath).should.be.false;
|
||||
fs.existsSync(defaultFlowFilePath).should.be.false();
|
||||
fs.existsSync(flowFilePath).should.be.false();
|
||||
|
||||
localfilesystem.saveFlows(testFlow).then(function() {
|
||||
fs.existsSync(defaultFlowFilePath).should.be.false;
|
||||
fs.existsSync(flowFilePath).should.be.true;
|
||||
fs.existsSync(defaultFlowFilePath).should.be.false();
|
||||
fs.existsSync(flowFilePath).should.be.true();
|
||||
localfilesystem.getFlows().then(function(flows) {
|
||||
flows.should.eql(testFlow);
|
||||
done();
|
||||
@@ -225,21 +225,21 @@ describe('LocalFileSystem', function() {
|
||||
var flowFileBackupPath = path.join(userDir,"."+flowFile+".backup");
|
||||
|
||||
localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() {
|
||||
fs.existsSync(defaultFlowFilePath).should.be.false;
|
||||
fs.existsSync(flowFilePath).should.be.false;
|
||||
fs.existsSync(flowFileBackupPath).should.be.false;
|
||||
fs.existsSync(defaultFlowFilePath).should.be.false();
|
||||
fs.existsSync(flowFilePath).should.be.false();
|
||||
fs.existsSync(flowFileBackupPath).should.be.false();
|
||||
|
||||
localfilesystem.saveFlows(testFlow).then(function() {
|
||||
fs.existsSync(flowFileBackupPath).should.be.false;
|
||||
fs.existsSync(defaultFlowFilePath).should.be.false;
|
||||
fs.existsSync(flowFilePath).should.be.true;
|
||||
fs.existsSync(flowFileBackupPath).should.be.false();
|
||||
fs.existsSync(defaultFlowFilePath).should.be.false();
|
||||
fs.existsSync(flowFilePath).should.be.true();
|
||||
var content = fs.readFileSync(flowFilePath,'utf8');
|
||||
var testFlow2 = [{"type":"tab","id":"bc5672ad.2741d8","label":"Sheet 2"}];
|
||||
|
||||
localfilesystem.saveFlows(testFlow2).then(function() {
|
||||
fs.existsSync(flowFileBackupPath).should.be.true;
|
||||
fs.existsSync(defaultFlowFilePath).should.be.false;
|
||||
fs.existsSync(flowFilePath).should.be.true;
|
||||
fs.existsSync(flowFileBackupPath).should.be.true();
|
||||
fs.existsSync(defaultFlowFilePath).should.be.false();
|
||||
fs.existsSync(flowFilePath).should.be.true();
|
||||
var backupContent = fs.readFileSync(flowFileBackupPath,'utf8');
|
||||
content.should.equal(backupContent);
|
||||
var content2 = fs.readFileSync(flowFilePath,'utf8');
|
||||
@@ -265,7 +265,7 @@ describe('LocalFileSystem', function() {
|
||||
var flowFilePath = path.join(userDir,flowFile);
|
||||
var credFile = path.join(userDir,"test_cred.json");
|
||||
localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() {
|
||||
fs.existsSync(credFile).should.be.false;
|
||||
fs.existsSync(credFile).should.be.false();
|
||||
|
||||
localfilesystem.getCredentials().then(function(creds) {
|
||||
creds.should.eql({});
|
||||
@@ -285,12 +285,12 @@ describe('LocalFileSystem', function() {
|
||||
|
||||
localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() {
|
||||
|
||||
fs.existsSync(credFile).should.be.false;
|
||||
fs.existsSync(credFile).should.be.false();
|
||||
|
||||
var credentials = {"abc":{"type":"creds"}};
|
||||
|
||||
localfilesystem.saveCredentials(credentials).then(function() {
|
||||
fs.existsSync(credFile).should.be.true;
|
||||
fs.existsSync(credFile).should.be.true();
|
||||
localfilesystem.getCredentials().then(function(creds) {
|
||||
creds.should.eql(credentials);
|
||||
done();
|
||||
@@ -316,14 +316,14 @@ describe('LocalFileSystem', function() {
|
||||
|
||||
fs.writeFileSync(credFile,"{}","utf8");
|
||||
|
||||
fs.existsSync(credFile).should.be.true;
|
||||
fs.existsSync(credFileBackup).should.be.false;
|
||||
fs.existsSync(credFile).should.be.true();
|
||||
fs.existsSync(credFileBackup).should.be.false();
|
||||
|
||||
var credentials = {"abc":{"type":"creds"}};
|
||||
|
||||
localfilesystem.saveCredentials(credentials).then(function() {
|
||||
fs.existsSync(credFile).should.be.true;
|
||||
fs.existsSync(credFileBackup).should.be.true;
|
||||
fs.existsSync(credFile).should.be.true();
|
||||
fs.existsSync(credFileBackup).should.be.true();
|
||||
done();
|
||||
}).otherwise(function(err) {
|
||||
done(err);
|
||||
@@ -341,12 +341,12 @@ describe('LocalFileSystem', function() {
|
||||
|
||||
localfilesystem.init({userDir:userDir, flowFile:flowFilePath, flowFilePretty:true}).then(function() {
|
||||
|
||||
fs.existsSync(credFile).should.be.false;
|
||||
fs.existsSync(credFile).should.be.false();
|
||||
|
||||
var credentials = {"abc":{"type":"creds"}};
|
||||
|
||||
localfilesystem.saveCredentials(credentials).then(function() {
|
||||
fs.existsSync(credFile).should.be.true;
|
||||
fs.existsSync(credFile).should.be.true();
|
||||
var content = fs.readFileSync(credFile,"utf8");
|
||||
content.split("\n").length.should.be.above(1);
|
||||
localfilesystem.getCredentials().then(function(creds) {
|
||||
@@ -367,7 +367,7 @@ describe('LocalFileSystem', function() {
|
||||
var settingsFile = path.join(userDir,".settings.json");
|
||||
|
||||
localfilesystem.init({userDir:userDir}).then(function() {
|
||||
fs.existsSync(settingsFile).should.be.false;
|
||||
fs.existsSync(settingsFile).should.be.false();
|
||||
localfilesystem.getSettings().then(function(settings) {
|
||||
settings.should.eql({});
|
||||
done();
|
||||
@@ -383,7 +383,7 @@ describe('LocalFileSystem', function() {
|
||||
var settingsFile = path.join(userDir,".config.json");
|
||||
fs.writeFileSync(settingsFile,"[This is not json","utf8");
|
||||
localfilesystem.init({userDir:userDir}).then(function() {
|
||||
fs.existsSync(settingsFile).should.be.true;
|
||||
fs.existsSync(settingsFile).should.be.true();
|
||||
localfilesystem.getSettings().then(function(settings) {
|
||||
settings.should.eql({});
|
||||
done();
|
||||
@@ -399,12 +399,12 @@ describe('LocalFileSystem', function() {
|
||||
var settingsFile = path.join(userDir,".config.json");
|
||||
|
||||
localfilesystem.init({userDir:userDir}).then(function() {
|
||||
fs.existsSync(settingsFile).should.be.false;
|
||||
fs.existsSync(settingsFile).should.be.false();
|
||||
|
||||
var settings = {"abc":{"type":"creds"}};
|
||||
|
||||
localfilesystem.saveSettings(settings).then(function() {
|
||||
fs.existsSync(settingsFile).should.be.true;
|
||||
fs.existsSync(settingsFile).should.be.true();
|
||||
localfilesystem.getSettings().then(function(_settings) {
|
||||
_settings.should.eql(settings);
|
||||
done();
|
||||
@@ -423,7 +423,7 @@ describe('LocalFileSystem', function() {
|
||||
var sessionsFile = path.join(userDir,".sessions.json");
|
||||
|
||||
localfilesystem.init({userDir:userDir}).then(function() {
|
||||
fs.existsSync(sessionsFile).should.be.false;
|
||||
fs.existsSync(sessionsFile).should.be.false();
|
||||
localfilesystem.getSessions().then(function(sessions) {
|
||||
sessions.should.eql({});
|
||||
done();
|
||||
@@ -439,7 +439,7 @@ describe('LocalFileSystem', function() {
|
||||
var sessionsFile = path.join(userDir,".sessions.json");
|
||||
fs.writeFileSync(sessionsFile,"[This is not json","utf8");
|
||||
localfilesystem.init({userDir:userDir}).then(function() {
|
||||
fs.existsSync(sessionsFile).should.be.true;
|
||||
fs.existsSync(sessionsFile).should.be.true();
|
||||
localfilesystem.getSessions().then(function(sessions) {
|
||||
sessions.should.eql({});
|
||||
done();
|
||||
@@ -455,12 +455,12 @@ describe('LocalFileSystem', function() {
|
||||
var sessionsFile = path.join(userDir,".sessions.json");
|
||||
|
||||
localfilesystem.init({userDir:userDir}).then(function() {
|
||||
fs.existsSync(sessionsFile).should.be.false;
|
||||
fs.existsSync(sessionsFile).should.be.false();
|
||||
|
||||
var sessions = {"abc":{"type":"creds"}};
|
||||
|
||||
localfilesystem.saveSessions(sessions).then(function() {
|
||||
fs.existsSync(sessionsFile).should.be.true;
|
||||
fs.existsSync(sessionsFile).should.be.true();
|
||||
localfilesystem.getSessions().then(function(_sessions) {
|
||||
_sessions.should.eql(sessions);
|
||||
done();
|
||||
|
Reference in New Issue
Block a user