3 var eos = require('../../server/class/Eos').instance;
4 var chai = require('chai');
5 var chaiAsPromised = require('chai-as-promised');
6 chai.use(chaiAsPromised);
7 var expect = chai.expect;
10 var db = require('../../server/class/DB').instance;
11 var testCommand = require('./testCommand.json');
16 * @param {string} Eosコマンドの名前
17 * @param {Array<Object>} コマンドに渡すオプション
18 * @returns {valid: boolean, message: string}
19 * function validate(command, params) {
24 describe('Eos クラス', function() {
28 describe(test1, function() {
30 it('should return Array', function() {
31 return expect(eos.getFiles()).to.eventually.be.length(2);
34 it('should be rejected(2)', function() {
35 return eos.validate('hoge').should.be.rejectedWith(Error, 'Command name is invalid');
38 it('should be rejected(3)', function() {
39 return eos.validate('mrcImageNoiseAdd').should.be.rejectedWith(Error, 'Options need to be Array');
42 it('should be rejected(4)', function() {
43 return eos.validate('mrcImageNoiseAdd', []).should.be.rejectedWith(Error, 'At least one option is required.');
46 it('should return false when options is not Array', function() {
47 return eos.validate('mrcImageNoiseAdd', {}).should.be.rejectedWith(Error, 'Options need to be Array');
50 it('should return false when options is invalid Object which have not "name" and "argumetns"', function() {
51 return eos.validate('mrcImageInfo', [{hoge: 'hoge'}]).should.be.rejectedWith(Error, 'Options need to include Object which have properties "name" and "arguments"');
53 it('should return false when "argumetns" properties are not Array', function() {
54 return eos.validate('mrcImageInfo', [{name: 'hoge', arguments: 'hoge'}]).should.be.rejectedWith(Error,'Each "arguments" properties needs to be Array');
57 it('should return false when required options do not exist', function() {
58 return eos.validate('mrcImageInfo', [{name: 'hoge', arguments: []}]).should.be.rejectedWith('Option -i are required');
61 it('should return false when required options do not exist', function() {
62 return eos.validate('dcdFilePrint', [{name: '-r', arguments: [1,2]}, { name: '-i', arguments: []}, { name: '-o', arguments: []} ]).should.be.rejectedWith(Error, 'Invalid arguments number');
65 it('should return false when input file does not exist', function() {
66 return eos.validate('dcdFilePrint', [{name: '-r', arguments: [1,2,3]}, { name: '-i', arguments: ['hoge.txt']}, { name: '-o', arguments: ['hoge.txt']} ]).should.be.rejectedWith(Error, 'hoge.txt doesn\'t exist.');
69 it('should return false when output file is not string', function() {
70 return eos.validate('dcdFilePrint', [{name: '-r', arguments: [1,2,3]}, { name: '-i', arguments: ['file1.txt']}, { name: '-o', arguments: [3]} ]).should.be.rejectedWith(Error, 'argType is invalid');
73 it('should return false when output file has already existed', function() {
74 return eos.validate('dcdFilePrint', [{name: '-r', arguments: [1,2,3]}, { name: '-i', arguments: ['file1.txt']}, { name: '-o', arguments: ['file1.txt']} ]).should.be.rejectedWith(Error, 'Invalid outfile name.');
86 * function toExecString(command, params) {
90 describe(test2, function() {
91 it('should return true when all options is proper.', function() {
92 var result = eos.toExecString('dcdFilePrint', [{name: '-r', arguments: [1,2,3]}, { name: '-i', arguments: ['file1.txt']}, { name: '-o', arguments: ['file3.txt']} ], "1f83f620-c1ed-11e5-9657-7942989daa00");
93 expect(result).to.equal('dcdFilePrint -r 1 2 3 -s 10 -e 100 -d 10 -m 0 -i /Users/Takafumi/zephyr/server/class/../../user-specific-files/workspace/file1.txt -o /Users/Takafumi/zephyr/server/class/../../user-specific-files/workspace/file3.txt');
103 * function toExecString(command, params) {
107 describe(toExecArray, function() {
109 process.env.NODE_ENV = '';
112 return Promise.all([db.test1(), db.test2(), db.testRest()])
116 it('should be resolved with length 4', function() {
117 var command = testCommand.command;
118 var options = testCommand.options;
119 var workspace = testCommand.workspace;
120 return eos.toExecArray(command, options, '1f83f620-c1ed-11e5-9657-7942989daa00').should.be.eventually.length(16);
125 describe('execute', function() {
127 process.env.NODE_ENV = '';
130 return Promise.all([db.test1(), db.test2(), db.testRest()])
134 it('should be resolved with length 4', function() {
135 return expect(eos.getFiles('1f83f620-c1ed-11e5-9657-7942989daa00')).to.eventually.length(4);
138 it('should be resolved about testCommand', function() {
139 var command = testCommand.command;
140 var options = testCommand.options;
141 var workspace = testCommand.workspace;
142 return eos.validate(command, options, workspace).should.be.fulfilled;
146 process.env.NODE_ENV = 'test';
150 describe('getFiles', function() {
152 process.env.NODE_ENV = '';
155 return Promise.all([db.test1(), db.test2(), db.testRest()])
159 it('should be resolved with length 4', function() {
160 return expect(eos.getFiles('1f83f620-c1ed-11e5-9657-7942989daa00')).to.eventually.length(4);
163 it('should be resolved about testCommand', function() {
164 var command = testCommand.command;
165 var options = testCommand.options;
166 var workspace = testCommand.workspace;
167 return eos.validate(command, options, workspace).should.be.fulfilled;
171 process.env.NODE_ENV = 'test';
177 * function getUUIDs(fileId)
178 * uuidとファイル名のkey-valueを取得
181 * @returns {object} key: filename, value: uuid
185 describe(getUUIDs, function() {
187 process.env.NODE_ENV = '';
190 return Promise.all([db.test1(), db.test2(), db.testRest()])
194 it('should be resolved', function() {
195 return eos.getUUIDs('1f83f620-c1ed-11e5-9657-7942989daa00').should.eventually.have.property("hoge.txt");