OSDN Git Service

[DEBUG] db.existDirectory() modify to search recursively.
[eos/zephyr.git] / test / mocha / DB.test.js
1 (function() {
2     'use strict';
3     var DB = require('../../server/class/DB');
4     var chai = require('chai');
5     var chaiAsPromised = require('chai-as-promised');
6     chai.use(chaiAsPromised);
7     var expect = chai.expect;
8     chai.should();
9
10     //process.env['NODE_ENV'] = 'production';
11
12
13
14     describe('DB クラス', function() {
15
16         var constructor = `
17         /**
18         * createFile
19         *
20         * @param name
21         * @param directory
22         * @returns {promise}<保存したファイルのファイル名(uuid)をresolveする>
23         */
24         `;
25         describe(constructor, function() {
26             var db;
27             before(function() {
28                 return DB()
29                 .then(function(r) {
30                     db = r;
31                 });
32             });
33
34
35             it('should return hello when call sayHello', function() {
36                 expect(db.sayHello()).to.equal('hello');
37             });
38         });
39
40
41         var getDirectoryParentId = `
42         /**
43         * getDirectoryParentId
44         * ディレクトリのparentIdを取得する 
45         * @param name
46         * @returns {promise} ディレクトリが存在すればresolve(uuid), しなければreject
47         */
48         `;
49         describe(getDirectoryParentId, function() {
50             var db;
51             before(function() {
52                 return DB()
53                 .then(function(r) {
54                     db = r;
55                 })
56                 .then(function() {
57                     return db.test2();
58                 });
59             });
60
61             it('should be rejected when a directory does not exist', function() {
62                 return db.getDirectoryParentId('hoge').should.be.rejectedWith(Error, '"hoge" directory doesn\'t exist.');
63             });
64             it('should be resolved when \'one\' exists', function() {
65                 return expect(db.getDirectoryParentId('one')).to.eventually.include.members(['1f83f620-c1ed-11e5-9657-7942989daa00']);
66             });
67             it('should be rejected when \'two\' exists', function() {
68                 return expect(db.getDirectoryParentId('two')).to.eventually.have.length(2);
69             });
70
71         });
72
73         var getDirectoryId = `
74         /**
75         * getDirectoryId
76         * ディレクトリのfileIdを取得する 
77         * @param name
78         * @returns {promise} ディレクトリが存在すればresolve(uuid), しなければreject
79         */
80         `;
81         describe(getDirectoryId, function() {
82             var db;
83             before(function() {
84                 return DB()
85                 .then(function(r) {
86                     db = r;
87                 })
88                 .then(function() {
89                     return db.test2();
90                 });
91             });
92
93             it('should be rejected when a directory does not exist', function() {
94                 return db.getDirectoryId('hoge').should.be.rejectedWith(Error, '"hoge" directory doesn\'t exist.');
95             });
96             it('should be resolved when \'/\' exists', function() {
97                 return expect(db.getDirectoryId('/')).to.eventually.include.members(['1f83f620-c1ed-11e5-9657-7942989daa00']);
98             });
99             it('should be rejected when \'two\' exists', function() {
100                 return expect(db.getDirectoryId('two')).to.eventually.have.length(2);
101             });
102
103         });
104
105
106         var getDirectory = `
107         /**
108         * getDirectory
109         * ディレクトリの情報を取得する 
110         * @param name
111         * @returns {promise} ディレクトリが存在すればresolve(obj), しなければreject
112         */
113         `;
114         describe(getDirectoryId, function() {
115             var db;
116             before(function() {
117                 return DB()
118                 .then(function(r) {
119                     db = r;
120                 })
121                 .then(function() {
122                     return db.test2();
123                 });
124             });
125
126             it('should be rejected when a directory does not exist', function() {
127                 return db.getDirectoryId('hoge').should.be.rejectedWith(Error, '"hoge" directory doesn\'t exist.');
128             });
129             it('should be resolved when \'/\' exists', function() {
130                 return expect(db.getDirectory('/')).to.eventually.have.length(1);
131             });
132             it('should be rejected when \'two\' exists', function() {
133                 return expect(db.getDirectory('two')).to.eventually.have.length(2);
134             });
135
136         });
137
138
139         var existFile = `
140         /**
141         * existFile
142         * 同一ディレクトリに同名のファイルが存在することを確かめる
143         * @param {string}fileName
144         * @param {string}parentDirectory
145         * @returns {promise}
146         */
147         `;
148         describe(existFile, function() {
149             var db;
150             before(function() {
151                 return DB()
152                 .then(function(r) {
153                     db = r;
154                 })
155                 .then(function() {
156                     return db.test1();
157                 })
158             });
159
160             /*
161                it('should be rejected when does not exist same name file in a directory', function() {
162                return db.existFile('hogehoge.txt', '/').should.be.rejectedWith(Error, '"hogehoge.txt" does not exist in "/" directory.');
163                });
164                */
165         });
166
167
168
169         var notExistFile = `
170         /**
171         * notExistFile
172         * 同一ディレクトリに同名のファイルが存在しないことを確かめる
173         * @param {string}fileName
174         * @param {string}parentDirectory
175         * @returns {promise}
176         */
177         `;
178         describe(notExistFile, function() {
179             var db;
180             before(function() {
181                 return DB()
182                 .then(function(r) {
183                     db = r;
184                 })
185                 .then(function() {
186                     return db.test1();
187                 })
188             });
189
190
191             /*
192                it('should be rejected when exist the same name file in a directory', function() {
193                return db.notExistFile('hoge.txt', '/').should.be.rejectedWith(Error, '"hoge.txt" has already existed in "/" directory.');
194                });
195                */
196         });
197
198
199
200         var existDirectory = `
201         /**
202         * existDirectory
203         * ディレクトリが存在することを確認する
204         * @param {string} directory ディレクトリの絶対パス
205         * @returns {promise} ディレクトリが存在しなければresolve、すればreject
206         */
207         `;
208         describe(existDirectory, function() {
209             var db;
210             before(function() {
211                 return DB()
212                 .then(function(r) {
213                     db = r;
214                 })
215                 .then(function() {
216                     return db.test2();
217                 })
218             });
219
220             it('should be resolved when a directory exists.', function() {
221                return expect(db.existDirectory('/one/two')).to.eventually.equal('/one/two');
222             });
223             it('should be rejected when does not exist directory', function() {
224                return db.existDirectory('/one/two/four').should.be.rejectedWith(Error, '"/one/two/four" directory doesn\'t exist.');
225             });
226
227             /*
228                it('should be resolveed when exists directory(1)', function() {
229                return expect(db.existDirectory('/')).to.eventually.equal('/');
230                });
231                it('should be resolveed when exists directory(2)', function() {
232                return db.existDirectory('/one').should.be.rejectedWith(Error, '"hage" directory doesn\'t exist.');
233                });
234                it('should be resolveed when exists directory(3)', function() {
235                return db.existDirectory('/one/two').should.be.rejectedWith(Error, '"hage" directory doesn\'t exist.');
236                });
237                */
238
239         });
240
241
242         var notExistDirectory = `
243         /**
244         * notExistDirectory
245         * ディレクトリが存在しないことを確認する
246         * @param {string} directory
247         * @returns {promise} ディレクトリが存在すればresolve、存在しなければreject
248         */
249         `;
250         describe(existDirectory, function() {
251             var db;
252             before(function() {
253                 return DB()
254                 .then(function(r) {
255                     db = r;
256                 })
257                 .then(function() {
258                     return db.test1();
259                 })
260             });
261
262             /*
263                it('should be rejected when exists directory', function() {
264                return db.notExistDirectory('/').should.be.rejectedWith(Error,'"/" directory exists.');
265                });
266                */
267         });
268
269         var createFile = `
270         /**
271         * createFile
272         *
273         * @param name
274         * @param directory
275         * @returns {promise}<保存したファイルのファイル名(uuid)をresolveする>
276         */
277         `;
278         describe(createFile, function() {
279             var db;
280             before(function() {
281                 return DB()
282                 .then(function(r) {
283                     db = r;
284                 })
285                 .then(function() {
286                     return db.test1();
287                 })
288             });
289
290             /*
291                it('should be rejected when "parentDirectory" doesn\'t exist', function() {
292                return db.createFile('hoge.txt', 'hoge').should.be.rejectedWith(Error, '"hoge" directory doesn\'t exist.');
293                });
294                it('should be rejected when a file has already existed in a directory.', function() {
295                return db.createFile('hoge.txt', '/').should.be.rejectedWith(Error, '"hoge.txt" has already existed in "/" directory.');
296                });
297                */
298         });
299
300
301
302
303         var removeFile = `
304         /**
305         * removeFile
306         * ファイルを削除する
307         * @param {string} fileName
308         * @param {string} parentDirectory
309         * @returns {promise} ファイル削除に成功すればresolve、失敗すればreject
310         */
311         `;
312
313         describe(removeFile, function() {
314             var db;
315             before(function() {
316                 return DB()
317                 .then(function(r) {
318                     db = r;
319                 })
320                 .then(function() {
321                     return db.test1();
322                 });
323             });
324             /*
325                it('should be resolved when removeFile() successed', function() {
326                return db.removeFile('hoge.txt', '/')
327                .then(function() {
328                return db.existFile('hoge.txt', '/')
329                })
330                .should.be.rejectedWith(Error, '"hoge.txt" does not exist in "/" directory.');
331                });
332                */
333         });
334     });
335 })();