• R/O
  • HTTP
  • SSH
  • HTTPS

zephyr: Commit

This repository is for zephyr, which is implemented for a GUI of Eos.


Commit MetaInfo

Revision710a53c242bd4ab2f60416368b48aada422cf6d6 (tree)
Time2016-01-25 16:51:04
Authorhimetani_cafe <fumifumi@yasu...>
Commiterhimetani_cafe

Log Message

[Develop and Test] db.createDirectory(directory)

Change Summary

Incremental Difference

--- a/server/class/DB.js
+++ b/server/class/DB.js
@@ -162,8 +162,7 @@ function DB() {
162162 var q = {
163163 where: {
164164 name: fileName,
165- parentId: fileId,
166- fileType: 1
165+ parentId: fileId
167166 }
168167 };
169168 return Files.findOne(q)
@@ -172,7 +171,7 @@ function DB() {
172171 if(r === null) {
173172 reject(new Error("\"" + fileName + "\" does not exist in " + '"' + parentDirectory + "\" directory."));
174173 } else {
175- console.log(r.fileId);
174+ //console.log(r.fileId);
176175 resolve(r.fileId);
177176 }
178177 });
@@ -189,6 +188,7 @@ function DB() {
189188 */
190189 function notExistFile(fileName, parentDirectory) {
191190 return new Promise(function(resolve, reject) {
191+ console.log(fileName, parentDirectory);
192192 existDirectory(parentDirectory)
193193 .catch(function(error) {
194194 reject(error);
@@ -197,8 +197,7 @@ function DB() {
197197 var q = {
198198 where: {
199199 name: fileName,
200- parentId: fileId,
201- fileType: 1
200+ parentId: fileId
202201 }
203202 };
204203 return Files.findOne(q)
@@ -353,22 +352,27 @@ function DB() {
353352 /**
354353 * createDirectory
355354 *
356- * @param fileName
357- * @param parentDirectory
355+ * @param directory
358356 * @returns {promise}<sequelize.createの結果を格納したobject | Error>
359357 */
360- function createDirectory(fileName,parentDirectory) {
358+ function createDirectory(directory) {
361359 return new Promise(function(resolve, reject) {
362- Promise.all([notExistFile(fileName, parentDirectory), existDirectory(parentDirectory)])
360+ var leaf = directory.split('/').pop();
361+ var parentDirectory = directory.replace('/'+leaf, '');
362+ if(!parentDirectory) {
363+ parentDirectory = '/';
364+ }
365+ Promise.all([existDirectory(parentDirectory), notExistDirectory(directory), notExistFile(leaf, parentDirectory)])
363366 .catch(function(error) {
364367 reject(error);
365368 })
366- .then(function() {
369+ .then(function(r) {
370+ var parentId = r[0];
367371 var q = {
368372 fileId: uuid.v1(),
369- name: fileName,
370- parentDirectory: parentDirectory,
371- fileType: 1
373+ name: leaf,
374+ parentId: parentId,
375+ fileType: 0
372376 }
373377 return Files.create(q)
374378 })
--- a/test/mocha/DB.test.js
+++ b/test/mocha/DB.test.js
@@ -161,13 +161,13 @@
161161 });
162162
163163 it('should be rejected when does not exist same name file in a directory', function() {
164- return db.existFile('hogehoge.txt', '/').should.be.rejectedWith(Error, '"hogehoge.txt" does not exist in "/" directory.');
164+ return db.existFile('hogehoge.txt', '/').should.be.rejectedWith(Error, '"hogehoge.txt" does not exist in "/" directory.');
165165 });
166166 it('should be rejected when a directory does not exist', function() {
167- return db.existFile('hogehoge.txt', '/hoge').should.be.rejectedWith(Error, '"/hoge" directory doesn\'t exist.');
167+ return db.existFile('hogehoge.txt', '/hoge').should.be.rejectedWith(Error, '"/hoge" directory doesn\'t exist.');
168168 });
169169 it('should be resolved when file exists in a directory', function() {
170- return expect(db.existFile('hogehoge.txt', '/one')).to.eventually.be.a('string');
170+ return expect(db.existFile('hogehoge.txt', '/one')).to.eventually.be.a('string');
171171 });
172172
173173 });
@@ -199,13 +199,13 @@
199199 });
200200
201201 it('should be rejected when the same name file has already existed in directory(1)', function() {
202- return db.notExistFile('hoge.txt', '/').should.be.rejectedWith(Error, '"hoge.txt" has already existed in "/" directory.');
202+ return db.notExistFile('hoge.txt', '/').should.be.rejectedWith(Error, '"hoge.txt" has already existed in "/" directory.');
203203 });
204204 it('should be rejected when the same name file has already existed in directory(2)', function() {
205- return db.notExistFile('hogehoge.txt', '/one').should.be.rejectedWith(Error, '"hogehoge.txt" has already existed in "/one" directory.');
205+ return db.notExistFile('hogehoge.txt', '/one').should.be.rejectedWith(Error, '"hogehoge.txt" has already existed in "/one" directory.');
206206 });
207207 it('should be resolved when the same name file does not exist in directory', function() {
208- return expect(db.notExistFile('hoge.txt', '/one')).to.eventually.equal();
208+ return expect(db.notExistFile('hoge.txt', '/one')).to.eventually.equal();
209209 });
210210
211211 });
@@ -269,17 +269,18 @@
269269 });
270270
271271 it('should be rejected when exists directory(1)', function() {
272- return db.notExistDirectory('/').should.be.rejectedWith(Error,'"/" directory exists.');
272+ return db.notExistDirectory('/').should.be.rejectedWith(Error,'"/" directory exists.');
273273 });
274274 it('should be rejected when exists directory(2)', function() {
275- return db.notExistDirectory('/one').should.be.rejectedWith(Error,'"/one" directory exists.');
275+ return db.notExistDirectory('/one').should.be.rejectedWith(Error,'"/one" directory exists.');
276276 });
277277 it('should be rejected when exists directory(3)', function() {
278- return db.notExistDirectory('/one/two').should.be.rejectedWith(Error,'"/one/two" directory exists.');
278+ return db.notExistDirectory('/one/two').should.be.rejectedWith(Error,'"/one/two" directory exists.');
279279 });
280280
281281 });
282282
283+
283284 var createFile = `
284285 /**
285286 * createFile
@@ -305,10 +306,10 @@
305306 });
306307
307308 it('should be rejected when "parentDirectory" doesn\'t exist', function() {
308- return db.createFile('hoge.txt', '/hoge').should.be.rejectedWith(Error, '"/hoge" directory doesn\'t exist.');
309+ return db.createFile('hoge.txt', '/hoge').should.be.rejectedWith(Error, '"/hoge" directory doesn\'t exist.');
309310 });
310311 it('should be rejected when a file has already existed in a directory.', function() {
311- return db.createFile('hoge.txt', '/').should.be.rejectedWith(Error, '"hoge.txt" has already existed in "/" directory.');
312+ return db.createFile('hoge.txt', '/').should.be.rejectedWith(Error, '"hoge.txt" has already existed in "/" directory.');
312313 });
313314 it('should be resolved when file creation successed.', function() {
314315 return expect(db.existFile('tarou.txt', '/')).to.eventually.be.a('string');
@@ -316,8 +317,6 @@
316317 });
317318
318319
319-
320-
321320 var removeFile = `
322321 /**
323322 * removeFile
@@ -340,12 +339,60 @@
340339 });
341340 });
342341 it('should be resolved when removeFile() successed', function() {
343- return db.removeFile('hoge.txt', '/')
344- .then(function() {
345- return db.existFile('hoge.txt', '/')
346- })
347- .should.be.rejectedWith(Error, '"hoge.txt" does not exist in "/" directory.');
342+ return db.removeFile('hoge.txt', '/')
343+ .then(function() {
344+ return db.existFile('hoge.txt', '/')
345+ })
346+ .should.be.rejectedWith(Error, '"hoge.txt" does not exist in "/" directory.');
348347 });
349348 });
349+
350+
351+ var createDirectory = `
352+ /**
353+ * createFile
354+ *
355+ * @param directory
356+ * @returns {promise}
357+ */
358+ `;
359+ describe(createDirectory, function() {
360+ var db;
361+ before(function() {
362+ return DB()
363+ .then(function(r) {
364+ db = r;
365+ })
366+ .then(function() {
367+ return db.test1();
368+ })
369+ .then(function() {
370+ return db.test2();
371+ })
372+ .then(function() {
373+ return db.createDirectory('/one/hoge');
374+ });
375+ /*
376+ .then(function() {
377+ return db.createDirectory('/one/two/three');
378+ });
379+ */
380+ });
381+
382+ it('should be rejected when directory has already existed', function() {
383+ return db.createDirectory('/one/two').should.be.rejectedWith(Error, '"/one/two" directory exists.');
384+ });
385+ it('should be rejected when parent directory does not exist.', function() {
386+ return db.createDirectory('/four/hoge').should.be.rejectedWith(Error, '"/four" directory doesn\'t exist.');
387+ });
388+ it('should be rejected when the same name file has already existed.', function() {
389+ return db.createDirectory('/hoge.txt').should.be.rejectedWith(Error, '"hoge.txt" has already existed in "/" directory.');
390+ });
391+ it('should be rejected when the /one/hoge directory has already existed', function() {
392+ return db.notExistDirectory('/one/hoge').should.be.rejectedWith(Error, '"/one/hoge" directory exists.');
393+ });
394+
395+ });
396+
350397 });
351398 })();
Show on old repository browser