@@ -217,4 +217,77 @@ describe('leetcode_client', function() {
217
217
} ) ;
218
218
} ) ;
219
219
} ) ; // #submitProblem
220
+
221
+ describe ( '#getSubmissions' , function ( ) {
222
+ it ( 'should ok' , function ( done ) {
223
+ var problem = {
224
+ id : 1 ,
225
+ name : 'Two Sum' ,
226
+ key : 'two-sum' ,
227
+ link : 'https://leetcode.com/problems/two-sum' ,
228
+ locked : false
229
+ } ;
230
+
231
+ nock ( 'https://leetcode.com' )
232
+ . get ( '/problems/two-sum/submissions/' )
233
+ . replyWithFile ( 200 , './test/mock/two-sum.submissions.html.20161006' ) ;
234
+
235
+ client . getSubmissions ( problem , function ( e , submissions ) {
236
+ assert . equal ( e , null ) ;
237
+
238
+ assert . equal ( submissions . length , 2 ) ;
239
+
240
+ assert . deepEqual ( submissions [ 0 ] , {
241
+ id : '73790064' ,
242
+ lang : 'cpp' ,
243
+ runtime : '9 ms' ,
244
+ path : '/submissions/detail/73790064/' ,
245
+ state : 'Accepted'
246
+ } ) ;
247
+
248
+ assert . deepEqual ( submissions [ 1 ] , {
249
+ id : '73489296' ,
250
+ lang : 'cpp' ,
251
+ runtime : 'N/A' ,
252
+ path : '/submissions/detail/73489296/' ,
253
+ state : 'Wrong Answer'
254
+ } ) ;
255
+
256
+ done ( ) ;
257
+ } ) ;
258
+ } ) ;
259
+ } ) ; // #getSubmissions
260
+
261
+ describe ( '#getSubmission' , function ( ) {
262
+ it ( 'should ok' , function ( done ) {
263
+ var submission = {
264
+ id : '73790064' ,
265
+ lang : 'cpp' ,
266
+ runtime : '9 ms' ,
267
+ path : '/submissions/detail/73790064/' ,
268
+ state : 'Accepted'
269
+ } ;
270
+
271
+ nock ( 'https://leetcode.com' )
272
+ . get ( '/submissions/detail/73790064/' )
273
+ . replyWithFile ( 200 , './test/mock/two-sum.submission.73790064.html.20161006' ) ;
274
+
275
+ client . getSubmission ( submission , function ( e , submission ) {
276
+ assert . equal ( e , null ) ;
277
+
278
+ assert . deepEqual ( submission . code ,
279
+ [
280
+ 'class Solution {' ,
281
+ 'public:' ,
282
+ ' vector<int> twoSum(vector<int>& nums, int target) {' ,
283
+ ' return res;' ,
284
+ ' }' ,
285
+ '};' ,
286
+ ''
287
+ ] . join ( '\r\n' ) ) ;
288
+
289
+ done ( ) ;
290
+ } ) ;
291
+ } ) ;
292
+ } ) ; // #getSubmission
220
293
} ) ;
0 commit comments