@@ -16,6 +16,15 @@ describe('test/app/service/topics.test.js', () => {
1616
1717 describe ( 'show()' , ( ) => {
1818 it ( 'should with render success' , function * ( ) {
19+ app . mockHttpclient ( `${ ctx . service . topics . root } /topic/57ea257b3670ca3f44c5beb6` , 'GET' , {
20+ data : {
21+ success : true ,
22+ data : {
23+ content : '<div class="markdown-text">Super Mock Content</div>' ,
24+ replies : [ ] ,
25+ } ,
26+ } ,
27+ } ) ;
1928 const topic = yield ctx . service . topics . show ( {
2029 id : '57ea257b3670ca3f44c5beb6' ,
2130 mdrender : true ,
@@ -27,6 +36,15 @@ describe('test/app/service/topics.test.js', () => {
2736 } ) ;
2837
2938 it ( 'should without render success' , function * ( ) {
39+ app . mockHttpclient ( `${ ctx . service . topics . root } /topic/57ea257b3670ca3f44c5beb6` , 'GET' , {
40+ data : {
41+ success : true ,
42+ data : {
43+ content : 'Super Mock Content' ,
44+ replies : [ ] ,
45+ } ,
46+ } ,
47+ } ) ;
3048 const topic = yield ctx . service . topics . show ( {
3149 id : '57ea257b3670ca3f44c5beb6' ,
3250 mdrender : false ,
@@ -38,6 +56,13 @@ describe('test/app/service/topics.test.js', () => {
3856 } ) ;
3957
4058 it ( 'should response 404 when topic id not exist' , function * ( ) {
59+ app . mockHttpclient ( `${ ctx . service . topics . root } /topic/5433d5e4e737cbe96dcef300` , 'GET' , {
60+ status : 404 ,
61+ data : {
62+ error_msg : '话题不存在' ,
63+ } ,
64+ } ) ;
65+
4166 try {
4267 yield ctx . service . topics . show ( {
4368 id : '5433d5e4e737cbe96dcef300' ,
@@ -53,6 +78,18 @@ describe('test/app/service/topics.test.js', () => {
5378
5479 describe ( 'list()' , ( ) => {
5580 it ( 'should with render, limit and tab success' , function * ( ) {
81+ app . mockHttpclient ( `${ ctx . service . topics . root } /topics` , 'GET' , {
82+ data : {
83+ success : true ,
84+ data : [
85+ {
86+ content : '<div class="markdown-text">mock content</div>' ,
87+ } ,
88+ { } , { } , { } , { } ,
89+ ] ,
90+ } ,
91+ } ) ;
92+
5693 const topics = yield ctx . service . topics . list ( {
5794 mdrender : true ,
5895 limit : 5 ,
@@ -67,6 +104,13 @@ describe('test/app/service/topics.test.js', () => {
67104
68105 describe ( 'create()' , ( ) => {
69106 it ( 'should create failed by accesstoken error' , function * ( ) {
107+ app . mockHttpclient ( `${ ctx . service . topics . root } /topics` , 'POST' , {
108+ status : 401 ,
109+ data : {
110+ error_msg : '错误的accessToken' ,
111+ } ,
112+ } ) ;
113+
70114 try {
71115 yield ctx . service . topics . create ( {
72116 accesstoken : 'hello' ,
@@ -97,6 +141,13 @@ describe('test/app/service/topics.test.js', () => {
97141
98142 describe ( 'update()' , ( ) => {
99143 it ( 'should update failed by accesstoken error' , function * ( ) {
144+ app . mockHttpclient ( `${ ctx . service . topics . root } /topics/update` , 'POST' , {
145+ status : 401 ,
146+ data : {
147+ error_msg : '错误的accessToken' ,
148+ } ,
149+ } ) ;
150+
100151 try {
101152 yield ctx . service . topics . update ( {
102153 id : '57ea257b3670ca3f44c5beb6' ,
0 commit comments