Add file extension into flow name of library automatically (#1331)

This commit is contained in:
Kazuhito Yokoi 2017-07-09 19:58:17 +09:00 committed by Nick O'Leary
parent c93870316c
commit b3ffd33507
2 changed files with 48 additions and 10 deletions

View File

@ -419,6 +419,9 @@ var localfilesystem = {
if (settings.readOnly) {
return when.resolve();
}
if (type === "flows" && !path.endsWith(".json")) {
path += ".json";
}
var fn = fspath.join(libDir, type, path);
var headers = "";
for (var i in meta) {

View File

@ -587,9 +587,13 @@ describe('LocalFileSystem', function() {
fs.mkdirSync(path.join(objLib,"A"));
fs.mkdirSync(path.join(objLib,"B"));
fs.mkdirSync(path.join(objLib,"B","C"));
fs.writeFileSync(path.join(objLib,"file1.js"),"// abc: def\n// not a metaline \n\n Hi",'utf8');
fs.writeFileSync(path.join(objLib,"B","file2.js"),"// ghi: jkl\n// not a metaline \n\n Hi",'utf8');
fs.writeFileSync(path.join(objLib,"B","flow.json"),"Hi",'utf8');
if (type === "functions" || type === "object") {
fs.writeFileSync(path.join(objLib,"file1.js"),"// abc: def\n// not a metaline \n\n Hi",'utf8');
fs.writeFileSync(path.join(objLib,"B","file2.js"),"// ghi: jkl\n// not a metaline \n\n Hi",'utf8');
}
if (type === "flows" || type === "object") {
fs.writeFileSync(path.join(objLib,"B","flow.json"),"Hi",'utf8');
}
}
it('should return a directory listing of library objects',function(done) {
@ -644,17 +648,17 @@ describe('LocalFileSystem', function() {
});
});
it('should return a newly saved library object',function(done) {
it('should return a newly saved library function',function(done) {
localfilesystem.init({userDir:userDir}).then(function() {
createObjectLibrary();
localfilesystem.getLibraryEntry('object','B').then(function(flows) {
flows.should.eql([ 'C', { ghi: 'jkl', fn: 'file2.js' }, {fn:'flow.json'} ]);
createObjectLibrary("functions");
localfilesystem.getLibraryEntry('functions','B').then(function(flows) {
flows.should.eql([ 'C', { ghi: 'jkl', fn: 'file2.js' } ]);
var ft = path.join("B","D","file3.js");
localfilesystem.saveLibraryEntry('object',ft,{mno:'pqr'},"// another non meta line\n\n Hi There").then(function() {
localfilesystem.saveLibraryEntry('functions',ft,{mno:'pqr'},"// another non meta line\n\n Hi There").then(function() {
setTimeout(function() {
localfilesystem.getLibraryEntry('object',path.join("B","D")).then(function(flows) {
localfilesystem.getLibraryEntry('functions',path.join("B","D")).then(function(flows) {
flows.should.eql([ { mno: 'pqr', fn: 'file3.js' } ]);
localfilesystem.getLibraryEntry('object',ft).then(function(body) {
localfilesystem.getLibraryEntry('functions',ft).then(function(body) {
body.should.eql("// another non meta line\n\n Hi There");
done();
}).otherwise(function(err) {
@ -675,4 +679,35 @@ describe('LocalFileSystem', function() {
});
});
it('should return a newly saved library flow',function(done) {
localfilesystem.init({userDir:userDir}).then(function() {
createObjectLibrary("flows");
localfilesystem.getLibraryEntry('flows','B').then(function(flows) {
flows.should.eql([ 'C', {fn:'flow.json'} ]);
var ft = path.join("B","D","file3");
localfilesystem.saveLibraryEntry('flows',ft,{mno:'pqr'},"Hi").then(function() {
setTimeout(function() {
localfilesystem.getLibraryEntry('flows',path.join("B","D")).then(function(flows) {
flows.should.eql([ { mno: 'pqr', fn: 'file3.json' } ]);
localfilesystem.getLibraryEntry('flows',ft+".json").then(function(body) {
body.should.eql("Hi");
done();
}).otherwise(function(err) {
done(err);
});
}).otherwise(function(err) {
done(err);
})}
, 50);
}).otherwise(function(err) {
done(err);
});
}).otherwise(function(err) {
done(err);
});
}).otherwise(function(err) {
done(err);
});
});
});