Skip to content

Commit

Permalink
update to v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhutu committed Feb 29, 2016
1 parent 720ebb8 commit fde2bbf
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 30 deletions.
7 changes: 7 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.0.1 / 2016-02-29
==================

* 修复初始化数据seed.js
* 修复七牛API调用和测试


1.0.0 / 2016-01-28
==================

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jackblog-api-koa",
"version": "1.0.0",
"version": "1.0.1",
"description": "jackblog API koa版",
"main": "server/app.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fs.readdirSync(modelsPath).forEach(function (file) {
// 初始化数据
if(config.seedDB && config.env === 'development') {
const initData = require('./config/seed');
app.use(initData());
initData();
}

//log记录
Expand Down
20 changes: 11 additions & 9 deletions server/config/seed.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/**
* 初始化数据
* 管理员用户
* email: [email protected]
* password: admin
*/
'use strict';

Expand All @@ -8,13 +11,14 @@ const User = mongoose.model('User');
const Article = mongoose.model('Article');
const TagCategory = mongoose.model('TagCategory');
const Tag = mongoose.model('Tag');
const co = require('co');
const logger = require('../util/logs').logger;

//初始化标签,文章,用户
function initData() {
return function *(next) {
module.exports = function () {
co(function* () {
const userCount = yield User.count();
if(userCount === 0){
yield User.remove();
yield User.create({
nickname:'admin',
email:'[email protected]',
Expand Down Expand Up @@ -43,7 +47,6 @@ function initData() {
}
const tagCount = yield TagCategory.count();
if(tagCount === 0){
yield TagCategory.remove();
yield Tag.remove();
const languageCat = yield TagCategory.create({
name:'language',
Expand Down Expand Up @@ -107,8 +110,7 @@ function initData() {
});
});
}
yield next;
}
}

module.exports = initData
}).catch(function (err) {
logger.debug('Init data error');
});
}
27 changes: 8 additions & 19 deletions test/util/qiniu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var should = require("should");
var qiniuHelper = require('../../server/util/qiniu');
var sinon = require('sinon');
var Promise = require('bluebird');

describe('test/util/qiniu.js',function () {
var mockKey = 'PwzqKey';
Expand All @@ -15,9 +14,9 @@ describe('test/util/qiniu.js',function () {
var stubFetch;
beforeEach(function () {
stubFetch = sinon.stub(qiniuHelper,'fetchFile');
stubFetch.withArgs(mockUrl,mockBucket,mockKey).returns(Promise.resolve([
{key:'/blog/article/test.png'},{status:200}
]));
stubFetch.withArgs(mockUrl,mockBucket,mockKey).returns(
Promise.resolve({key:'/blog/article/test.png'})
);
//stubFetch.withArgs('errUrl',mockBucket,'errKey').returns(Promise.reject());
});

Expand All @@ -39,9 +38,7 @@ describe('test/util/qiniu.js',function () {
var uploadStub;
beforeEach(function () {
uploadStub = sinon.stub(qiniuHelper,'uploadFile');
uploadStub.returns(Promise.resolve([
{key:'/blog/article/test.png'},{status:200}
]));
uploadStub.returns(Promise.resolve({key:'/blog/article/test.png'}));
});

afterEach(function () {
Expand All @@ -61,9 +58,7 @@ describe('test/util/qiniu.js',function () {
var moveStub;
beforeEach(function () {
moveStub = sinon.stub(qiniuHelper,'moveFile');
moveStub.returns(Promise.resolve([
{key:'/blog/article/test.png'},{status:200}
]));
moveStub.returns(Promise.resolve({key:'/blog/article/test.png'}));
});

afterEach(function () {
Expand All @@ -83,9 +78,7 @@ describe('test/util/qiniu.js',function () {
var copyStub;
beforeEach(function () {
copyStub = sinon.stub(qiniuHelper,'copyFile');
copyStub.returns(Promise.resolve([
{key:'/blog/article/test.png'},{status:200}
]));
copyStub.returns(Promise.resolve({key:'/blog/article/test.png'}));
});

afterEach(function () {
Expand All @@ -104,9 +97,7 @@ describe('test/util/qiniu.js',function () {
var removeStub;
beforeEach(function () {
removeStub = sinon.stub(qiniuHelper,'removeFile');
removeStub.returns(Promise.resolve([
{key:'/blog/article/test.png'},{status:200}
]));
removeStub.returns(Promise.resolve({key:'/blog/article/test.png'}));
});

afterEach(function () {
Expand All @@ -126,9 +117,7 @@ describe('test/util/qiniu.js',function () {
var listStub;
beforeEach(function () {
listStub = sinon.stub(qiniuHelper,'allList');
listStub.returns(Promise.resolve([
{items:[{key:'/blog/article/test.png'}]},{status:200}
]));
listStub.returns(Promise.resolve({items:[{key:'/blog/article/test.png'}]}));
});

afterEach(function () {
Expand Down

0 comments on commit fde2bbf

Please sign in to comment.