OSDN Git Service

[Develop and Test] getUUIDs() v0.3.0p0039
authorhimetani_cafe <fumifumi@yasunaga-lab.bio.kyutech.ac.jp>
Mon, 8 Feb 2016 00:30:28 +0000 (09:30 +0900)
committerhimetani_cafe <fumifumi@yasunaga-lab.bio.kyutech.ac.jp>
Mon, 8 Feb 2016 00:30:28 +0000 (09:30 +0900)
modified:   server/api/v1/execution/index.js
modified:   server/class/Eos.js
modified:   test/mocha/Eos.test.js
new file:   test/mocha/hoge.js

server/api/v1/execution/index.js
server/class/Eos.js
test/mocha/Eos.test.js
test/mocha/hoge.js [new file with mode: 0644]

index 7e68a38..4f041a6 100644 (file)
@@ -31,9 +31,8 @@ router.post('/', function(req, res) {
             res.send(info);
         })
         .then(function() {
-            return eos.toExecString(command, options, workspace);
-        })
-        .then(function(execStr) {
+            return eos.execute(command, options, workspace);
+        .then(function(result) {
             console.log(execStr);
             var info = {
                 status: 'success',
index 7840134..f1857d2 100644 (file)
@@ -1,18 +1,3 @@
-
-/**
- * Eosコマンドをエミュレートするクラス 
- * @varructor
- * @returns {object}
- * function execute(command, params) {
- */
-var eos = {
-    validate: validate,
-    toExecString: toExecString,
-    execute: execute,
-    getFiles: getFiles
-}
-
-
 /**
  *
  * Class variables
@@ -27,16 +12,9 @@ var ocfReference = {};
 commandList.forEach(function(c) {
     ocfReference[c.name] = require(__dirname + '/../../user-specific-files/OptionControlFile/commands/' + c.name);
 });
+var spawn = require('child_process').spawn;
 
 
-// for unit test
-
-
-/**
- *
- * Class variables
- */
-
 function hasOneProperty(options) {
     return new Promise(function(resolve, reject) {
         if(options.length === 0) {
@@ -265,12 +243,11 @@ function toExecString(command, options, workspaceId) {
  * @param params
  * @returns {object}
  */
-function execute(command, options) {
-    var result = validate(command, options);
-    if(!result.hasDone) {
-    } else {
-        var str = toExecString(command, options);
-    }
+function execute(str) {
+    return new Promise(function(resolve, reject) {
+        exec(str);
+        
+    });
 }
 
 /**
@@ -292,4 +269,37 @@ function getFiles(fileId) {
     });
 }
 
+/**
+ * getUUID
+ * @param fileId 
+ * @returns {object} key: filename, value: uuid
+ */
+function getUUIDs(fileId) {
+    return new Promise(function(resolve) {
+        db.getFiles(fileId)
+        .then(function(r) {
+            var uuids = {};
+            r.forEach(function(v) {
+                uuids[v.dataValues.name] = v.dataValues.fileId;
+                //console.log(uuids);
+            });
+            resolve(uuids);
+        });
+    });
+}
+
+/**
+ * Eosコマンドをエミュレートするクラス 
+ * @varructor
+ * @returns {object}
+ * function execute(command, params) {
+ */
+var eos = {
+    validate: validate,
+    toExecString: toExecString,
+    execute: execute,
+    getFiles: getFiles,
+    getUUIDs: getUUIDs
+}
+
 module.exports = { instance: eos };
index ceaefdc..16e2843 100644 (file)
     */
     `;
 
-    var test2 = `
-    /**
-    * 実行時文字列への変換 
-    *
-    * @param command
-    * @param options
-    * @returns {string}
-    * function toExecString(command, params) {
-    */
-    `;
-
+    
     describe('Eos クラス', function() {
         before(function() {
         });
             });
         });
 
+        var test2 = `
+        /**
+        * 実行時文字列への変換 
+        *
+        * @param command
+        * @param options
+        * @returns {string}
+        * function toExecString(command, params) {
+        */
+        `;
+
+        
+        describe('execute', function() {
+            before(function() {
+                process.env.NODE_ENV = '';
+                return db.init()
+                .then(function() {
+                    return Promise.all([db.test1(), db.test2(), db.testRest()])
+                });
+            });
+
+            it('should be resolved with length 4', function() {
+                return expect(eos.getFiles('1f83f620-c1ed-11e5-9657-7942989daa00')).to.eventually.length(4);
+            });
+
+            it('should be resolved about testCommand', function() {
+                var command = testCommand.command;
+                var options = testCommand.options;
+                var workspace = testCommand.workspace;
+                return eos.validate(command, options, workspace).should.be.fulfilled;
+            });
+
+            after(function() {
+                process.env.NODE_ENV = 'test';
+            });
+        });
+
         describe('getFiles', function() {
             before(function() {
                 process.env.NODE_ENV = '';
                 process.env.NODE_ENV = 'test';
             });
         });
+
+        var getUUIDs = `
+        /**
+        * function getUUIDs(fileId)
+        * uuidとファイル名のkey-valueを取得 
+        *
+        * @param fileId
+        * @returns {object} key: filename, value: uuid
+        */
+        `;
+
+        describe(getUUIDs, function() {
+            before(function() {
+                process.env.NODE_ENV = '';
+                return db.init()
+                .then(function() {
+                    return Promise.all([db.test1(), db.test2(), db.testRest()])
+                });
+            });
+
+            it('should be resolved', function() {
+                return eos.getUUIDs('1f83f620-c1ed-11e5-9657-7942989daa00').should.eventually.have.property("hoge.txt");
+            });
+        });
     });
 })();
diff --git a/test/mocha/hoge.js b/test/mocha/hoge.js
new file mode 100644 (file)
index 0000000..3c8cfca
--- /dev/null
@@ -0,0 +1,11 @@
+var options = require('./testCommand.json').options;
+
+var array = options.reduce(function(a,b) {
+    a.push(b.name);
+    b.arguments.forEach(function(v) {
+        return a.push(v);
+    });
+    return a;
+},[]);
+
+console.log(array);