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;
10 //process.env['NODE_ENV'] = 'production';
14 describe('DB クラス', function() {
22 * @returns {promise}<保存したファイルのファイル名(uuid)をresolveする>
25 describe(constructor, function() {
35 it('should return hello when call sayHello', function() {
36 expect(db.sayHello()).to.equal('hello');
41 var getDirectoryParentId = `
43 * getDirectoryParentId
44 * ディレクトリのparentIdを取得する
46 * @returns {promise} ディレクトリが存在すればresolve(uuid), しなければreject
49 describe(getDirectoryParentId, function() {
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.');
64 it('should be resolved when \'one\' exists', function() {
65 return expect(db.getDirectoryParentId('one')).to.eventually.include.members(['1f83f620-c1ed-11e5-9657-7942989daa00']);
67 it('should be rejected when \'two\' exists', function() {
68 return expect(db.getDirectoryParentId('two')).to.eventually.have.length(2);
73 var getDirectoryId = `
78 * @returns {promise} ディレクトリが存在すればresolve(uuid), しなければreject
81 describe(getDirectoryId, function() {
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.');
96 it('should be resolved when \'/\' exists', function() {
97 return expect(db.getDirectoryId('/')).to.eventually.include.members(['1f83f620-c1ed-11e5-9657-7942989daa00']);
99 it('should be rejected when \'two\' exists', function() {
100 return expect(db.getDirectoryId('two')).to.eventually.have.length(2);
111 * @returns {promise} ディレクトリが存在すればresolve(obj), しなければreject
114 describe(getDirectoryId, function() {
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.');
129 it('should be resolved when \'/\' exists', function() {
130 return expect(db.getDirectory('/')).to.eventually.have.length(1);
132 it('should be rejected when \'two\' exists', function() {
133 return expect(db.getDirectory('two')).to.eventually.have.length(2);
142 * 同一ディレクトリに同名のファイルが存在することを確かめる
143 * @param {string}fileName
144 * @param {string}parentDirectory
148 describe(existFile, function() {
163 it('should be rejected when does not exist same name file in a directory', function() {
164 return db.existFile('hogehoge.txt', '/').should.be.rejectedWith(Error, '"hogehoge.txt" does not exist in "/" directory.');
166 it('should be rejected when a directory does not exist', function() {
167 return db.existFile('hogehoge.txt', '/hoge').should.be.rejectedWith(Error, '"/hoge" directory doesn\'t exist.');
169 it('should be resolved when file exists in a directory', function() {
170 return expect(db.existFile('hogehoge.txt', '/one')).to.eventually.be.a('string');
180 * 同一ディレクトリに同名のファイルが存在しないことを確かめる
181 * @param {string}fileName
182 * @param {string}parentDirectory
186 describe(notExistFile, function() {
201 it('should be rejected when the same name file has already existed in directory(1)', function() {
202 return db.notExistFile('hoge.txt', '/').should.be.rejectedWith(Error, '"hoge.txt" has already existed in "/" directory.');
204 it('should be rejected when the same name file has already existed in directory(2)', function() {
205 return db.notExistFile('hogehoge.txt', '/one').should.be.rejectedWith(Error, '"hogehoge.txt" has already existed in "/one" directory.');
207 it('should be resolved when the same name file does not exist in directory', function() {
208 return expect(db.notExistFile('hoge.txt', '/one')).to.eventually.equal();
213 var existDirectory = `
217 * @param {string} directory ディレクトリの絶対パス
218 * @returns {promise} ディレクトリが存在しなければresolve、すればreject
221 describe(existDirectory, function() {
233 it('should be rejected when does not exist directory', function() {
234 return db.existDirectory('/one/two/four').should.be.rejectedWith(Error, '"/one/two/four" directory doesn\'t exist.');
236 it('should be resolved when exists directory(1)', function() {
237 return expect(db.existDirectory('/')).to.eventually.equal('1f83f620-c1ed-11e5-9657-7942989daa00');
239 it('should be resolved when exists directory(2)', function() {
240 return expect(db.existDirectory('/one')).to.eventually.be.a('string');
242 it('should be resolved when exists directory(3)', function() {
243 return expect(db.existDirectory('/one/two')).to.eventually.be.a('string');
248 var notExistDirectory = `
251 * ディレクトリが存在しないことを確認する
252 * @param {string} directory
253 * @returns {promise} ディレクトリが存在すればresolve、存在しなければreject
256 describe(existDirectory, function() {
271 it('should be rejected when exists directory(1)', function() {
272 return db.notExistDirectory('/').should.be.rejectedWith(Error,'"/" directory exists.');
274 it('should be rejected when exists directory(2)', function() {
275 return db.notExistDirectory('/one').should.be.rejectedWith(Error,'"/one" directory exists.');
277 it('should be rejected when exists directory(3)', function() {
278 return db.notExistDirectory('/one/two').should.be.rejectedWith(Error,'"/one/two" directory exists.');
289 * @returns {promise}<保存したファイルのファイル名(uuid)をresolveする>
292 describe(createFile, function() {
303 return db.createFile('tarou.txt', '/');
307 it('should be rejected when "parentDirectory" doesn\'t exist', function() {
308 return db.createFile('hoge.txt', '/hoge').should.be.rejectedWith(Error, '"/hoge" directory doesn\'t exist.');
310 it('should be rejected when a file has already existed in a directory.', function() {
311 return db.createFile('hoge.txt', '/').should.be.rejectedWith(Error, '"hoge.txt" has already existed in "/" directory.');
313 it('should be resolved when file creation successed.', function() {
314 return expect(db.existFile('tarou.txt', '/')).to.eventually.be.a('string');
325 * @param {string} fileName
326 * @param {string} parentDirectory
327 * @returns {promise} ファイル削除に成功すればresolve、失敗すればreject
331 describe(removeFile, function() {
342 it('should be resolved when removeFile() successed', function() {
343 return db.removeFile('hoge.txt', '/')
345 return db.existFile('hoge.txt', '/')
347 .should.be.rejectedWith(Error, '"hoge.txt" does not exist in "/" directory.');