@@ -13,86 +13,6 @@ var thumbId = 'BHxGDVy7WY6BCOcv3AwbywUE630Vw0tAV_V8bzBaCZid4Km5fwXrVOso3X0zas4n'
1313var movieId = 'b4F8SfaZZQwalDxwPjd923ACV5IUeYvZ9-dYKf5ytXrS-IImXEkl2U8Fl5EH-jCF' ;
1414
1515describe ( 'common.js' , function ( ) {
16- describe ( 'mixin' , function ( ) {
17- it ( 'should ok' , function ( ) {
18- API . mixin ( { sayHi : function ( ) { } } ) ;
19- expect ( API . prototype ) . to . have . property ( 'sayHi' ) ;
20- } ) ;
21-
22- it ( 'should not ok when override method' , function ( ) {
23- var obj = { sayHi : function ( ) { } } ;
24- expect ( API . mixin ) . withArgs ( obj ) . to . throwException ( / D o n ' t a l l o w o v e r r i d e e x i s t e d p r o t o t y p e m e t h o d \. / ) ;
25- } ) ;
26- } ) ;
27-
28- describe ( 'getAccessToken' , function ( ) {
29- it ( 'should ok' , function ( done ) {
30- var api = new API ( config . appid , config . appsecret ) ;
31- api . getAccessToken ( function ( err , token ) {
32- should . not . exist ( err ) ;
33- expect ( token ) . to . only . have . keys ( 'accessToken' , 'expireTime' ) ;
34- done ( ) ;
35- } ) ;
36- } ) ;
37-
38- it ( 'should not ok' , function ( done ) {
39- var api = new API ( 'appid' , 'secret' ) ;
40- api . getAccessToken ( function ( err , token ) {
41- should . exist ( err ) ;
42- err . name . should . be . equal ( 'WeChatAPIError' ) ;
43- err . message . should . be . equal ( 'invalid credential' ) ;
44- done ( ) ;
45- } ) ;
46- } ) ;
47-
48- describe ( 'mock urllib err' , function ( ) {
49- before ( function ( ) {
50- muk ( urllib , 'request' , function ( url , args , callback ) {
51- var err = new Error ( 'Urllib Error' ) ;
52- err . name = 'UrllibError' ;
53- callback ( err ) ;
54- } ) ;
55- } ) ;
56-
57- after ( function ( ) {
58- muk . restore ( ) ;
59- } ) ;
60-
61- it ( 'should get mock error' , function ( done ) {
62- var api = new API ( 'appid' , 'secret' ) ;
63- api . getAccessToken ( function ( err , token ) {
64- should . exist ( err ) ;
65- err . name . should . be . equal ( 'WeChatAPIUrllibError' ) ;
66- err . message . should . be . equal ( 'Urllib Error' ) ;
67- done ( ) ;
68- } ) ;
69- } ) ;
70- } ) ;
71-
72- describe ( 'mock token' , function ( ) {
73- before ( function ( ) {
74- muk ( urllib , 'request' , function ( url , args , callback ) {
75- process . nextTick ( function ( ) {
76- callback ( null , { "access_token" : "ACCESS_TOKEN" , "expires_in" : 7200 } ) ;
77- } ) ;
78- } ) ;
79- } ) ;
80- after ( function ( ) {
81- muk . restore ( ) ;
82- } ) ;
83-
84- it ( 'should ok' , function ( done ) {
85- var api = new API ( 'appid' , 'secret' ) ;
86- api . getAccessToken ( function ( err , token ) {
87- should . not . exist ( err ) ;
88- token . should . have . property ( 'accessToken' , 'ACCESS_TOKEN' ) ;
89- // token.should.have.property('expireTime', 7200);
90- done ( ) ;
91- } ) ;
92- } ) ;
93- } ) ;
94- } ) ;
95-
9616 describe ( 'isAccessTokenValid' , function ( ) {
9717 it ( 'should invalid' , function ( ) {
9818 var token = new API . AccessToken ( 'token' , new Date ( ) . getTime ( ) - 7200 * 1000 ) ;
@@ -630,41 +550,5 @@ describe('common.js', function () {
630550 } ) ;
631551 } ) ;
632552 } ) ;
633-
634- describe ( 'getRecords mock' , function ( ) {
635- before ( function ( ) {
636- muk ( urllib , 'request' , function ( url , args , callback ) {
637- var data = { "recordlist" : [ ] } ;
638- var res = {
639- headers : {
640- 'content-type' : 'application/json'
641- }
642- } ;
643- process . nextTick ( function ( ) {
644- callback ( null , data , res ) ;
645- } ) ;
646- } ) ;
647- } ) ;
648-
649- after ( function ( ) {
650- muk . restore ( ) ;
651- } ) ;
652-
653- it ( 'getRecords should ok' , function ( done ) {
654- var condition = {
655- "starttime" : 123456789 ,
656- "endtime" : 987654321 ,
657- // "openid" : "OPENID",
658- "pagesize" : 10 ,
659- "pageindex" : 1 ,
660- } ;
661-
662- api . getRecords ( condition , function ( err , data , res ) {
663- expect ( err ) . not . to . be . ok ( ) ;
664- expect ( data ) . to . have . property ( 'recordlist' ) ;
665- done ( ) ;
666- } ) ;
667- } ) ;
668- } ) ;
669553 } ) ;
670554} ) ;
0 commit comments