@@ -171,15 +171,19 @@ describe('plugin:leetcode', function() {
171
171
} ) ; // #getCategoryProblems
172
172
173
173
describe ( '#getProblem' , function ( ) {
174
+ beforeEach ( function ( ) {
175
+ PROBLEM . locked = false ;
176
+ } ) ;
177
+
174
178
it ( 'should ok' , function ( done ) {
175
179
nock ( 'https://leetcode.com' )
176
- . get ( '/problems/find-the-difference ' )
177
- . replyWithFile ( 200 , './test/mock/find-the-difference.html.20170714 ' ) ;
180
+ . post ( '/graphql ' )
181
+ . replyWithFile ( 200 , './test/mock/find-the-difference.json.20171216 ' ) ;
178
182
179
183
plugin . getProblem ( PROBLEM , function ( e , problem ) {
180
184
assert . equal ( e , null ) ;
181
- assert . equal ( problem . totalAC , '73.2K ' ) ;
182
- assert . equal ( problem . totalSubmit , '142K ' ) ;
185
+ assert . equal ( problem . totalAC , '89.7K ' ) ;
186
+ assert . equal ( problem . totalSubmit , '175.7K ' ) ;
183
187
assert . equal ( problem . desc ,
184
188
[
185
189
'' ,
@@ -203,7 +207,7 @@ describe('plugin:leetcode', function() {
203
207
''
204
208
] . join ( '\r\n' ) ) ;
205
209
206
- assert . equal ( problem . templates . length , 11 ) ;
210
+ assert . equal ( problem . templates . length , 12 ) ;
207
211
208
212
assert . equal ( problem . templates [ 0 ] . value , 'cpp' ) ;
209
213
assert . equal ( problem . templates [ 0 ] . text , 'C++' ) ;
@@ -221,7 +225,7 @@ describe('plugin:leetcode', function() {
221
225
assert . equal ( problem . templates [ 1 ] . text , 'Java' ) ;
222
226
assert . equal ( problem . templates [ 1 ] . defaultCode ,
223
227
[
224
- 'public class Solution {' ,
228
+ 'class Solution {' ,
225
229
' public char findTheDifference(String s, String t) {' ,
226
230
' ' ,
227
231
' }' ,
@@ -333,15 +337,23 @@ describe('plugin:leetcode', function() {
333
337
'}'
334
338
] . join ( '\n' ) ) ;
335
339
340
+ assert . equal ( problem . templates [ 11 ] . value , 'kotlin' ) ;
341
+ assert . equal ( problem . templates [ 11 ] . text , 'Kotlin' ) ;
342
+ assert . equal ( problem . templates [ 11 ] . defaultCode ,
343
+ [
344
+ 'class Solution {' ,
345
+ ' fun findTheDifference(s: String, t: String): Char {' ,
346
+ ' ' ,
347
+ ' }' ,
348
+ '}'
349
+ ] . join ( '\n' ) ) ;
350
+
336
351
done ( ) ;
337
352
} ) ;
338
353
} ) ;
339
354
340
355
it ( 'should fail if no permission for locked' , function ( done ) {
341
356
PROBLEM . locked = true ;
342
- nock ( 'https://leetcode.com' )
343
- . get ( '/problems/find-the-difference' )
344
- . replyWithFile ( 200 , './test/mock/locked.html.20161015' ) ;
345
357
346
358
plugin . getProblem ( PROBLEM , function ( e , problem ) {
347
359
assert . equal ( e , 'failed to load locked problem!' ) ;
@@ -350,9 +362,7 @@ describe('plugin:leetcode', function() {
350
362
} ) ;
351
363
352
364
it ( 'should fail if session expired' , function ( done ) {
353
- nock ( 'https://leetcode.com' )
354
- . get ( '/problems/find-the-difference' )
355
- . reply ( 403 ) ;
365
+ nock ( 'https://leetcode.com' ) . post ( '/graphql' ) . reply ( 403 ) ;
356
366
357
367
plugin . getProblem ( PROBLEM , function ( e , problem ) {
358
368
assert . equal ( e , session . errors . EXPIRED ) ;
@@ -361,9 +371,7 @@ describe('plugin:leetcode', function() {
361
371
} ) ;
362
372
363
373
it ( 'should fail if http error' , function ( done ) {
364
- nock ( 'https://leetcode.com' )
365
- . get ( '/problems/find-the-difference' )
366
- . reply ( 500 ) ;
374
+ nock ( 'https://leetcode.com' ) . post ( '/graphql' ) . reply ( 500 ) ;
367
375
368
376
plugin . getProblem ( PROBLEM , function ( e , problem ) {
369
377
assert . deepEqual ( e , { msg : 'http error' , statusCode : 500 } ) ;
@@ -372,9 +380,7 @@ describe('plugin:leetcode', function() {
372
380
} ) ;
373
381
374
382
it ( 'should fail if unknown error' , function ( done ) {
375
- nock ( 'https://leetcode.com' )
376
- . get ( '/problems/find-the-difference' )
377
- . replyWithError ( 'unknown error!' ) ;
383
+ nock ( 'https://leetcode.com' ) . post ( '/graphql' ) . replyWithError ( 'unknown error!' ) ;
378
384
379
385
plugin . getProblem ( PROBLEM , function ( e , problem ) {
380
386
assert . equal ( e . message , 'unknown error!' ) ;
0 commit comments