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) {
30 * function toExecString(command, params) {
34 describe('Eos クラス', function() {
38 describe(test1, function() {
40 it('should return Array', function() {
41 return expect(eos.getFiles()).to.eventually.be.length(2);
44 it('should be rejected(2)', function() {
45 return eos.validate('hoge').should.be.rejectedWith(Error, 'Command name is invalid');
48 it('should be rejected(3)', function() {
49 return eos.validate('mrcImageNoiseAdd').should.be.rejectedWith(Error, 'Options need to be Array');
52 it('should be rejected(4)', function() {
53 return eos.validate('mrcImageNoiseAdd', []).should.be.rejectedWith(Error, 'At least one option is required.');
56 it('should return false when options is not Array', function() {
57 return eos.validate('mrcImageNoiseAdd', {}).should.be.rejectedWith(Error, 'Options need to be Array');
60 it('should return false when options is invalid Object which have not "name" and "argumetns"', function() {
61 return eos.validate('mrcImageInfo', [{hoge: 'hoge'}]).should.be.rejectedWith(Error, 'Options need to include Object which have properties "name" and "arguments"');
63 it('should return false when "argumetns" properties are not Array', function() {
64 return eos.validate('mrcImageInfo', [{name: 'hoge', arguments: 'hoge'}]).should.be.rejectedWith(Error,'Each "arguments" properties needs to be Array');
67 it('should return false when required options do not exist', function() {
68 return eos.validate('mrcImageInfo', [{name: 'hoge', arguments: []}]).should.be.rejectedWith('Option -i are required');
71 it('should return false when required options do not exist', function() {
72 return eos.validate('dcdFilePrint', [{name: '-r', arguments: [1,2]}, { name: '-i', arguments: []}, { name: '-o', arguments: []} ]).should.be.rejectedWith(Error, 'Invalid arguments number');
75 it('should return false when input file does not exist', function() {
76 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.');
79 it('should return false when output file is not string', function() {
80 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');
83 it('should return false when output file has already existed', function() {
84 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.');
89 describe(test2, function() {
90 it('should return true when all options is proper.', function() {
91 var result = eos.toExecString('dcdFilePrint', [{name: '-r', arguments: [1,2,3]}, { name: '-i', arguments: ['file1.txt']}, { name: '-o', arguments: ['file3.txt']} ]);
92 expect(result).to.equal('dcdFilePrint -r 1 2 3 -s 10 -e 100 -d 10 -m 0 -i file1.txt -o file3.txt');
96 describe('getFiles', function() {
98 process.env.NODE_ENV = '';
101 return Promise.all([db.test1(), db.test2(), db.testRest()])
105 it('should be resolved with length 4', function() {
106 return expect(eos.getFiles('1f83f620-c1ed-11e5-9657-7942989daa00')).to.eventually.length(4);
109 it('should be resolved about testCommand', function() {
110 var command = testCommand.command;
111 var options = testCommand.options;
112 var workspace = testCommand.workspace;
113 return eos.validate(command, options, workspace).should.be.fulfilled;
117 process.env.NODE_ENV = 'test';