• R/O
  • HTTP
  • SSH
  • HTTPS

zephyr: Commit

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


Commit MetaInfo

Revisionc88556b36a5c5405bef945b8e6d0df344be7f176 (tree)
Time2016-01-23 14:38:47
Authorhimetani_cafe <fumifumi@yasu...>
Commiterhimetani_cafe

Log Message

[Test]: db.createFile

Please enter the commit message for your changes. Lines starting
with will be ignored, and an empty message aborts the commit.
On branch master
Changes to be committed:

modified: package.json
modified: server/class/DB.js
modified: test/mocha/DB.test.js

Change Summary

Incremental Difference

--- a/package.json
+++ b/package.json
@@ -19,12 +19,14 @@
1919 "co": "^4.6.0",
2020 "commander": "^2.9.0",
2121 "express": "^4.13.3",
22+ "node-uuid": "^1.4.7",
2223 "sequelize": "^3.18.0",
2324 "socket.io": "^1.3.7",
2425 "sqlite3": "^3.1.1"
2526 },
2627 "devDependencies": {
2728 "chai": "^3.4.1",
29+ "chai-as-promised": "^5.2.0",
2830 "gulp": "^3.9.0",
2931 "gulp-sass": "^2.1.1",
3032 "mocha": "^2.3.4",
--- a/server/class/DB.js
+++ b/server/class/DB.js
@@ -9,6 +9,7 @@ function DB() {
99 var fs = require('fs');
1010 var Sequelize = require('sequelize');
1111 var co = require('co');
12+ var uuid = require('node-uuid');
1213
1314 var sequelize;
1415 var test = 'hello';
@@ -17,27 +18,70 @@ function DB() {
1718 dialect: 'sqlite'
1819 };
1920
21+ /**
22+ * sync
23+ *
24+ * @returns {promise}<DBオブジェクトの関数群のオブジェクトをresolveする>
25+ */
2026 function sync() {
2127 return new Promise(function(resolve) {
22- Promise.all([Directory.sync(), File.sync()])
28+ Files.sync()
2329 .then(function() {
2430 var root = {
25- name: 'root',
26- parent: ''
31+ fileId: uuid.v1(),
32+ name: '/',
33+ parentDirectory: '',
34+ fileType: 0
2735 };
28- return Directory.create(root);
36+ return Files.create(root);
2937 })
3038 .then(function() {
3139 var c = {
3240 sayHello: function() {
3341 return test;
34- }
42+ },
43+ createFile: createFile
44+ /*
45+ removeFile: removeFile,
46+ createDirectory: createDirectory,
47+ removeDirectory: removeDirectory,
48+ getFilename: getFilename,
49+ moveFile: moveFile,
50+ moveDirectory: moveDirectory
51+ */
3552 };
3653 resolve(c);
3754 });
3855 });
3956 }
4057
58+ /**
59+ * createFile
60+ *
61+ * @param name
62+ * @param directory
63+ * @returns {promise}<保存したファイルのファイル名(uuid)をresolveする>
64+ */
65+ function createFile(fileName,parentDirectory) {
66+ return new Promise(function(resolve) {
67+ var q = {
68+ fileId: uuid.v1(),
69+ name: fileName,
70+ parentDirectory: parentDirectory,
71+ fileType: 0
72+ }
73+ Files.create(q)
74+ .then(function(r) {
75+ resolve(r);
76+ });
77+ });
78+ }
79+
80+ /**
81+ *
82+ * @constructor
83+ * @returns {promise}
84+ */
4185 if(process.env['NODE_ENV'] === 'production') {
4286 var dbPath = __dirname + '/../../user-specific-files/db/db.workspace';
4387 dbOption.storage = dbPath;
@@ -52,7 +96,7 @@ function DB() {
5296
5397 sequelize = new Sequelize('','','', dbOption);
5498
55- var File = sequelize.define('file', {
99+ var Files = sequelize.define('file', {
56100 fileId: {
57101 type: Sequelize.UUID,
58102 field: 'file_id',
@@ -63,29 +107,18 @@ function DB() {
63107 field: 'name',
64108 allowNull: false
65109 },
66- directoryName: {
110+ parentDirectory: {
67111 type: Sequelize.STRING,
68- field: 'directory_name',
112+ field: 'parent_directory',
69113 allowNull: false
70- }
71- });
72-
73- var Directory = sequelize.define('directory', {
74- name: {
75- type: Sequelize.STRING,
76- field: 'name',
77- primaryKey: true
78114 },
79- parent: {
80- type: Sequelize.STRING,
81- field: 'parent',
115+ fileType: {
116+ type: Sequelize.ENUM(0,1),
117+ field: 'file_type',
82118 allowNull: false
83119 }
84120 });
85121
86- Directory.hasMany(File, {foreignKey: 'directoryName'});
87- File.belongsTo(Directory, {foreignKey: 'name'});
88-
89122 return sync();
90123 }
91124
--- a/test/mocha/DB.test.js
+++ b/test/mocha/DB.test.js
@@ -1,20 +1,52 @@
11 (function() {
22 'use strict';
33 var DB = require('../../server/class/DB');
4- var expect = require('chai').expect;
4+ var chai = require('chai');
5+ var chaiAsPromised = require('chai-as-promised');
6+ chai.use(chaiAsPromised);
7+ var expect = chai.expect;
8+ var should = chai.should;
59
610 //process.env['NODE_ENV'] = 'production';
7- var db;
8- before(function() {
9- return DB()
10- .then(function(r) {
11- db = r;
12- });
13- });
11+
12+ var constructor = `
13+ /**
14+ * createFile
15+ *
16+ * @param name
17+ * @param directory
18+ * @returns {promise}<保存したファイルのファイル名(uuid)をresolveする>
19+ */
20+ `;
21+
22+ var createFile = `
23+ /**
24+ * createFile
25+ *
26+ * @param name
27+ * @param directory
28+ * @returns {promise}<保存したファイルのファイル名(uuid)をresolveする>
29+ */
30+ `;
1431
1532 describe('DB クラス', function() {
16- it('test of test', function() {
17- expect(db.sayHello()).to.equal('hello');
33+ var db;
34+ before(function() {
35+ return DB()
36+ .then(function(r) {
37+ db = r;
38+ });
39+ });
40+
41+ describe(constructor, function() {
42+ it('should return hello when call sayHello', function() {
43+ expect(db.sayHello()).to.equal('hello');
44+ });
45+ });
46+ describe(createFile, function() {
47+ it('should return object which have proverty "dataValues"', function() {
48+ return expect(db.createFile('hage.txt','root')).to.eventually.have.property('dataValues');
49+ });
1850 });
1951 });
2052 })();
Show on old repository browser