• R/O
  • HTTP
  • SSH
  • HTTPS

zephyr: Commit

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


Commit MetaInfo

Revisionb89607d54c6171fdd526463d303cbabd328c8ef5 (tree)
Time2016-01-23 23:44:04
Authorhimetani_cafe <fumifumi@yasu...>
Commiterhimetani_cafe

Log Message

[Develop & Test] removeFile()

Change Summary

Incremental Difference

--- a/server/class/DB.js
+++ b/server/class/DB.js
@@ -107,7 +107,6 @@ function DB() {
107107 };
108108 Files.findOne(q)
109109 .then(function(r) {
110- console.log(r);
111110 if(r === null) {
112111 reject(new Error("\"" + fileName + "\" does not exist in " + '"' + parentDirectory + "\" directory."));
113112 } else {
@@ -205,19 +204,24 @@ function DB() {
205204 * @returns {promise} ファイル削除に成功すればresolve、失敗すればreject
206205 */
207206 function removeFile(fileName, parentDirectory) {
208- return new Promise(function(resolve, reject) {
209- var q = {
210- where: {
211- name: fileName,
212- parentDirectory: parentDirectory
213- }
214- };
215-
216- Files.destroy(q)
217- .then(function() {
218- resolve();
219- });
220- });
207+ return new Promise(function(resolve, reject) {
208+ existFile(fileName, parentDirectory)
209+ .catch(function(error) {
210+ reject(error);
211+ })
212+ .then(function() {
213+ var q = {
214+ where: {
215+ name: fileName,
216+ parentDirectory: parentDirectory
217+ }
218+ };
219+ return Files.destroy(q);
220+ })
221+ .then(function() {
222+ resolve();
223+ });
224+ });
221225 }
222226
223227 /**
--- a/test/mocha/DB.test.js
+++ b/test/mocha/DB.test.js
@@ -170,7 +170,6 @@
170170 it('should be rejected when a file has already existed in a directory.', function() {
171171 return db.createFile('hoge.txt', '/').should.be.rejectedWith(Error, '"hoge.txt" has already existed in "/" directory.');
172172 });
173-
174173 });
175174
176175
@@ -186,7 +185,7 @@
186185 */
187186 `;
188187
189- describe(createFile, function() {
188+ describe(removeFile, function() {
190189 var db;
191190 before(function() {
192191 return DB()
@@ -195,15 +194,15 @@
195194 })
196195 .then(function() {
197196 return db.test1();
198- })
199- .then(function() {
200- return db.removeFile('hoge.txt', '/');
201197 });
202198 });
203199 it('should be resolved when removeFile() successed', function() {
204- return db.createFile('hoge.txt', '/').should.eventually.be.a('string');
200+ return db.removeFile('hoge.txt', '/')
201+ .then(function() {
202+ return db.existFile('hoge.txt', '/')
203+ })
204+ .should.be.rejectedWith(Error, '"hoge.txt" does not exist in "/" directory.');
205205 });
206-
207206 });
208207 });
209208 })();
Show on old repository browser