OSDN Git Service

[Develop & Test] removeFile()
[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             it('should return hello when call sayHello', function() {
35                 expect(db.sayHello()).to.equal('hello');
36             });
37         });
38
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
67
68
69         var notExistFile = `
70         /**
71         * notExistFile
72         * 同一ディレクトリに同名のファイルが存在しないことを確かめる
73         * @param {string}fileName
74         * @param {string}parentDirectory
75         * @returns {promise}
76         */
77         `;
78         describe(notExistFile, function() {
79             var db;
80             before(function() {
81                 return DB()
82                 .then(function(r) {
83                     db = r;
84                 })
85                 .then(function() {
86                     return db.test1();
87                 })
88             });
89
90
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.');
93             });
94         });
95
96
97
98         var existDirectory = `
99         /**
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         * ディレクトリが存在しないことを確認する
125         * @param {string} directory
126         * @returns {promise} ディレクトリが存在すればresolve、存在しなければreject
127         */
128         `;
129         describe(existDirectory, function() {
130             var db;
131             before(function() {
132                 return DB()
133                 .then(function(r) {
134                     db = r;
135                 })
136                 .then(function() {
137                     return db.test1();
138                 })
139             });
140
141             it('should be rejected when exists directory', function() {
142                 return db.notExistDirectory('/').should.be.rejectedWith(Error,'"/" directory exists.');
143             });
144         });
145
146         var createFile = `
147         /**
148         * createFile
149         *
150         * @param name
151         * @param directory
152         * @returns {promise}<保存したファイルのファイル名(uuid)をresolveする>
153         */
154         `;
155         describe(createFile, function() {
156             var db;
157             before(function() {
158                 return DB()
159                 .then(function(r) {
160                     db = r;
161                 })
162                 .then(function() {
163                     return db.test1();
164                 })
165             });
166
167             it('should be rejected when "parentDirectory" doesn\'t exist', function() {
168                 return db.createFile('hoge.txt', 'hoge').should.be.rejectedWith(Error, '"hoge" directory doesn\'t exist.');
169             });
170             it('should be rejected when a file has already existed in a directory.', function() {
171                 return db.createFile('hoge.txt', '/').should.be.rejectedWith(Error, '"hoge.txt" has already existed in "/" directory.');
172             });
173         });
174
175
176
177
178         var removeFile = `
179         /**
180         * removeFile
181         * ファイルを削除する
182         * @param {string} fileName
183         * @param {string} parentDirectory
184         * @returns {promise} ファイル削除に成功すればresolve、失敗すればreject
185         */
186         `;
187
188         describe(removeFile, function() {
189             var db;
190             before(function() {
191                 return DB()
192                 .then(function(r) {
193                     db = r;
194                 })
195                 .then(function() {
196                     return db.test1();
197                 });
198             });
199             it('should be resolved when removeFile() successed', function() {
200                 return db.removeFile('hoge.txt', '/')
201                 .then(function() {
202                     return db.existFile('hoge.txt', '/')
203                 })
204                 .should.be.rejectedWith(Error, '"hoge.txt" does not exist in "/" directory.');
205             });
206         });
207     });
208 })();