| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,94 @@ | |||
| 1 | + var assert = require('chai').assert; | ||
| 2 | + var rewire = require('rewire'); | ||
| 3 | + | ||
| 4 | + var log = require('../../lib/log'); | ||
| 5 | + | ||
| 6 | + var config = rewire('../../lib/config'); | ||
| 7 | + var session = rewire('../../lib/session'); | ||
| 8 | + var plugin = rewire('../../lib/plugins/retry'); | ||
| 9 | + | ||
| 10 | + describe('plugin:retry', function() { | ||
| 11 | + var USER = {}; | ||
| 12 | + var NEXT = {}; | ||
| 13 | + var PROBLEMS = [{id: 0, name: 'name0'}]; | ||
| 14 | + | ||
| 15 | + before(function() { | ||
| 16 | + log.init(); | ||
| 17 | + config.init(); | ||
| 18 | + plugin.init(); | ||
| 19 | + | ||
| 20 | + session.getUser = function() { | ||
| 21 | + return USER; | ||
| 22 | + }; | ||
| 23 | + | ||
| 24 | + plugin.__set__('config', config); | ||
| 25 | + plugin.__set__('session', session); | ||
| 26 | + plugin.setNext(NEXT); | ||
| 27 | + }); | ||
| 28 | + | ||
| 29 | + it('should fail if auto login disabled', function(done) { | ||
| 30 | + config.AUTO_LOGIN = false; | ||
| 31 | + NEXT.getProblems = function(cb) { | ||
| 32 | + return cb(session.errors.EXPIRED); | ||
| 33 | + }; | ||
| 34 | + | ||
| 35 | + plugin.getProblems(function(e, problems) { | ||
| 36 | + assert.equal(e, session.errors.EXPIRED); | ||
| 37 | + done(); | ||
| 38 | + }); | ||
| 39 | + }); | ||
| 40 | + | ||
| 41 | + it('should retry if session expired', function(done) { | ||
| 42 | + config.AUTO_LOGIN = true; | ||
| 43 | + | ||
| 44 | + var n = 0; | ||
| 45 | + NEXT.getProblems = function(cb) { | ||
| 46 | + ++n; | ||
| 47 | + if (n === 1) return cb(session.errors.EXPIRED); | ||
| 48 | + return cb(null, PROBLEMS); | ||
| 49 | + }; | ||
| 50 | + | ||
| 51 | + NEXT.login = function(user, cb) { | ||
| 52 | + return cb(null, user); | ||
| 53 | + }; | ||
| 54 | + | ||
| 55 | + plugin.getProblems(function(e, problems) { | ||
| 56 | + assert.equal(e, null); | ||
| 57 | + assert.equal(problems, PROBLEMS); | ||
| 58 | + done(); | ||
| 59 | + }); | ||
| 60 | + }); | ||
| 61 | + | ||
| 62 | + it('should fail if user expired locally', function(done) { | ||
| 63 | + config.AUTO_LOGIN = true; | ||
| 64 | + | ||
| 65 | + var n = 0; | ||
| 66 | + NEXT.getProblems = function(cb) { | ||
| 67 | + ++n; | ||
| 68 | + if (n === 1) return cb(session.errors.EXPIRED); | ||
| 69 | + return cb(null, PROBLEMS); | ||
| 70 | + }; | ||
| 71 | + | ||
| 72 | + session.getUser = function() { | ||
| 73 | + return null; | ||
| 74 | + }; | ||
| 75 | + | ||
| 76 | + plugin.getProblems(function(e, problems) { | ||
| 77 | + assert.equal(e, null); | ||
| 78 | + assert.equal(problems, PROBLEMS); | ||
| 79 | + done(); | ||
| 80 | + }); | ||
| 81 | + }); | ||
| 82 | + | ||
| 83 | + it('should fail if other errors', function(done) { | ||
| 84 | + config.AUTO_LOGIN = true; | ||
| 85 | + NEXT.getProblems = function(cb) { | ||
| 86 | + return cb('unknown error'); | ||
| 87 | + }; | ||
| 88 | + | ||
| 89 | + plugin.getProblems(function(e, problems) { | ||
| 90 | + assert.equal(e, 'unknown error'); | ||
| 91 | + done(); | ||
| 92 | + }); | ||
| 93 | + }); | ||
| 94 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments