Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f970dc8

Browse files
Add UT for session.
Signed-off-by: Eric Wang <skygragon@gmail.com>
1 parent 25fa7f7 commit f970dc8

File tree

1 file changed

+65
-2
lines changed

1 file changed

+65
-2
lines changed

‎test/plugins/test_leetcode.js

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ describe('plugin:leetcode', function() {
4444
it('should ok', function(done) {
4545
nock('https://leetcode.com')
4646
.get('/accounts/login/')
47-
.reply(200, '', {
48-
'Set-Cookie': [
47+
.reply(200, '', { 'Set-Cookie': [
4948
'csrftoken=LOGIN_CSRF_TOKEN; Max-Age=31449600; Path=/; secure'
5049
]});
5150

@@ -653,4 +652,68 @@ describe('plugin:leetcode', function() {
653652
});
654653
});
655654
}); // #getFavorites
655+
656+
describe('#session', function() {
657+
const DATA = {sessions: []};
658+
659+
it('should getSessions ok', function(done) {
660+
nock('https://leetcode.com')
661+
.post('/session/')
662+
.reply(200, JSON.stringify(DATA));
663+
664+
plugin.getSessions(function(e, sessions) {
665+
assert.notExists(e);
666+
assert.deepEqual(sessions, []);
667+
done();
668+
});
669+
});
670+
671+
it('should activateSessions ok', function(done) {
672+
nock('https://leetcode.com')
673+
.put('/session/', {func: 'activate', target: 1})
674+
.reply(200, JSON.stringify(DATA));
675+
676+
plugin.activateSession({id: 1}, function(e, sessions) {
677+
assert.notExists(e);
678+
assert.deepEqual(sessions, []);
679+
done();
680+
});
681+
});
682+
683+
it('should createSessions ok', function(done) {
684+
nock('https://leetcode.com')
685+
.put('/session/', {func: 'create', name: 's1'})
686+
.reply(200, JSON.stringify(DATA));
687+
688+
plugin.createSession('s1', function(e, sessions) {
689+
assert.notExists(e);
690+
assert.deepEqual(sessions, []);
691+
done();
692+
});
693+
});
694+
695+
it('should deleteSessions ok', function(done) {
696+
nock('https://leetcode.com')
697+
.delete('/session/', {target: 1})
698+
.reply(200, JSON.stringify(DATA));
699+
700+
plugin.deleteSession({id: 1}, function(e, sessions) {
701+
assert.notExists(e);
702+
assert.deepEqual(sessions, []);
703+
done();
704+
});
705+
});
706+
707+
it('should fail if 302 returned', function(done) {
708+
nock('https://leetcode.com')
709+
.post('/session/')
710+
.reply(302);
711+
712+
plugin.getSessions(function(e, sessions) {
713+
assert.deepEqual(e, session.errors.EXPIRED);
714+
assert.notExists(sessions);
715+
done();
716+
});
717+
});
718+
}); // #session
656719
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /