Skip to content

Commit d8402d3

Browse files
committed
improve cov 100% | jsdoc | pre-commit hook | opt code
1 parent dc50140 commit d8402d3

File tree

79 files changed

+11763
-145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+11763
-145
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ coverage/
77
run/
88
.DS_Store
99
*.swp
10+
out/
1011

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ $ npm run dev
4545

4646
- ✔︎ Full APIs Wrapped
4747
- ✔︎ RESTful Style
48-
- ✔︎ 30+ Case, 90%+ Unit Test(`BDD`)
48+
- ✔︎ 30+ Case, 100%+ Unit Test(`BDD`)
4949
- ✔︎ Hot Reload in Dev
50+
- ✔︎ pre-commit hook to run cov & build docs and host in Github Pages @see `package.json`
5051

5152
## Unit Test
5253

app/controller/auth.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
/**
2-
* @Controller
3-
* @Module auth
1+
/**
42
* ---------------------------------------------
53
* Author : IndexXuan(https://github.com/IndexXuan)
64
* Mail : indexxuan@gmail.com
75
* Date : Tue 14 Mar 2017 03:15:19 PM CST
86
*/
97

8+
/**
9+
* @Controller
10+
* @file auth
11+
* @module Auth
12+
*/
13+
1014
'use strict'
1115

1216
module.exports = app => {

app/controller/members.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/**
2-
* @Controller
3-
* @Module members
4-
* ---------------------------------------------
52
* Author : IndexXuan(https://github.com/IndexXuan)
63
* Mail : indexxuan@gmail.com
74
* Date : Fri 10 Mar 2017 03:21:40 PM CST
85
*/
96

7+
/**
8+
* @Controller
9+
* @module Members
10+
*/
11+
1012
'use strict'
1113

1214
module.exports = app => {

app/controller/nodes.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/**
2-
* @Controller
3-
* @Module nodes
4-
* ---------------------------------------------
52
* Author : IndexXuan(https://github.com/IndexXuan)
63
* Mail : indexxuan@gmail.com
74
* Date : Fri 10 Mar 2017 02:49:54 PM CST
85
*/
96

7+
/**
8+
* @Controller
9+
* @module Nodes
10+
*/
11+
1012
'use strict'
1113

1214
module.exports = app => {

app/controller/replies.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
/**
2-
* @Controller
3-
* @Module replies
4-
* ---------------------------------------------
52
* Author : IndexXuan(https://github.com/IndexXuan)
63
* Mail : indexxuan@gmail.com
74
* Date : Mon 13 Mar 2017 05:28:59 PM CST
85
*/
96

7+
/**
8+
* @Controller
9+
* @module Replies
10+
*/
11+
1012
'use strict'
1113

1214
module.exports = app => {
13-
return class RepiesController extends app.Controller {
15+
return class RepliesController extends app.Controller {
1416
/**
1517
* show
1618
* 返回一个topic下的全部回复
@@ -42,6 +44,7 @@ module.exports = app => {
4244
ctx.params = Object.assign(ctx.params, ctx.query)
4345
ctx.body = await ctx.service.replies.create(ctx.params)
4446
}
45-
} // /.class=>RepiesController
47+
} // /.class=>RepliesController
4648
} // /.exports
4749

50+

app/controller/site.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/**
2-
* @Controller
3-
* @Module site
4-
* ---------------------------------------------
52
* Author : IndexXuan(https://github.com/IndexXuan)
63
* Mail : indexxuan@gmail.com
74
* Date : Fri 10 Mar 2017 02:18:42 PM CST
85
*/
96

7+
/**
8+
* @Controller
9+
* @module Site
10+
*/
11+
1012
'use strict'
1113

1214
module.exports = app => {

app/controller/topics.js

Lines changed: 163 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,142 @@
11
/**
2-
* @Controller
3-
* @Module topics
4-
* ---------------------------------------------
52
* Author : IndexXuan(https://github.com/IndexXuan)
63
* Mail : indexxuan@gmail.com
74
* Date : Fri 03 Mar 2017 03:23:34 PM CST
85
*/
96

107
/**
11-
* @Controller
12-
*
13-
* 1. 调用validate方法对请求参数进行验证
14-
* 2. 按照接口约定的格式设置响应状态码和内容
8+
* @Controller
9+
* @file 主题相关API
10+
* @author IndexXuan
11+
* @module Topics
1512
*/
1613

1714
'use strict'
1815

1916
module.exports = app => {
2017
return class TopicsController extends app.Controller {
2118
/**
22-
* latest
23-
* 返回最新topics
19+
* 返回最新topics列表
20+
* @example
21+
* GET /api/v2/topics/latest
2422
*
25-
* @param {Object} ctx - 请求上下文
26-
* @returns {Promise} - @async
23+
* [{
24+
* id: 350959,
25+
* url: "http://www.v2ex.com/t/350959",
26+
* title: "MacBook Pro 13 寸顶配 最新款转让",
27+
* replies: 1,
28+
* content: "由于本人急需用钱,现需要忍痛割爱,电脑于 apple 官方网站购买(有苹果官方发票和可以查看本人购买记录),从 1 月 15 日使用至今,原价 22,328RMB ,现 2w 转让,限北京当面交易。...",
29+
* created: 1490693527,
30+
* member: {
31+
* id: 79264,
32+
* username: "richardzhou",
33+
* vatar_large: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=73&d=retro",
34+
* avatar_mini: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=24&d=retro",
35+
* avatar_normal: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=48&d=retro",
36+
* tagline: ""
37+
* },
38+
* node: {
39+
* id: 10,
40+
* name: "mbp",
41+
* title: "MacBook Pro",
42+
* title_alternative: "MacBook Pro",
43+
* topics: 3021,
44+
* url: "http://www.v2ex.com/go/mbp",
45+
* avatar_large: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_large.png?m=1488347268",
46+
* avatar_mini: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_mini.png?m=1488347268",
47+
* avatar_normal: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_normal.png?m=1488347268"
48+
* },
49+
* last_modified: 1490693527,
50+
* last_touched: 1490693347
51+
* }, {
52+
* ...
53+
* }]
2754
*/
28-
async latest (ctx) {
55+
async latest () {
56+
const { ctx } = this
2957
ctx.body = await ctx.service.topics.latest()
3058
}
3159

3260
/**
33-
* hot
34-
* 返回最热topics
61+
* 返回最热topics列表
62+
* @example
63+
* GET /api/v2/topics/hot
3564
*
36-
* @param {Object} ctx - 请求上下文
37-
* @returns {Promise} - @async
65+
* [{
66+
* id: 350959,
67+
* url: "http://www.v2ex.com/t/350959",
68+
* title: "MacBook Pro 13 寸顶配 最新款转让",
69+
* replies: 1,
70+
* content: "由于本人急需用钱,现需要忍痛割爱,电脑于 apple 官方网站购买(有苹果官方发票和可以查看本人购买记录),从 1 月 15 日使用至今,原价 22,328RMB ,现 2w 转让,限北京当面交易。...",
71+
* created: 1490693527,
72+
* member: {
73+
* id: 79264,
74+
* username: "richardzhou",
75+
* vatar_large: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=73&d=retro",
76+
* avatar_mini: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=24&d=retro",
77+
* avatar_normal: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=48&d=retro",
78+
* tagline: ""
79+
* },
80+
* node: {
81+
* id: 10,
82+
* name: "mbp",
83+
* title: "MacBook Pro",
84+
* title_alternative: "MacBook Pro",
85+
* topics: 3021,
86+
* url: "http://www.v2ex.com/go/mbp",
87+
* avatar_large: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_large.png?m=1488347268",
88+
* avatar_mini: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_mini.png?m=1488347268",
89+
* avatar_normal: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_normal.png?m=1488347268"
90+
* },
91+
* last_modified: 1490693527,
92+
* last_touched: 1490693347
93+
* }, {
94+
* ...
95+
* }]
3896
*/
39-
async hot (ctx) {
97+
async hot () {
98+
const { ctx } = this
4099
ctx.body = await ctx.service.topics.hot()
41100
}
42101

43102
/**
44-
* show
45-
* 返回一个特定topics
103+
* 返回特定topics
104+
* @param {Number|String} id - topic_id
105+
* @example
106+
* GET /api/v2/topics/show?id=${id}
46107
*
47-
* @param {Object} ctx - 请求上下文
48-
* @returns {Promise}-@async
108+
* {
109+
* id: 350959,
110+
* url: "http://www.v2ex.com/t/350959",
111+
* title: "MacBook Pro 13 寸顶配 最新款转让",
112+
* replies: 1,
113+
* content: "由于本人急需用钱,现需要忍痛割爱,电脑于 apple 官方网站购买(有苹果官方发票和可以查看本人购买记录),从 1 月 15 日使用至今,原价 22,328RMB ,现 2w 转让,限北京当面交易。...",
114+
* created: 1490693527,
115+
* member: {
116+
* id: 79264,
117+
* username: "richardzhou",
118+
* vatar_large: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=73&d=retro",
119+
* avatar_mini: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=24&d=retro",
120+
* avatar_normal: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=48&d=retro",
121+
* tagline: ""
122+
* },
123+
* node: {
124+
* id: 10,
125+
* name: "mbp",
126+
* title: "MacBook Pro",
127+
* title_alternative: "MacBook Pro",
128+
* topics: 3021,
129+
* url: "http://www.v2ex.com/go/mbp",
130+
* avatar_large: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_large.png?m=1488347268",
131+
* avatar_mini: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_mini.png?m=1488347268",
132+
* avatar_normal: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_normal.png?m=1488347268"
133+
* },
134+
* last_modified: 1490693527,
135+
* last_touched: 1490693347
136+
* }
49137
*/
50-
async show (ctx) {
138+
async show () {
139+
const { ctx } = this
51140
// validator
52141
ctx.validate({
53142
id: { type: 'id', required: true }
@@ -57,14 +146,47 @@ module.exports = app => {
57146
}
58147

59148
/**
60-
* getAllByType
61149
* 返回一个类型下的所有topics
62-
* @enums: [ 'username', 'node_name', 'node_id' ]
150+
* @param {String} type - topics的类型
151+
* - @enum [ 'username', 'node_name', 'node_id' ]
152+
* @param {String} value - topics类型的值
153+
* @example
154+
* GET /api/v2/topics/node_name/vim
63155
*
64-
* @param {Object} ctx - 请求上下文
65-
* @returns {Promise}-@async
156+
* [{
157+
* id: 350959,
158+
* url: "http://www.v2ex.com/t/350959",
159+
* title: "MacBook Pro 13 寸顶配 最新款转让",
160+
* replies: 1,
161+
* content: "由于本人急需用钱,现需要忍痛割爱,电脑于 apple 官方网站购买(有苹果官方发票和可以查看本人购买记录),从 1 月 15 日使用至今,原价 22,328RMB ,现 2w 转让,限北京当面交易。...",
162+
* created: 1490693527,
163+
* member: {
164+
* id: 79264,
165+
* username: "richardzhou",
166+
* vatar_large: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=73&d=retro",
167+
* avatar_mini: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=24&d=retro",
168+
* avatar_normal: "//v2ex.assets.uxengine.net/gravatar/4b89de587467c780f7f2a6b4460b66ea?s=48&d=retro",
169+
* tagline: ""
170+
* },
171+
* node: {
172+
* id: 10,
173+
* name: "mbp",
174+
* title: "MacBook Pro",
175+
* title_alternative: "MacBook Pro",
176+
* topics: 3021,
177+
* url: "http://www.v2ex.com/go/mbp",
178+
* avatar_large: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_large.png?m=1488347268",
179+
* avatar_mini: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_mini.png?m=1488347268",
180+
* avatar_normal: "//v2ex.assets.uxengine.net/navatar/d3d9/4468/10_normal.png?m=1488347268"
181+
* },
182+
* last_modified: 1490693527,
183+
* last_touched: 1490693347
184+
* }, {
185+
* ...
186+
* }]
66187
*/
67-
async getAllByType (ctx) {
188+
async getAllByType () {
189+
const { ctx } = this
68190
// validator
69191
ctx.validate({
70192
type: { type: 'enum', values: [ 'username', 'node_name', 'node_id' ], required: true },
@@ -78,13 +200,23 @@ module.exports = app => {
78200
}
79201

80202
/**
81-
* create
82203
* 创建一个topic,返回创建结果
83204
*
84-
* @param ctx
85-
* @returns {Promise} - @async
205+
* @param {String} title - 标题
206+
* @param {String} content - 内容
207+
* @param {String} node_name - 节点名
208+
* @example
209+
* POST /api/v2/topics/new
210+
* data: { title: ${title}, content: ${content}, node_name: ${node_name} }
211+
*
212+
* {
213+
* result: true|false,
214+
* msg: ${msg}, // 可能的一些信息
215+
* url: ${url} // 此新建topic的url
216+
* }
86217
*/
87-
async create (ctx) {
218+
async create () {
219+
const { ctx } = this
88220
ctx.validate({
89221
title: { type: 'string', required: true },
90222
content: { type: 'string', required: true },

app/extend/context.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/**
2-
* @Extend Context
3-
* ---------------------------------------------
42
* Author : IndexXuan(https://github.com/IndexXuan)
53
* Mail : indexxuan@gmail.com
64
* Date : Fri 24 Mar 2017 11:15:04 AM CST
75
*/
86

7+
/**
8+
* @module Extend
9+
*/
10+
911
'use strict'
1012

1113
// sessionid cookie name

0 commit comments

Comments
 (0)