@@ -8,6 +8,9 @@ var API = require('../').API;
88
99var puling = 'ofL4cs7hr04cJIcu600_W-ZwwxHg' ;
1010var imageId = 'XDZxzuRWBPqI4R9n_nNR5uRVZVQCSneMoELyWKflwM2qF9K38vnVFzgaD97uCTUu' ;
11+ var voiceId = '9R5BhAum7AEaGhwku0WhgvtO4C_7Xs78NoiRvm6v7IyoTljE4HH5o8E_UfnPrL0p' ;
12+ var thumbId = 'BHxGDVy7WY6BCOcv3AwbywUE630Vw0tAV_V8bzBaCZid4Km5fwXrVOso3X0zas4n' ;
13+ var movieId = 'b4F8SfaZZQwalDxwPjd923ACV5IUeYvZ9-dYKf5ytXrS-IImXEkl2U8Fl5EH-jCF' ;
1114
1215describe ( 'common.js' , function ( ) {
1316 describe ( 'getAccessToken' , function ( ) {
@@ -493,6 +496,14 @@ describe('common.js', function () {
493496 } ) ;
494497 } ) ;
495498
499+ it ( 'getWhichGroup should ok' , function ( done ) {
500+ api . getWhichGroup ( puling , function ( err , data , res ) {
501+ expect ( err ) . not . to . be . ok ( ) ;
502+ expect ( data ) . to . have . property ( 'groupid' ) ;
503+ done ( ) ;
504+ } ) ;
505+ } ) ;
506+
496507 it ( 'createGroup should ok' , function ( done ) {
497508 api . createGroup ( 'new group' , function ( err , data , res ) {
498509 expect ( err ) . not . to . be . ok ( ) ;
@@ -566,7 +577,7 @@ describe('common.js', function () {
566577 } ) ;
567578
568579 it ( 'sendVoice should ok' , function ( done ) {
569- api . sendVoice ( puling , 'imageId' , function ( err , data , res ) {
580+ api . sendVoice ( puling , voiceId , function ( err , data , res ) {
570581 expect ( err ) . not . to . be . ok ( ) ;
571582 expect ( data ) . to . have . property ( 'errcode' , 0 ) ;
572583 expect ( data ) . to . have . property ( 'errmsg' , 'ok' ) ;
@@ -575,10 +586,10 @@ describe('common.js', function () {
575586 } ) ;
576587
577588 it ( 'sendVideo should ok' , function ( done ) {
578- api . sendVideo ( puling , 'mediaId' , 'thumbMediaId' , function ( err , data , res ) {
579- should . exist ( err ) ;
580- err . name . should . be . equal ( 'WeChatAPIError' ) ;
581- err . message . should . be . equal ( 'invalid appid ') ;
589+ api . sendVideo ( puling , movieId , thumbId , function ( err , data , res ) {
590+ expect ( err ) . not . to . be . ok ( ) ;
591+ expect ( data ) . to . have . property ( 'errcode' , 0 ) ;
592+ expect ( data ) . to . have . property ( 'errmsg' , 'ok ') ;
582593 done ( ) ;
583594 } ) ;
584595 } ) ;
@@ -589,13 +600,13 @@ describe('common.js', function () {
589600 "description" :"MUSIC_DESCRIPTION" , // 可选
590601 "musicurl" :"MUSIC_URL" ,
591602 "hqmusicurl" :"HQ_MUSIC_URL" ,
592- "thumb_media_id" :"THUMB_MEDIA_ID"
603+ "thumb_media_id" : thumbId
593604 } ;
594605
595606 api . sendMusic ( puling , music , function ( err , data , res ) {
596- should . exist ( err ) ;
597- err . name . should . be . equal ( 'WeChatAPIError' ) ;
598- err . message . should . be . equal ( 'invalid appid ') ;
607+ expect ( err ) . not . to . be . ok ( ) ;
608+ expect ( data ) . to . have . property ( 'errcode' , 0 ) ;
609+ expect ( data ) . to . have . property ( 'errmsg' , 'ok ') ;
599610 done ( ) ;
600611 } ) ;
601612 } ) ;
@@ -618,48 +629,25 @@ describe('common.js', function () {
618629 } ) ;
619630 } ) ;
620631
621- it ( 'deliverNotify should ok' , function ( done ) {
622- api . deliverNotify ( '{}' , function ( err , menu ) {
623- should . exist ( err ) ;
624- err . name . should . be . equal ( 'WeChatAPIError' ) ;
625- err . message . should . be . equal ( 'invalid appid' ) ;
626- done ( ) ;
627- } ) ;
628- } ) ;
629-
630- it ( 'orderQuery should ok' , function ( done ) {
631- api . orderQuery ( '{}' , function ( err , menu ) {
632- should . exist ( err ) ;
633- err . name . should . be . equal ( 'WeChatAPIError' ) ;
634- err . message . should . be . equal ( 'invalid appid' ) ;
635- done ( ) ;
636- } ) ;
637- } ) ;
638-
639632 describe ( 'upload media' , function ( ) {
633+ var fixture = {
634+ 'Image' : path . join ( __dirname , './fixture/image.jpg' ) ,
635+ 'Voice' : path . join ( __dirname , './fixture/test.mp3' ) ,
636+ 'Video' : path . join ( __dirname , './fixture/movie.mp4' ) ,
637+ 'Thumb' : path . join ( __dirname , './fixture/pic.jpg' )
638+ } ;
640639 [ 'Image' , 'Voice' , 'Video' , 'Thumb' ] . forEach ( function ( method ) {
641- // before(function () {
642- // muk(urllib, 'request', function (url, args, callback) {
643- // var resp = {
644- // "type":"image",
645- // "media_id":"usr5xL_gcxapoRjwH3bQZw_zKvcXL-DU4tRJtLtrtN71-3bXL52p3xX63ebp7tqA",
646- // "created_at":1383233542
647- // };
648- // process.nextTick(function () {
649- // callback(null, resp);
650- // });
651- // });
652- // });
653-
654- // after(function () {
655- // muk.restore();
656- // });
657640 it ( 'upload' + method + ' should ok' , function ( done ) {
658- api [ 'upload' + method ] ( path . join ( __dirname , './fixture/image.jpg' ) , function ( err , data , res ) {
641+ // 上传文件比较慢
642+ this . timeout ( 60000 ) ;
643+ api [ 'upload' + method ] ( fixture [ method ] , function ( err , data , res ) {
659644 should . not . exist ( err ) ;
660- console . log ( data ) ;
661- data . should . have . property ( 'type' , 'image' ) ;
662- data . should . have . property ( 'media_id' ) ;
645+ data . should . have . property ( 'type' , method . toLowerCase ( ) ) ;
646+ if ( method === 'Thumb' ) {
647+ data . should . have . property ( 'thumb_media_id' ) ;
648+ } else {
649+ data . should . have . property ( 'media_id' ) ;
650+ }
663651 data . should . have . property ( 'created_at' ) ;
664652 done ( ) ;
665653 } ) ;
@@ -759,4 +747,25 @@ describe('common.js', function () {
759747 } ) ;
760748 } ) ;
761749 } ) ;
750+
751+ describe ( 'pay' , function ( ) {
752+ var api = new API ( 'appid' , 'secret' ) ;
753+ it ( 'deliverNotify should ok' , function ( done ) {
754+ api . deliverNotify ( '{}' , function ( err , menu ) {
755+ should . exist ( err ) ;
756+ err . name . should . be . equal ( 'WeChatAPIError' ) ;
757+ err . message . should . be . equal ( 'invalid appid' ) ;
758+ done ( ) ;
759+ } ) ;
760+ } ) ;
761+
762+ it ( 'orderQuery should ok' , function ( done ) {
763+ api . orderQuery ( '{}' , function ( err , menu ) {
764+ should . exist ( err ) ;
765+ err . name . should . be . equal ( 'WeChatAPIError' ) ;
766+ err . message . should . be . equal ( 'invalid appid' ) ;
767+ done ( ) ;
768+ } ) ;
769+ } ) ;
770+ } ) ;
762771} ) ;
0 commit comments