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() {
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.');
172 * 同一ディレクトリに同名のファイルが存在しないことを確かめる
173 * @param {string}fileName
174 * @param {string}parentDirectory
178 describe(notExistFile, function() {
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.');
200 var existDirectory = `
204 * @param {string} directory ディレクトリの絶対パス
205 * @returns {promise} ディレクトリが存在しなければresolve、すればreject
208 describe(existDirectory, function() {
220 it('should be resolved when a directory exists.', function() {
221 return expect(db.existDirectory('/one/two')).to.eventually.equal('/one/two');
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.');
228 it('should be resolveed when exists directory(1)', function() {
229 return expect(db.existDirectory('/')).to.eventually.equal('/');
231 it('should be resolveed when exists directory(2)', function() {
232 return db.existDirectory('/one').should.be.rejectedWith(Error, '"hage" directory doesn\'t exist.');
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.');
242 var notExistDirectory = `
245 * ディレクトリが存在しないことを確認する
246 * @param {string} directory
247 * @returns {promise} ディレクトリが存在すればresolve、存在しなければreject
250 describe(existDirectory, function() {
263 it('should be rejected when exists directory', function() {
264 return db.notExistDirectory('/').should.be.rejectedWith(Error,'"/" directory exists.');
275 * @returns {promise}<保存したファイルのファイル名(uuid)をresolveする>
278 describe(createFile, function() {
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.');
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.');
307 * @param {string} fileName
308 * @param {string} parentDirectory
309 * @returns {promise} ファイル削除に成功すればresolve、失敗すればreject
313 describe(removeFile, function() {
325 it('should be resolved when removeFile() successed', function() {
326 return db.removeFile('hoge.txt', '/')
328 return db.existFile('hoge.txt', '/')
330 .should.be.rejectedWith(Error, '"hoge.txt" does not exist in "/" directory.');