Skip to content

Commit 27037b8

Browse files
committed
Add UT for leetcode_client.getProblems
Signed-off-by: Eric Wang <[email protected]>
1 parent 50b7c53 commit 27037b8

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

lib/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function initConfig() {
2323
var config = defaultConfig;
2424

2525
// check local config: ~/.lcconfig
26-
var f = h.getHomeDir() + '/.lcconfig';
26+
var f = h.getConfigFile();
2727
if (fs.existsSync(f)) {
2828
var localConfig = JSON.parse(fs.readFileSync(f));
2929
_.extend(defaultConfig, localConfig);

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"eslint": "^3.3.1",
4444
"eslint-config-google": "^0.6.0",
4545
"mocha": "^3.0.2",
46+
"nock": "^8.0.0",
4647
"nyc": "^8.1.0"
4748
}
4849
}

test/mock/problems.json

+1
Large diffs are not rendered by default.

test/test_leetcode_client.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var assert = require('chai').assert;
2+
var nock = require('nock');
3+
4+
var client = require('../lib/leetcode_client');
5+
var config = require('../lib/config');
6+
7+
describe('leetcode_client', function() {
8+
describe('#getProblems', function() {
9+
it('should ok', function(done) {
10+
nock(config.PROBLEMS_URL)
11+
.get('/')
12+
.replyWithFile(200, './test/mock/problems.json');
13+
14+
client.getProblems(function(e, problems) {
15+
assert.equal(e, null);
16+
assert.equal(problems.length, 382);
17+
done();
18+
});
19+
});
20+
}); // #getProblems
21+
});

0 commit comments

Comments
 (0)