@@ -20,6 +20,7 @@ describe('leetcode_client', function() {
20
20
msg : 'session expired, please login again' ,
21
21
statusCode : - 1
22
22
} ;
23
+ var URL_ALGORITHMS = 'https://leetcode.com/api/problems/algorithms/' ;
23
24
24
25
before ( function ( ) {
25
26
config . init ( ) ;
@@ -46,10 +47,10 @@ describe('leetcode_client', function() {
46
47
47
48
it ( 'should ok' , function ( done ) {
48
49
config . AUTO_LOGIN = true ;
49
- nock ( config . URL_PROBLEMS ) . get ( '/' ) . reply ( 403 ) ;
50
- nock ( config . URL_PROBLEMS ) . get ( '/' ) . replyWithFile ( 200 , './test/mock/problems.json.20160911' ) ;
50
+ nock ( URL_ALGORITHMS ) . get ( '/' ) . reply ( 403 ) ;
51
+ nock ( URL_ALGORITHMS ) . get ( '/' ) . replyWithFile ( 200 , './test/mock/problems.json.20160911' ) ;
51
52
52
- client . getProblems ( USER , function ( e , problems ) {
53
+ client . getProblems ( 'algorithms' , USER , function ( e , problems ) {
53
54
assert . equal ( e , null ) ;
54
55
assert . equal ( problems . length , 377 ) ;
55
56
done ( ) ;
@@ -58,19 +59,19 @@ describe('leetcode_client', function() {
58
59
59
60
it ( 'should fail if no auto login' , function ( done ) {
60
61
config . AUTO_LOGIN = false ;
61
- nock ( config . URL_PROBLEMS ) . get ( '/' ) . reply ( 403 ) ;
62
+ nock ( URL_ALGORITHMS ) . get ( '/' ) . reply ( 403 ) ;
62
63
63
- client . getProblems ( USER , function ( e , problems ) {
64
+ client . getProblems ( 'algorithms' , USER , function ( e , problems ) {
64
65
assert . deepEqual ( e , EXPIRED_ERROR ) ;
65
66
done ( ) ;
66
67
} ) ;
67
68
} ) ;
68
69
69
70
it ( 'should fail if other error' , function ( done ) {
70
71
config . AUTO_LOGIN = true ;
71
- nock ( config . URL_PROBLEMS ) . get ( '/' ) . reply ( 503 ) ;
72
+ nock ( URL_ALGORITHMS ) . get ( '/' ) . reply ( 503 ) ;
72
73
73
- client . getProblems ( USER , function ( e , problems ) {
74
+ client . getProblems ( 'algorithms' , USER , function ( e , problems ) {
74
75
var expected = {
75
76
msg : 'http error' ,
76
77
statusCode : 503
@@ -82,13 +83,13 @@ describe('leetcode_client', function() {
82
83
83
84
it ( 'should fail if http error in relogin' , function ( done ) {
84
85
config . AUTO_LOGIN = true ;
85
- nock ( config . URL_PROBLEMS ) . get ( '/' ) . reply ( 403 ) ;
86
- nock ( config . URL_PROBLEMS ) . get ( '/' ) . reply ( 403 ) ;
86
+ nock ( URL_ALGORITHMS ) . get ( '/' ) . reply ( 403 ) ;
87
+ nock ( URL_ALGORITHMS ) . get ( '/' ) . reply ( 403 ) ;
87
88
core . login = function ( user , cb ) {
88
89
return cb ( 'unknown error!' ) ;
89
90
} ;
90
91
91
- client . getProblems ( USER , function ( e , problems ) {
92
+ client . getProblems ( 'algorithms' , USER , function ( e , problems ) {
92
93
assert . deepEqual ( e , EXPIRED_ERROR ) ;
93
94
done ( ) ;
94
95
} ) ;
@@ -97,9 +98,9 @@ describe('leetcode_client', function() {
97
98
98
99
describe ( '#getProblems' , function ( ) {
99
100
it ( 'should ok' , function ( done ) {
100
- nock ( config . URL_PROBLEMS ) . get ( '/' ) . replyWithFile ( 200 , './test/mock/problems.json.20160911' ) ;
101
+ nock ( URL_ALGORITHMS ) . get ( '/' ) . replyWithFile ( 200 , './test/mock/problems.json.20160911' ) ;
101
102
102
- client . getProblems ( USER , function ( e , problems ) {
103
+ client . getProblems ( 'algorithms' , USER , function ( e , problems ) {
103
104
assert . equal ( e , null ) ;
104
105
assert . equal ( problems . length , 377 ) ;
105
106
done ( ) ;
@@ -108,9 +109,9 @@ describe('leetcode_client', function() {
108
109
109
110
it ( 'should fail if not login' , function ( done ) {
110
111
config . AUTO_LOGIN = false ;
111
- nock ( config . URL_PROBLEMS ) . get ( '/' ) . replyWithFile ( 200 , './test/mock/problems.nologin.json.20161015' ) ;
112
+ nock ( URL_ALGORITHMS ) . get ( '/' ) . replyWithFile ( 200 , './test/mock/problems.nologin.json.20161015' ) ;
112
113
113
- client . getProblems ( USER , function ( e , problems ) {
114
+ client . getProblems ( 'algorithms' , USER , function ( e , problems ) {
114
115
assert . deepEqual ( e , EXPIRED_ERROR ) ;
115
116
done ( ) ;
116
117
} ) ;
0 commit comments