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;
15 * @param {string} Eosコマンドの名前
16 * @param {Array<Object>} コマンドに渡すオプション
17 * @returns {valid: boolean, message: string}
18 * function validate(command, params) {
29 * function toExecString(command, params) {
33 describe('Eos クラス', function() {
37 describe(test1, function() {
39 it('should return Array', function() {
40 return expect(eos.getFiles()).to.eventually.be.length(2);
43 it('should be rejected(2)', function() {
44 return eos.validate('hoge').should.be.rejectedWith(Error, 'Command name is invalid');
47 it('should be rejected(3)', function() {
48 return eos.validate('mrcImageNoiseAdd').should.be.rejectedWith(Error, 'Options need to be Array');
51 it('should be rejected(4)', function() {
52 return eos.validate('mrcImageNoiseAdd', []).should.be.rejectedWith(Error, 'At least one option is required.');
55 it('should return false when options is not Array', function() {
56 return eos.validate('mrcImageNoiseAdd', {}).should.be.rejectedWith(Error, 'Options need to be Array');
59 it('should return false when options is invalid Object which have not "name" and "argumetns"', function() {
60 return eos.validate('mrcImageInfo', [{hoge: 'hoge'}]).should.be.rejectedWith(Error, 'Options need to include Object which have properties "name" and "arguments"');
62 it('should return false when "argumetns" properties are not Array', function() {
63 return eos.validate('mrcImageInfo', [{name: 'hoge', arguments: 'hoge'}]).should.be.rejectedWith(Error,'Each "arguments" properties needs to be Array');
66 it('should return false when required options do not exist', function() {
67 return eos.validate('mrcImageInfo', [{name: 'hoge', arguments: []}]).should.be.rejectedWith('Option -i are required');
70 it('should return false when required options do not exist', function() {
71 return eos.validate('dcdFilePrint', [{name: '-r', arguments: [1,2]}, { name: '-i', arguments: []}, { name: '-o', arguments: []} ]).should.be.rejectedWith(Error, 'Invalid arguments number');
74 it('should return false when input file does not exist', function() {
75 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.');
78 it('should return false when output file is not string', function() {
79 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');
82 it('should return false when output file has already existed', function() {
83 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.');
87 describe(test2, function() {
89 it('should return true when all options is proper.', function() {
90 var result = eos.toExecString('dcdFilePrint', [{name: '-r', arguments: [1,2,3]}, { name: '-i', arguments: ['file1.txt']}, { name: '-o', arguments: ['file3.txt']} ]);
91 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);
110 process.env.NODE_ENV = 'test';