3 var db = require('../../server/class/DB').instance;
4 var chai = require('chai');
5 var chaiAsPromised = require('chai-as-promised');
6 chai.use(chaiAsPromised);
7 var expect = chai.expect;
10 describe('DB クラス', function() {
18 * @returns {promise}<保存したファイルのファイル名(uuid)をresolveする>
21 describe(constructor, function() {
25 it('should return hello when call sayHello', function() {
26 expect(db.sayHello()).to.equal('hello');
31 var getDirectoryParentId = `
33 * getDirectoryParentId
34 * ディレクトリのparentIdを取得する
36 * @returns {promise} ディレクトリが存在すればresolve(uuid), しなければreject
39 describe(getDirectoryParentId, function() {
47 it('should be rejected when a directory does not exist', function() {
48 return db.getDirectoryParentId('hoge').should.be.rejectedWith(Error, '"hoge" directory doesn\'t exist.');
50 it('should be resolved when \'one\' exists', function() {
51 return expect(db.getDirectoryParentId('one')).to.eventually.include.members(['1f83f620-c1ed-11e5-9657-7942989daa00']);
53 it('should be rejected when \'two\' exists', function() {
54 return expect(db.getDirectoryParentId('two')).to.eventually.have.length(2);
58 var getDirectoryId = `
63 * @returns {promise} ディレクトリが存在すればresolve(uuid), しなければreject
66 describe(getDirectoryId, function() {
73 it('should be rejected when a directory does not exist', function() {
74 return db.getDirectoryId('hoge').should.be.rejectedWith(Error, '"hoge" directory doesn\'t exist.');
76 it('should be resolved when \'/\' exists', function() {
77 return expect(db.getDirectoryId('/')).to.eventually.include.members(['1f83f620-c1ed-11e5-9657-7942989daa00']);
79 it('should be rejected when \'two\' exists', function() {
80 return expect(db.getDirectoryId('two')).to.eventually.have.length(2);
90 * @returns {promise} ディレクトリが存在すればresolve(obj), しなければreject
93 describe(getDirectory, function() {
101 it('should be rejected when a directory does not exist', function() {
102 return db.getDirectoryId('hoge').should.be.rejectedWith(Error, '"hoge" directory doesn\'t exist.');
104 it('should be resolved when \'/\' exists', function() {
105 return expect(db.getDirectory('/')).to.eventually.have.length(1);
107 it('should be rejected when \'two\' exists', function() {
108 return expect(db.getDirectory('two')).to.eventually.have.length(2);
116 * 同一ディレクトリに同名のファイルが存在することを確かめる
117 * @param {string}fileName
118 * @param {string}parentDirectory
122 describe(existFile, function() {
133 it('should be rejected when does not exist same name file in a directory', function() {
134 return db.existFile('hogehoge.txt', '/').should.be.rejectedWith(Error, '"hogehoge.txt" does not exist in "/" directory.');
136 it('should be rejected when a directory does not exist', function() {
137 return db.existFile('hogehoge.txt', '/hoge').should.be.rejectedWith(Error, '"/hoge" directory doesn\'t exist.');
139 it('should be resolved when file exists in a directory', function() {
140 return expect(db.existFile('hogehoge.txt', '/one')).to.eventually.be.a('string');
149 * 同一ディレクトリに同名のファイルが存在しないことを確かめる
150 * @param {string}fileName
151 * @param {string}parentDirectory
155 describe(notExistFile, function() {
166 it('should be rejected when the same name file has already existed in directory(1)', function() {
167 return db.notExistFile('hoge.txt', '/').should.be.rejectedWith(Error, '"hoge.txt" has already existed in "/" directory.');
169 it('should be rejected when the same name file has already existed in directory(2)', function() {
170 return db.notExistFile('hogehoge.txt', '/one').should.be.rejectedWith(Error, '"hogehoge.txt" has already existed in "/one" directory.');
172 it('should be resolved when the same name file does not exist in directory', function() {
173 return expect(db.notExistFile('hoge.txt', '/one')).to.eventually.equal();
177 var existDirectory = `
181 * @param {string} directory ディレクトリの絶対パス
182 * @returns {promise} ディレクトリが存在しなければresolve、すればreject
185 describe(existDirectory, function() {
193 it('should be rejected when does not exist directory(1)', function() {
194 return db.existDirectory('/one/two/four').should.be.rejectedWith(Error, '"/one/two/four" directory doesn\'t exist.');
196 it('should be rejected when does not exist directory(2)', function() {
197 return db.existDirectory('hoge').should.be.rejectedWith(Error, 'directory name should start "/" so that it is absolute path including root.');
199 it('should be resolved when exists directory(1)', function() {
200 return expect(db.existDirectory('/')).to.eventually.equal('1f83f620-c1ed-11e5-9657-7942989daa00');
202 it('should be resolved when exists directory(2)', function() {
203 return expect(db.existDirectory('/one')).to.eventually.be.a('string');
205 it('should be resolved when exists directory(3)', function() {
206 return expect(db.existDirectory('/one/two')).to.eventually.be.a('string');
208 it('should be rejected when call with no parameter', function() {
209 return db.existDirectory().should.be.rejectedWith(Error, 'parameter "directory" is undefined');
214 var notExistDirectory = `
217 * ディレクトリが存在しないことを確認する
218 * @param {string} directory
219 * @returns {promise} ディレクトリが存在すればresolve、存在しなければreject
222 describe(existDirectory, function() {
233 it('should be rejected when exists directory(1)', function() {
234 return db.notExistDirectory('/').should.be.rejectedWith(Error,'"/" directory exists.');
236 it('should be rejected when exists directory(2)', function() {
237 return db.notExistDirectory('/one').should.be.rejectedWith(Error,'"/one" directory exists.');
239 it('should be rejected when exists directory(3)', function() {
240 return db.notExistDirectory('/one/two').should.be.rejectedWith(Error,'"/one/two" directory exists.');
242 it('should be resolved(1)', function() {
243 return expect(db.notExistDirectory()).to.eventually.equal();
245 it('should be resolved(2)', function() {
246 return expect(db.notExistDirectory('hoge')).to.eventually.equal();
257 * @returns {promise}<保存したファイルのファイル名(uuid)をresolveする>
260 describe(createFile, function() {
267 return db.createFile('tarou.txt', '/');
271 it('should be rejected when "parentDirectory" doesn\'t exist', function() {
272 return db.createFile('hoge.txt', '/hoge').should.be.rejectedWith(Error, '"/hoge" directory doesn\'t exist.');
274 it('should be rejected when a file has already existed in a directory.', function() {
275 return db.createFile('hoge.txt', '/').should.be.rejectedWith(Error, '"hoge.txt" has already existed in "/" directory.');
277 it('should be resolved when file creation successed.', function() {
278 return expect(db.existFile('tarou.txt', '/')).to.eventually.be.a('string');
280 it('should be rejected(1)', function() {
281 return db.createFile().should.be.rejectedWith(Error, 'filename is required.');
283 it('should be rejected(2)', function() {
284 return db.createFile('hoge.txt', '').should.be.rejectedWith(Error, 'parameter "directory" is undefined');
286 it('should be rejected(3)', function() {
287 return db.createFile(null, '/').should.be.rejectedWith(Error, 'filename is required.');
296 * @param {string} fileName
297 * @param {string} parentDirectory
298 * @returns {promise} ファイル削除に成功すればresolve、失敗すればreject
302 describe(removeFile, function() {
309 it('should be resolved when removeFile() successed', function() {
310 return db.removeFile('hoge.txt', '/')
312 return db.existFile('hoge.txt', '/')
314 .should.be.rejectedWith(Error, '"hoge.txt" does not exist in "/" directory.');
319 var createDirectory = `
327 describe(createDirectory, function() {
337 return db.createDirectory('/one/hoge');
341 it('should be rejected when directory has already existed', function() {
342 return db.createDirectory('/one/two').should.be.rejectedWith(Error, '"/one/two" directory exists.');
344 it('should be rejected when parent directory does not exist.', function() {
345 return db.createDirectory('/four/hoge').should.be.rejectedWith(Error, '"/four" directory doesn\'t exist.');
347 it('should be rejected when the same name file has already existed.', function() {
348 return db.createDirectory('/hoge.txt').should.be.rejectedWith(Error, '"hoge.txt" has already existed in "/" directory.');
350 it('should be rejected when the /one/hoge directory has already existed', function() {
351 return db.notExistDirectory('/one/hoge').should.be.rejectedWith(Error, '"/one/hoge" directory exists.');
353 it('should be rejected(1)', function() {
354 return db.createDirectory('hoge').should.be.rejectedWith(Error, 'directory name should start "/" so that it is absolute path including root.');
356 it('should be rejected(2)', function() {
357 return db.createDirectory().should.be.rejectedWith(Error, 'directory name should start "/" so that it is absolute path including root.');
365 * @param {string} fileId ディレクトリのfileId
366 * @returns {promise} resolve([Array]<string>fileId) 引数で与えられたディレクトリを直接の親に持つファイルのレコードの配列を返す。
369 describe(createDirectory, function() {
380 it('should be rejected when calling with invalid fileId', function() {
381 return db.getFiles('').should.be.rejected;
383 it('should be resolved(1)', function() {
384 return expect(db.getFiles('1f83f620-c1ed-11e5-9657-7942989daa00')).to.eventually.be.an('array');
386 it('should be resolved(2)', function() {
387 return expect(db.getFiles('1f83f620-c1ed-11e5-9657-7942989daa04')).to.eventually.be.length(2);
391 var getDirectories = `
395 * @param {string} fileId ディレクトリのfileId
396 * @returns {promise} resolve([Array]<string>fileId) 引数で与えられたディレクトリを直接の親に持つファイルのレコードの配列を返す。
399 describe(createDirectory, function() {
410 it('should be resolved', function() {
411 return expect(db.getDirectories()).to.eventually.be.length(4);