• R/O
  • HTTP
  • SSH
  • HTTPS

zephyr: Commit

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


Commit MetaInfo

Revision39dd722913897f26ba90cc6d2d3af0367f4a1169 (tree)
Time2016-01-23 20:48:13
Authorhimetani_cafe <fumifumi@yasu...>
Commiterhimetani_cafe

Log Message

develop and test (not)existFile(), (not)existDirectory(),

Change Summary

Incremental Difference

--- a/server/class/DB.js
+++ b/server/class/DB.js
@@ -40,8 +40,10 @@ function DB() {
4040 sayHello: function() {
4141 return test;
4242 },
43- checkFile: checkFile,
44- checkDirectory: checkDirectory,
43+ existFile: existFile,
44+ notExistFile: notExistFile,
45+ existDirectory: existDirectory,
46+ notExistDirectory: notExistDirectory,
4547 createFile: createFile,
4648 test1: test1,
4749 removeFile: removeFile
@@ -67,7 +69,7 @@ function DB() {
6769 */
6870 function createFile(fileName,parentDirectory) {
6971 return new Promise(function(resolve, reject) {
70- Promise.all([checkFile(fileName, parentDirectory), checkDirectory(parentDirectory)])
72+ Promise.all([notExistFile(fileName, parentDirectory), existDirectory(parentDirectory)])
7173 .catch(function(error) {
7274 reject(error);
7375 })
@@ -86,14 +88,44 @@ function DB() {
8688 });
8789 }
8890
91+
8992 /**
90- * checkFile
91- * 同一ディレクトリに同名のファイルが存在するかどうか調べる
93+ * existFile
94+ * 同一ディレクトリに同名のファイルが存在することを確かめる
9295 * @param {string}fileName
9396 * @param {string}parentDirectory
94- * @returns {promise}
97+ * @returns {promise} ファイルが存在すればresolve、存在しなければreject
9598 */
96- function checkFile(fileName, parentDirectory) {
99+ function existFile(fileName, parentDirectory) {
100+ return new Promise(function(resolve, reject) {
101+ var q = {
102+ where: {
103+ name: fileName,
104+ parentDirectory: parentDirectory,
105+ fileType: 1
106+ }
107+ };
108+ Files.findOne(q)
109+ .then(function(r) {
110+ console.log(r);
111+ if(r === null) {
112+ reject(new Error("\"" + fileName + "\" does not exist in " + '"' + parentDirectory + "\" directory."));
113+ } else {
114+ resolve();
115+ }
116+ });
117+ });
118+ }
119+
120+
121+ /**
122+ * notExistFile
123+ * 同一ディレクトリに同名のファイルが存在していないことを確かめる
124+ * @param {string}fileName
125+ * @param {string}parentDirectory
126+ * @returns {promise} ファイルが存在しなければresolve、存在すればreject
127+ */
128+ function notExistFile(fileName, parentDirectory) {
97129 return new Promise(function(resolve, reject) {
98130 var q = {
99131 where: {
@@ -114,12 +146,12 @@ function DB() {
114146 }
115147
116148 /**
117- * checkDirectory
118- * ディレクトリが存在するかどうか調べる
149+ * existDirectory
150+ * ディレクトリが存在することを確認する
119151 * @param {string} directory
120152 * @returns {promise} ディレクトリが存在すればresolve、存在しなければreject
121153 */
122- function checkDirectory(directory) {
154+ function existDirectory(directory) {
123155 return new Promise(function(resolve, reject) {
124156 var q = {
125157 where: {
@@ -138,6 +170,33 @@ function DB() {
138170 });
139171 }
140172
173+
174+ /**
175+ * notExistDirectory
176+ * ディレクトリが存在しないことを確認する
177+ * @param {string} directory
178+ * @returns {promise} ディレクトリが存在しなければresolve、存在すればreject
179+ */
180+ function notExistDirectory(directory) {
181+ return new Promise(function(resolve, reject) {
182+ var q = {
183+ where: {
184+ name: directory,
185+ fileType: 0
186+ }
187+ };
188+ Files.findOne(q)
189+ .then(function(r) {
190+ if(r === null) {
191+ resolve();
192+ } else {
193+ reject(new Error('"' + directory + '" directory exists.'));
194+ }
195+ });
196+ });
197+ }
198+
199+
141200 /**
142201 * removeFile
143202 * ファイルを削除する
--- a/test/mocha/DB.test.js
+++ b/test/mocha/DB.test.js
@@ -37,17 +37,45 @@
3737 });
3838
3939
40+ var existFile = `
41+ /**
42+ * existFile
43+ * 同一ディレクトリに同名のファイルが存在することを確かめる
44+ * @param {string}fileName
45+ * @param {string}parentDirectory
46+ * @returns {promise}
47+ */
48+ `;
49+ describe(existFile, function() {
50+ var db;
51+ before(function() {
52+ return DB()
53+ .then(function(r) {
54+ db = r;
55+ })
56+ .then(function() {
57+ return db.test1();
58+ })
59+ });
60+
61+
62+ it('should be rejected when does not exist same name file in a directory', function() {
63+ return db.existFile('hogehoge.txt', '/').should.be.rejectedWith(Error, '"hogehoge.txt" does not exist in "/" directory.');
64+ });
65+ });
66+
4067
41- var checkFile = `
68+
69+ var notExistFile = `
4270 /**
43- * checkFile
44- * 同一ディレクトリに同名のファイルが存在するかどうか調べる
71+ * notExistFile
72+ * 同一ディレクトリに同名のファイルが存在しないことを確かめる
4573 * @param {string}fileName
4674 * @param {string}parentDirectory
4775 * @returns {promise}
4876 */
4977 `;
50- describe(checkFile, function() {
78+ describe(notExistFile, function() {
5179 var db;
5280 before(function() {
5381 return DB()
@@ -60,22 +88,45 @@
6088 });
6189
6290
63- it('should be rejected when have the same name file in a directory', function() {
64- return db.checkFile('hoge.txt', '/').should.be.rejected;
91+ it('should be rejected when exist the same name file in a directory', function() {
92+ return db.notExistFile('hoge.txt', '/').should.be.rejectedWith(Error, '"hoge.txt" has already existed in "/" directory.');
6593 });
6694 });
6795
6896
6997
70- var checkDirectory = `
98+ var existDirectory = `
7199 /**
72- * checkDirectory
73- *
100+ * existDirectory
101+ * ディレクトリが存在することを確認する
102+ * @param {string} directory
103+ * @returns {promise} ディレクトリが存在しなければresolve、すればreject
104+ */
105+ `;
106+ describe(existDirectory, function() {
107+ var db;
108+ before(function() {
109+ return DB()
110+ .then(function(r) {
111+ db = r;
112+ })
113+ });
114+
115+ it('should be rejected when does not exist directory', function() {
116+ return db.existDirectory('hage').should.be.rejectedWith(Error, '"hage" directory doesn\'t exist.');
117+ });
118+ });
119+
120+
121+ var notExistDirectory = `
122+ /**
123+ * notExistDirectory
124+ * ディレクトリが存在しないことを確認する
74125 * @param {string} directory
75126 * @returns {promise} ディレクトリが存在すればresolve、存在しなければreject
76127 */
77128 `;
78- describe(checkDirectory, function() {
129+ describe(existDirectory, function() {
79130 var db;
80131 before(function() {
81132 return DB()
@@ -87,13 +138,11 @@
87138 })
88139 });
89140
90- it('should be rejected when have the same name file in a directory', function() {
91- return db.checkDirectory('hage').should.be.rejected;
141+ it('should be rejected when exists directory', function() {
142+ return db.notExistDirectory('/').should.be.rejectedWith(Error,'"/" directory exists.');
92143 });
93144 });
94145
95-
96-
97146 var createFile = `
98147 /**
99148 * createFile
Show on old repository browser