Files
shields/services/github/github-api-provider.integration.js
Paul Melnikow 7a664ca3e8 Run prettier (#1866)
Merging this separately so the commit with the tooling change is readable. This is a follow-on to #1167 which turned prettier on.
2018-08-08 17:57:14 -04:00

38 lines
1.0 KiB
JavaScript

'use strict'
const { expect } = require('chai')
const GithubApiProvider = require('./github-api-provider')
describe('Github API provider', function() {
const baseUrl = process.env.GITHUB_URL || 'https://api.github.com'
let githubApiProvider
before(function() {
githubApiProvider = new GithubApiProvider({ baseUrl })
})
const headers = []
async function performOneRequest() {
const { res } = await githubApiProvider.requestAsPromise(
require('request'),
'/repos/rust-lang/rust',
{}
)
expect(res.statusCode).to.equal(200)
headers.push(res.headers)
}
before('should be able to run 10 requests', async function() {
this.timeout(10000)
for (let i = 0; i < 10; ++i) {
await performOneRequest()
}
})
it('should decrement the limit remaining with each request', function() {
const remaining = headers.map(h => +h['x-ratelimit-remaining'])
const expected = Array.from({ length: 10 }, (e, i) => remaining[0] - i)
expect(remaining).to.deep.equal(expected)
})
})