|
| 1 | +import assert from 'assert'; |
| 2 | +import expect from 'must'; |
| 3 | +import nock from 'nock'; |
| 4 | + |
| 5 | +import Github from '../lib/GitHub'; |
| 6 | +import testUser from './fixtures/user.json'; |
| 7 | +import {assertSuccessful, assertFailure} from './helpers/callbacks'; |
| 8 | +import fixtureExhausted from './fixtures/repos-ratelimit-exhausted.js'; |
| 9 | +import fixtureOk from './fixtures/repos-ratelimit-ok.js'; |
| 10 | + |
| 11 | +describe('Rate limit error', function() { |
| 12 | + let github; |
| 13 | + let user; |
| 14 | + let scope; |
| 15 | + |
| 16 | + before(function() { |
| 17 | + github = new Github(); |
| 18 | + user = github.getUser(testUser.USERNAME); |
| 19 | + }); |
| 20 | + |
| 21 | + beforeEach(function() { |
| 22 | + scope = fixtureExhausted(); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should reject promise with 403 error', function() { |
| 26 | + return user.listRepos().then(function() { |
| 27 | + assert.fail(undefined, undefined, 'Promise was resolved instead of rejected'); |
| 28 | + }, function(error) { |
| 29 | + expect(error).to.be.an.error(); |
| 30 | + expect(error).to.have.own('response'); |
| 31 | + expect(error.response).to.have.own('status'); |
| 32 | + expect(error.response.status).to.be(403); |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should call callback', function(done) { |
| 37 | + user.listRepos(assertFailure(done, function(error) { |
| 38 | + expect(error).to.be.an.error(); |
| 39 | + expect(error).to.have.own('response'); |
| 40 | + expect(error.response).to.have.own('status'); |
| 41 | + expect(error.response.status).to.be(403); |
| 42 | + done(); |
| 43 | + })); |
| 44 | + }); |
| 45 | + |
| 46 | + afterEach(function() { |
| 47 | + scope.done(); |
| 48 | + nock.cleanAll(); |
| 49 | + }); |
| 50 | +}); |
| 51 | + |
| 52 | +describe('Rate limit OK', function() { |
| 53 | + let github; |
| 54 | + let user; |
| 55 | + let scope; |
| 56 | + |
| 57 | + before(function() { |
| 58 | + github = new Github(); |
| 59 | + user = github.getUser(testUser.USERNAME); |
| 60 | + }); |
| 61 | + |
| 62 | + beforeEach(function() { |
| 63 | + scope = fixtureOk(); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should resolve promise', function() { |
| 67 | + return expect(user.listRepos()).to.resolve.to.object(); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should call callback with array of results', function(done) { |
| 71 | + user.listRepos(assertSuccessful(done, function(error, result) { |
| 72 | + expect(error).is.not.an.error(); |
| 73 | + expect(error).is.not.truthy(); |
| 74 | + expect(result).is.array(); |
| 75 | + done(); |
| 76 | + })); |
| 77 | + }); |
| 78 | + |
| 79 | + afterEach(function() { |
| 80 | + scope.done(); |
| 81 | + nock.cleanAll(); |
| 82 | + }); |
| 83 | +}); |
0 commit comments