This repository is for zephyr, which is implemented for a GUI of Eos.
Revision | 39dd722913897f26ba90cc6d2d3af0367f4a1169 (tree) |
---|---|
Time | 2016-01-23 20:48:13 |
Author | himetani_cafe <fumifumi@yasu...> |
Commiter | himetani_cafe |
develop and test (not)existFile(), (not)existDirectory(),
@@ -40,8 +40,10 @@ function DB() { | ||
40 | 40 | sayHello: function() { |
41 | 41 | return test; |
42 | 42 | }, |
43 | - checkFile: checkFile, | |
44 | - checkDirectory: checkDirectory, | |
43 | + existFile: existFile, | |
44 | + notExistFile: notExistFile, | |
45 | + existDirectory: existDirectory, | |
46 | + notExistDirectory: notExistDirectory, | |
45 | 47 | createFile: createFile, |
46 | 48 | test1: test1, |
47 | 49 | removeFile: removeFile |
@@ -67,7 +69,7 @@ function DB() { | ||
67 | 69 | */ |
68 | 70 | function createFile(fileName,parentDirectory) { |
69 | 71 | return new Promise(function(resolve, reject) { |
70 | - Promise.all([checkFile(fileName, parentDirectory), checkDirectory(parentDirectory)]) | |
72 | + Promise.all([notExistFile(fileName, parentDirectory), existDirectory(parentDirectory)]) | |
71 | 73 | .catch(function(error) { |
72 | 74 | reject(error); |
73 | 75 | }) |
@@ -86,14 +88,44 @@ function DB() { | ||
86 | 88 | }); |
87 | 89 | } |
88 | 90 | |
91 | + | |
89 | 92 | /** |
90 | - * checkFile | |
91 | - * 同一ディレクトリに同名のファイルが存在するかどうか調べる | |
93 | + * existFile | |
94 | + * 同一ディレクトリに同名のファイルが存在することを確かめる | |
92 | 95 | * @param {string}fileName |
93 | 96 | * @param {string}parentDirectory |
94 | - * @returns {promise} | |
97 | + * @returns {promise} ファイルが存在すればresolve、存在しなければreject | |
95 | 98 | */ |
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) { | |
97 | 129 | return new Promise(function(resolve, reject) { |
98 | 130 | var q = { |
99 | 131 | where: { |
@@ -114,12 +146,12 @@ function DB() { | ||
114 | 146 | } |
115 | 147 | |
116 | 148 | /** |
117 | - * checkDirectory | |
118 | - * ディレクトリが存在するかどうか調べる | |
149 | + * existDirectory | |
150 | + * ディレクトリが存在することを確認する | |
119 | 151 | * @param {string} directory |
120 | 152 | * @returns {promise} ディレクトリが存在すればresolve、存在しなければreject |
121 | 153 | */ |
122 | - function checkDirectory(directory) { | |
154 | + function existDirectory(directory) { | |
123 | 155 | return new Promise(function(resolve, reject) { |
124 | 156 | var q = { |
125 | 157 | where: { |
@@ -138,6 +170,33 @@ function DB() { | ||
138 | 170 | }); |
139 | 171 | } |
140 | 172 | |
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 | + | |
141 | 200 | /** |
142 | 201 | * removeFile |
143 | 202 | * ファイルを削除する |
@@ -37,17 +37,45 @@ | ||
37 | 37 | }); |
38 | 38 | |
39 | 39 | |
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 | + | |
40 | 67 | |
41 | - var checkFile = ` | |
68 | + | |
69 | + var notExistFile = ` | |
42 | 70 | /** |
43 | - * checkFile | |
44 | - * 同一ディレクトリに同名のファイルが存在するかどうか調べる | |
71 | + * notExistFile | |
72 | + * 同一ディレクトリに同名のファイルが存在しないことを確かめる | |
45 | 73 | * @param {string}fileName |
46 | 74 | * @param {string}parentDirectory |
47 | 75 | * @returns {promise} |
48 | 76 | */ |
49 | 77 | `; |
50 | - describe(checkFile, function() { | |
78 | + describe(notExistFile, function() { | |
51 | 79 | var db; |
52 | 80 | before(function() { |
53 | 81 | return DB() |
@@ -60,22 +88,45 @@ | ||
60 | 88 | }); |
61 | 89 | |
62 | 90 | |
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.'); | |
65 | 93 | }); |
66 | 94 | }); |
67 | 95 | |
68 | 96 | |
69 | 97 | |
70 | - var checkDirectory = ` | |
98 | + var existDirectory = ` | |
71 | 99 | /** |
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 | + * ディレクトリが存在しないことを確認する | |
74 | 125 | * @param {string} directory |
75 | 126 | * @returns {promise} ディレクトリが存在すればresolve、存在しなければreject |
76 | 127 | */ |
77 | 128 | `; |
78 | - describe(checkDirectory, function() { | |
129 | + describe(existDirectory, function() { | |
79 | 130 | var db; |
80 | 131 | before(function() { |
81 | 132 | return DB() |
@@ -87,13 +138,11 @@ | ||
87 | 138 | }) |
88 | 139 | }); |
89 | 140 | |
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.'); | |
92 | 143 | }); |
93 | 144 | }); |
94 | 145 | |
95 | - | |
96 | - | |
97 | 146 | var createFile = ` |
98 | 147 | /** |
99 | 148 | * createFile |