@@ -4,6 +4,10 @@ var expect = require('expect.js');
44var urllib = require ( 'urllib' ) ;
55var muk = require ( 'muk' ) ;
66var puling = 'ofL4cs7hr04cJIcu600_W-ZwwxHg' ;
7+ var imageId = 'XDZxzuRWBPqI4R9n_nNR5uRVZVQCSneMoELyWKflwM2qF9K38vnVFzgaD97uCTUu' ;
8+ var voiceId = '9R5BhAum7AEaGhwku0WhgvtO4C_7Xs78NoiRvm6v7IyoTljE4HH5o8E_UfnPrL0p' ;
9+ var thumbId = 'BHxGDVy7WY6BCOcv3AwbywUE630Vw0tAV_V8bzBaCZid4Km5fwXrVOso3X0zas4n' ;
10+ var movieId = 'b4F8SfaZZQwalDxwPjd923ACV5IUeYvZ9-dYKf5ytXrS-IImXEkl2U8Fl5EH-jCF' ;
711
812describe ( 'api_customer' , function ( ) {
913 var api = new API ( config . appid , config . appsecret ) ;
@@ -29,10 +33,16 @@ describe('api_customer', function () {
2933
3034 describe ( 'sendText' , function ( ) {
3135 it ( 'sendText should ok' , function ( done ) {
32- api . sendText ( puling , 'Hellow World' , function ( err , data , res ) {
33- expect ( err ) . not . to . be . ok ( ) ;
34- expect ( data ) . to . have . property ( 'errcode' , 0 ) ;
35- expect ( data ) . to . have . property ( 'errmsg' , 'ok' ) ;
36+ api . sendText ( puling , 'Hello World' , function ( err , data , res ) {
37+ if ( ! err ) {
38+ expect ( err ) . not . to . be . ok ( ) ;
39+ expect ( data ) . to . have . property ( 'errcode' , 0 ) ;
40+ expect ( data ) . to . have . property ( 'errmsg' , 'ok' ) ;
41+ } else {
42+ expect ( err ) . to . be . ok ( ) ;
43+ expect ( err ) . to . have . property ( 'name' , 'WeChatAPIError' ) ;
44+ expect ( err ) . to . have . property ( 'message' , 'response out of time limit' ) ;
45+ }
3646 done ( ) ;
3747 } ) ;
3848 } ) ;
@@ -51,12 +61,18 @@ describe('api_customer', function () {
5161 } ) ;
5262 } ) ;
5363
54- describe ( 'sendText' , function ( ) {
55- it ( 'sendText should ok' , function ( done ) {
56- api . sendText ( puling , 'Hellow World' , function ( err , data , res ) {
57- expect ( err ) . not . to . be . ok ( ) ;
58- expect ( data ) . to . have . property ( 'errcode' , 0 ) ;
59- expect ( data ) . to . have . property ( 'errmsg' , 'ok' ) ;
64+ describe ( 'sendImage' , function ( ) {
65+ it ( 'sendImage should ok' , function ( done ) {
66+ api . sendImage ( puling , imageId , function ( err , data , res ) {
67+ if ( ! err ) {
68+ expect ( err ) . not . to . be . ok ( ) ;
69+ expect ( data ) . to . have . property ( 'errcode' , 0 ) ;
70+ expect ( data ) . to . have . property ( 'errmsg' , 'ok' ) ;
71+ } else {
72+ expect ( err ) . to . be . ok ( ) ;
73+ expect ( err ) . to . have . property ( 'name' , 'WeChatAPIError' ) ;
74+ // expect(err).to.have.property('message', 'response out of time limit');
75+ }
6076 done ( ) ;
6177 } ) ;
6278 } ) ;
@@ -65,7 +81,150 @@ describe('api_customer', function () {
6581 mockError ( ) ;
6682
6783 it ( 'should not ok' , function ( done ) {
68- api . sendText ( puling , 'Hellow World' , function ( err , data ) {
84+ api . sendImage ( puling , imageId , function ( err , data ) {
85+ expect ( err ) . to . be . ok ( ) ;
86+ expect ( err . name ) . to . be ( 'WeChatAPIError' ) ;
87+ expect ( err . message ) . to . be ( 'mock error' ) ;
88+ done ( ) ;
89+ } ) ;
90+ } ) ;
91+ } ) ;
92+ } ) ;
93+
94+ describe ( 'sendVoice' , function ( ) {
95+ it ( 'sendVoice should ok' , function ( done ) {
96+ api . sendVoice ( puling , voiceId , function ( err , data , res ) {
97+ if ( ! err ) {
98+ expect ( err ) . not . to . be . ok ( ) ;
99+ expect ( data ) . to . have . property ( 'errcode' , 0 ) ;
100+ expect ( data ) . to . have . property ( 'errmsg' , 'ok' ) ;
101+ } else {
102+ expect ( err ) . to . be . ok ( ) ;
103+ expect ( err ) . to . have . property ( 'name' , 'WeChatAPIError' ) ;
104+ expect ( err ) . to . have . property ( 'message' , 'response out of time limit' ) ;
105+ }
106+ done ( ) ;
107+ } ) ;
108+ } ) ;
109+
110+ describe ( 'mock err' , function ( ) {
111+ mockError ( ) ;
112+
113+ it ( 'should not ok' , function ( done ) {
114+ api . sendVoice ( puling , voiceId , function ( err , data ) {
115+ expect ( err ) . to . be . ok ( ) ;
116+ expect ( err . name ) . to . be ( 'WeChatAPIError' ) ;
117+ expect ( err . message ) . to . be ( 'mock error' ) ;
118+ done ( ) ;
119+ } ) ;
120+ } ) ;
121+ } ) ;
122+ } ) ;
123+
124+ describe ( 'sendVideo' , function ( ) {
125+ it ( 'sendVideo should ok' , function ( done ) {
126+ api . sendVideo ( puling , voiceId , thumbId , function ( err , data , res ) {
127+ if ( ! err ) {
128+ expect ( err ) . not . to . be . ok ( ) ;
129+ expect ( data ) . to . have . property ( 'errcode' , 0 ) ;
130+ expect ( data ) . to . have . property ( 'errmsg' , 'ok' ) ;
131+ } else {
132+ expect ( err ) . to . be . ok ( ) ;
133+ expect ( err ) . to . have . property ( 'name' , 'WeChatAPIError' ) ;
134+ expect ( err ) . to . have . property ( 'message' , 'invalid media_id' ) ;
135+ }
136+ done ( ) ;
137+ } ) ;
138+ } ) ;
139+
140+ describe ( 'mock err' , function ( ) {
141+ mockError ( ) ;
142+
143+ it ( 'should not ok' , function ( done ) {
144+ api . sendVideo ( puling , voiceId , thumbId , function ( err , data ) {
145+ expect ( err ) . to . be . ok ( ) ;
146+ expect ( err . name ) . to . be ( 'WeChatAPIError' ) ;
147+ expect ( err . message ) . to . be ( 'mock error' ) ;
148+ done ( ) ;
149+ } ) ;
150+ } ) ;
151+ } ) ;
152+ } ) ;
153+
154+ describe ( 'sendMusic' , function ( ) {
155+ var music = {
156+ title : '音乐标题' , // 可选
157+ description : '描述内容' , // 可选
158+ musicurl : 'http://url.cn/xxx' , // 音乐文件地址
159+ hqmusicurl : "HQ_MUSIC_URL" ,
160+ thumb_media_id : "THUMB_MEDIA_ID"
161+ } ;
162+
163+ it ( 'sendMusic should ok' , function ( done ) {
164+ api . sendMusic ( puling , music , function ( err , data , res ) {
165+ if ( ! err ) {
166+ expect ( err ) . not . to . be . ok ( ) ;
167+ expect ( data ) . to . have . property ( 'errcode' , 0 ) ;
168+ expect ( data ) . to . have . property ( 'errmsg' , 'ok' ) ;
169+ } else {
170+ expect ( err ) . to . be . ok ( ) ;
171+ expect ( err ) . to . have . property ( 'name' , 'WeChatAPIError' ) ;
172+ expect ( err ) . to . have . property ( 'message' , 'invalid media_id' ) ;
173+ }
174+ done ( ) ;
175+ } ) ;
176+ } ) ;
177+
178+ describe ( 'mock err' , function ( ) {
179+ mockError ( ) ;
180+
181+ it ( 'should not ok' , function ( done ) {
182+ api . sendMusic ( puling , music , function ( err , data ) {
183+ expect ( err ) . to . be . ok ( ) ;
184+ expect ( err . name ) . to . be ( 'WeChatAPIError' ) ;
185+ expect ( err . message ) . to . be ( 'mock error' ) ;
186+ done ( ) ;
187+ } ) ;
188+ } ) ;
189+ } ) ;
190+ } ) ;
191+
192+ describe ( 'sendNews' , function ( ) {
193+ var articles = [
194+ {
195+ "title" :"Happy Day" ,
196+ "description" :"Is Really A Happy Day" ,
197+ "url" :"URL" ,
198+ "picurl" :"PIC_URL"
199+ } ,
200+ {
201+ "title" :"Happy Day" ,
202+ "description" :"Is Really A Happy Day" ,
203+ "url" :"URL" ,
204+ "picurl" :"PIC_URL"
205+ }
206+ ] ;
207+
208+ it ( 'sendMusic should ok' , function ( done ) {
209+ api . sendNews ( puling , articles , function ( err , data , res ) {
210+ if ( ! err ) {
211+ expect ( err ) . not . to . be . ok ( ) ;
212+ expect ( data ) . to . have . property ( 'errcode' , 0 ) ;
213+ expect ( data ) . to . have . property ( 'errmsg' , 'ok' ) ;
214+ } else {
215+ expect ( err ) . to . be . ok ( ) ;
216+ expect ( err ) . to . have . property ( 'name' , 'WeChatAPIError' ) ;
217+ expect ( err ) . to . have . property ( 'message' , 'invalid media_id' ) ;
218+ }
219+ done ( ) ;
220+ } ) ;
221+ } ) ;
222+
223+ describe ( 'mock err' , function ( ) {
224+ mockError ( ) ;
225+
226+ it ( 'should not ok' , function ( done ) {
227+ api . sendNews ( puling , articles , function ( err , data ) {
69228 expect ( err ) . to . be . ok ( ) ;
70229 expect ( err . name ) . to . be ( 'WeChatAPIError' ) ;
71230 expect ( err . message ) . to . be ( 'mock error' ) ;
0 commit comments