Skip to content

Commit 68b6e13

Browse files
committed
fix: fixed test cases
Fixed all test cases relating to getProblem(s) to adapt new parameter
1 parent 9caafb2 commit 68b6e13

File tree

5 files changed

+41
-40
lines changed

5 files changed

+41
-40
lines changed

lib/commands/list.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ const cmd = {
1616
return yargs
1717
.option('q', core.filters.query)
1818
.option('s', {
19-
alias: 'stat',
20-
type: 'boolean',
21-
default: false,
19+
alias: 'stat',
20+
type: 'boolean',
21+
default: false,
2222
describe: 'Show statistics of listed questions'
2323
})
2424
.option('t', core.filters.tag)
2525
.option('x', {
26-
alias: 'extra',
27-
type: 'boolean',
28-
default: false,
26+
alias: 'extra',
27+
type: 'boolean',
28+
default: false,
2929
describe: 'Show extra details: category, companies, tags.'
3030
})
3131
.option('T', {
32-
alias: 'dontTranslate',
33-
type: 'boolean',
34-
default: false,
32+
alias: 'dontTranslate',
33+
type: 'boolean',
34+
default: false,
3535
describe: 'Set to true to disable endpoint\'s translation',
3636
})
3737
.positional('keyword', {

lib/commands/show.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ const cmd = {
5858
describe: 'Show extra question details in source code'
5959
})
6060
.option('T', {
61-
alias: 'dontTranslate',
62-
type: 'boolean',
63-
default: false,
61+
alias: 'dontTranslate',
62+
type: 'boolean',
63+
default: false,
6464
describe: 'Set to true to disable endpoint\'s translation',
6565
})
6666
.positional('keyword', {

lib/commands/submission.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ const cmd = {
4343
describe: 'Show extra question details in submission code'
4444
})
4545
.option('T', {
46-
alias: 'dontTranslate',
47-
type: 'boolean',
48-
default: false,
46+
alias: 'dontTranslate',
47+
type: 'boolean',
48+
default: false,
4949
describe: 'Set to true to disable endpoint\'s translation',
5050
})
5151
.positional('keyword', {

test/plugins/test_cache.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('plugin:cache', function() {
5252
it('should getProblems w/ cache ok', function(done) {
5353
cache.set('problems', PROBLEMS);
5454

55-
plugin.getProblems(function(e, problems) {
55+
plugin.getProblems(false, function(e, problems) {
5656
assert.equal(e, null);
5757
assert.deepEqual(problems, PROBLEMS);
5858
done();
@@ -61,9 +61,9 @@ describe('plugin:cache', function() {
6161

6262
it('should getProblems w/o cache ok', function(done) {
6363
cache.del('problems');
64-
next.getProblems = cb => cb(null, PROBLEMS);
64+
next.getProblems = (needT, cb) => cb(null, PROBLEMS);
6565

66-
plugin.getProblems(function(e, problems) {
66+
plugin.getProblems(false, function(e, problems) {
6767
assert.equal(e, null);
6868
assert.deepEqual(problems, PROBLEMS);
6969
done();
@@ -72,9 +72,9 @@ describe('plugin:cache', function() {
7272

7373
it('should getProblems w/o cache fail if client error', function(done) {
7474
cache.del('problems');
75-
next.getProblems = cb => cb('client getProblems error');
75+
next.getProblems = (needT, cb) => cb('client getProblems error');
7676

77-
plugin.getProblems(function(e, problems) {
77+
plugin.getProblems(false, function(e, problems) {
7878
assert.equal(e, 'client getProblems error');
7979
done();
8080
});
@@ -86,7 +86,7 @@ describe('plugin:cache', function() {
8686
cache.set('problems', PROBLEMS);
8787
cache.set('0.slug0.algorithms', PROBLEMS[0]);
8888

89-
plugin.getProblem(_.clone(PROBLEM), function(e, problem) {
89+
plugin.getProblem(_.clone(PROBLEM), false, function(e, problem) {
9090
assert.equal(e, null);
9191
assert.deepEqual(problem, PROBLEMS[0]);
9292
done();
@@ -96,9 +96,9 @@ describe('plugin:cache', function() {
9696
it('should getProblem w/o cache ok', function(done) {
9797
cache.set('problems', PROBLEMS);
9898
cache.del('0.slug0.algorithms');
99-
next.getProblem = (problem, cb) => cb(null, PROBLEMS[0]);
99+
next.getProblem = (problem, needT, cb) => cb(null, PROBLEMS[0]);
100100

101-
plugin.getProblem(_.clone(PROBLEM), function(e, problem) {
101+
plugin.getProblem(_.clone(PROBLEM), false, function(e, problem) {
102102
assert.equal(e, null);
103103
assert.deepEqual(problem, PROBLEMS[0]);
104104
done();
@@ -108,9 +108,9 @@ describe('plugin:cache', function() {
108108
it('should getProblem fail if client error', function(done) {
109109
cache.set('problems', PROBLEMS);
110110
cache.del('0.slug0.algorithms');
111-
next.getProblem = (problem, cb) => cb('client getProblem error');
111+
next.getProblem = (problem, needT, cb) => cb('client getProblem error');
112112

113-
plugin.getProblem(_.clone(PROBLEM), function(e, problem) {
113+
plugin.getProblem(_.clone(PROBLEM), false, function(e, problem) {
114114
assert.equal(e, 'client getProblem error');
115115
done();
116116
});
@@ -140,7 +140,7 @@ describe('plugin:cache', function() {
140140
const ret = plugin.updateProblem(PROBLEMS[0], kv);
141141
assert.equal(ret, true);
142142

143-
plugin.getProblems(function(e, problems) {
143+
plugin.getProblems(false, function(e, problems) {
144144
assert.equal(e, null);
145145
assert.deepEqual(problems, [
146146
{id: 0, fid: 0, name: 'name0', slug: 'slug0', value: 'value00', starred: false, desc: '<pre></pre>', likes: '1', dislikes: '1', category: 'algorithms'},

test/test_core.js

+15-14
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ describe('core', function() {
4040

4141
beforeEach(function() {
4242
next = {};
43-
next.getProblems = cb => cb(null, PROBLEMS);
44-
next.getProblem = (p, cb) => cb(null, p);
43+
next.getProblems = (needTrans, cb) => cb(null, PROBLEMS);
44+
next.getProblem = (p, needTrans, cb) => cb(null, p);
4545

4646
core = rewire('../lib/core');
4747
core.setNext(next);
@@ -68,7 +68,7 @@ describe('core', function() {
6868
let n = cases.length;
6969

7070
for (let x of cases) {
71-
core.filterProblems({query: x[0]}, function(e, problems) {
71+
core.filterProblems({query: x[0], dontTranslate: false}, function(e, problems) {
7272
assert.notExists(e);
7373
assert.equal(problems.length, x[1].length);
7474

@@ -90,7 +90,7 @@ describe('core', function() {
9090
let n = cases.length;
9191

9292
for (let x of cases) {
93-
core.filterProblems({tag: x[0]}, function(e, problems) {
93+
core.filterProblems({ tag: x[0], dontTranslate: false}, function(e, problems) {
9494
assert.notExists(e);
9595
assert.equal(problems.length, x[1].length);
9696

@@ -102,7 +102,7 @@ describe('core', function() {
102102
});
103103

104104
it('should fail if getProblems error', function(done) {
105-
next.getProblems = cb => cb('getProblems error');
105+
next.getProblems = (needT, cb) => cb('getProblems error');
106106
core.filterProblems({}, function(e) {
107107
assert.equal(e, 'getProblems error');
108108
done();
@@ -340,50 +340,51 @@ describe('core', function() {
340340
}); // #exportProblem
341341

342342
describe('#getProblem', function() {
343-
it('should get by id ok', function(done) {
344-
core.getProblem(0, function(e, problem) {
343+
it('should get by id ok', function (done) {
344+
// set needTranslate to false here because it's not used anyways
345+
core.getProblem(0, false, function(e, problem) {
345346
assert.notExists(e);
346347
assert.deepEqual(problem, PROBLEMS[0]);
347348
done();
348349
});
349350
});
350351

351352
it('should get by key ok', function(done) {
352-
core.getProblem('slug0', function(e, problem) {
353+
core.getProblem('slug0', false, function(e, problem) {
353354
assert.notExists(e);
354355
assert.deepEqual(problem, PROBLEMS[0]);
355356
done();
356357
});
357358
});
358359

359360
it('should fail if not found', function(done) {
360-
core.getProblem(3, function(e, problem) {
361+
core.getProblem(3, false, function(e, problem) {
361362
assert.equal(e, 'Problem not found!');
362363
done();
363364
});
364365
});
365366

366367
it('should fail if client error', function(done) {
367-
next.getProblem = (problem, cb) => cb('client getProblem error');
368+
next.getProblem = (problem, needT, cb) => cb('client getProblem error');
368369

369-
core.getProblem(0, function(e, problem) {
370+
core.getProblem(0, false, function(e, problem) {
370371
assert.equal(e, 'client getProblem error');
371372
done();
372373
});
373374
});
374375

375376
it('should ok if problem is already there', function(done) {
376-
core.getProblem(PROBLEMS[1], function(e, problem) {
377+
core.getProblem(PROBLEMS[1], false, function(e, problem) {
377378
assert.notExists(e);
378379
assert.deepEqual(problem, PROBLEMS[1]);
379380
done();
380381
});
381382
});
382383

383384
it('should fail if getProblems error', function(done) {
384-
next.getProblems = cb => cb('getProblems error');
385+
next.getProblems = (needT, cb) => cb('getProblems error');
385386

386-
core.getProblem(0, function(e, problem) {
387+
core.getProblem(0, false, function(e, problem) {
387388
assert.equal(e, 'getProblems error');
388389
done();
389390
});

0 commit comments

Comments
 (0)