• R/O
  • HTTP
  • SSH
  • HTTPS

zephyr: Commit

This repository is for zephyr, which is implemented for a GUI of Eos.


Commit MetaInfo

Revisiond1bbaddb4805bec247cad7cce05f44ff750b1566 (tree)
Time2016-02-08 09:30:28
Authorhimetani_cafe <fumifumi@yasu...>
Commiterhimetani_cafe

Log Message

[Develop and Test] getUUIDs()
modified: server/api/v1/execution/index.js
modified: server/class/Eos.js
modified: test/mocha/Eos.test.js
new file: test/mocha/hoge.js

Change Summary

Incremental Difference

--- a/server/api/v1/execution/index.js
+++ b/server/api/v1/execution/index.js
@@ -31,9 +31,8 @@ router.post('/', function(req, res) {
3131 res.send(info);
3232 })
3333 .then(function() {
34- return eos.toExecString(command, options, workspace);
35- })
36- .then(function(execStr) {
34+ return eos.execute(command, options, workspace);
35+ .then(function(result) {
3736 console.log(execStr);
3837 var info = {
3938 status: 'success',
--- a/server/class/Eos.js
+++ b/server/class/Eos.js
@@ -1,18 +1,3 @@
1-
2-/**
3- * Eosコマンドをエミュレートするクラス
4- * @varructor
5- * @returns {object}
6- * function execute(command, params) {
7- */
8-var eos = {
9- validate: validate,
10- toExecString: toExecString,
11- execute: execute,
12- getFiles: getFiles
13-}
14-
15-
161 /**
172 *
183 * Class variables
@@ -27,16 +12,9 @@ var ocfReference = {};
2712 commandList.forEach(function(c) {
2813 ocfReference[c.name] = require(__dirname + '/../../user-specific-files/OptionControlFile/commands/' + c.name);
2914 });
15+var spawn = require('child_process').spawn;
3016
3117
32-// for unit test
33-
34-
35-/**
36- *
37- * Class variables
38- */
39-
4018 function hasOneProperty(options) {
4119 return new Promise(function(resolve, reject) {
4220 if(options.length === 0) {
@@ -265,12 +243,11 @@ function toExecString(command, options, workspaceId) {
265243 * @param params
266244 * @returns {object}
267245 */
268-function execute(command, options) {
269- var result = validate(command, options);
270- if(!result.hasDone) {
271- } else {
272- var str = toExecString(command, options);
273- }
246+function execute(str) {
247+ return new Promise(function(resolve, reject) {
248+ exec(str);
249+
250+ });
274251 }
275252
276253 /**
@@ -292,4 +269,37 @@ function getFiles(fileId) {
292269 });
293270 }
294271
272+/**
273+ * getUUID
274+ * @param fileId
275+ * @returns {object} key: filename, value: uuid
276+ */
277+function getUUIDs(fileId) {
278+ return new Promise(function(resolve) {
279+ db.getFiles(fileId)
280+ .then(function(r) {
281+ var uuids = {};
282+ r.forEach(function(v) {
283+ uuids[v.dataValues.name] = v.dataValues.fileId;
284+ //console.log(uuids);
285+ });
286+ resolve(uuids);
287+ });
288+ });
289+}
290+
291+/**
292+ * Eosコマンドをエミュレートするクラス
293+ * @varructor
294+ * @returns {object}
295+ * function execute(command, params) {
296+ */
297+var eos = {
298+ validate: validate,
299+ toExecString: toExecString,
300+ execute: execute,
301+ getFiles: getFiles,
302+ getUUIDs: getUUIDs
303+}
304+
295305 module.exports = { instance: eos };
--- a/test/mocha/Eos.test.js
+++ b/test/mocha/Eos.test.js
@@ -20,17 +20,7 @@
2020 */
2121 `;
2222
23- var test2 = `
24- /**
25- * 実行時文字列への変換
26- *
27- * @param command
28- * @param options
29- * @returns {string}
30- * function toExecString(command, params) {
31- */
32- `;
33-
23+
3424 describe('Eos クラス', function() {
3525 before(function() {
3626 });
@@ -93,6 +83,43 @@
9383 });
9484 });
9585
86+ var test2 = `
87+ /**
88+ * 実行時文字列への変換
89+ *
90+ * @param command
91+ * @param options
92+ * @returns {string}
93+ * function toExecString(command, params) {
94+ */
95+ `;
96+
97+
98+ describe('execute', function() {
99+ before(function() {
100+ process.env.NODE_ENV = '';
101+ return db.init()
102+ .then(function() {
103+ return Promise.all([db.test1(), db.test2(), db.testRest()])
104+ });
105+ });
106+
107+ it('should be resolved with length 4', function() {
108+ return expect(eos.getFiles('1f83f620-c1ed-11e5-9657-7942989daa00')).to.eventually.length(4);
109+ });
110+
111+ it('should be resolved about testCommand', function() {
112+ var command = testCommand.command;
113+ var options = testCommand.options;
114+ var workspace = testCommand.workspace;
115+ return eos.validate(command, options, workspace).should.be.fulfilled;
116+ });
117+
118+ after(function() {
119+ process.env.NODE_ENV = 'test';
120+ });
121+ });
122+
96123 describe('getFiles', function() {
97124 before(function() {
98125 process.env.NODE_ENV = '';
@@ -117,5 +144,29 @@
117144 process.env.NODE_ENV = 'test';
118145 });
119146 });
147+
148+ var getUUIDs = `
149+ /**
150+ * function getUUIDs(fileId)
151+ * uuidとファイル名のkey-valueを取得
152+ *
153+ * @param fileId
154+ * @returns {object} key: filename, value: uuid
155+ */
156+ `;
157+
158+ describe(getUUIDs, function() {
159+ before(function() {
160+ process.env.NODE_ENV = '';
161+ return db.init()
162+ .then(function() {
163+ return Promise.all([db.test1(), db.test2(), db.testRest()])
164+ });
165+ });
166+
167+ it('should be resolved', function() {
168+ return eos.getUUIDs('1f83f620-c1ed-11e5-9657-7942989daa00').should.eventually.have.property("hoge.txt");
169+ });
170+ });
120171 });
121172 })();
--- /dev/null
+++ b/test/mocha/hoge.js
@@ -0,0 +1,11 @@
1+var options = require('./testCommand.json').options;
2+
3+var array = options.reduce(function(a,b) {
4+ a.push(b.name);
5+ b.arguments.forEach(function(v) {
6+ return a.push(v);
7+ });
8+ return a;
9+},[]);
10+
11+console.log(array);
Show on old repository browser