Skip to content

Commit 668b814

Browse files
committed
Add UT for leetcode_client.js
Signed-off-by: Eric Wang <[email protected]>
1 parent d4ab4c9 commit 668b814

4 files changed

+917
-0
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
"extends": "google",
88
"rules": {
99
"key-spacing": [2, { "align": "value" }],
10+
"max-len": [1, 120],
1011
"no-eval": 1, // we use it on purpose
1112
"no-multi-spaces": [2, { exceptions: { "SwitchCase": true }}],
1213
"no-unused-expressions": 1,

test/mock/two-sum.submission.73790064.html.20161006

+458
Large diffs are not rendered by default.

test/mock/two-sum.submissions.html.20161006

+385
Large diffs are not rendered by default.

test/test_leetcode_client.js

+73
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,77 @@ describe('leetcode_client', function() {
217217
});
218218
});
219219
}); // #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
220293
});

0 commit comments

Comments
 (0)