Files
shields/services/github/github-auth-service.spec.js
chris48s 99bffd3a86 Send better user-agent values (and got config changes) (#7309)
* expose fetchLimitBytes/userAgent in got-config module

* export a function not a factory

* send better user-agent values

- add userAgentBase setting
- send short SHA in user agent on heroku
- set a version (tag or short SHA) in Dockefile and use
  it to report server version in UA for docker users

* add a comment explaining fileSize

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2021-11-25 17:11:49 +00:00

65 lines
1.9 KiB
JavaScript

import Joi from 'joi'
import { expect } from 'chai'
import sinon from 'sinon'
import { GithubAuthV3Service } from './github-auth-service.js'
import GithubApiProvider from './github-api-provider.js'
describe('GithubAuthV3Service', function () {
class DummyGithubAuthV3Service extends GithubAuthV3Service {
static category = 'build'
static route = { base: 'runs' }
async handle() {
const { requiredString } = await this._requestJson({
schema: Joi.object({
requiredString: Joi.string().required(),
}).required(),
url: '/repos/badges/shields/check-runs',
options: {
headers: {
Accept: 'application/vnd.github.antiope-preview+json',
},
},
})
return { message: requiredString }
}
}
it('forwards custom Accept header', async function () {
const requestFetcher = sinon.stub().returns(
Promise.resolve({
buffer: '{"requiredString": "some-string"}',
res: {
statusCode: 200,
headers: {
'x-ratelimit-limit': 12500,
'x-ratelimit-remaining': 7955,
'x-ratelimit-reset': 123456789,
},
},
})
)
const githubApiProvider = new GithubApiProvider({
baseUrl: 'https://github-api.example.com',
})
const mockToken = { update: sinon.mock(), invalidate: sinon.mock() }
sinon.stub(githubApiProvider.standardTokens, 'next').returns(mockToken)
DummyGithubAuthV3Service.invoke({
requestFetcher,
githubApiProvider,
})
expect(requestFetcher).to.have.been.calledOnceWith(
'https://github-api.example.com/repos/badges/shields/check-runs',
{
headers: {
'User-Agent': 'shields (self-hosted)/dev',
Accept: 'application/vnd.github.antiope-preview+json',
Authorization: 'token undefined',
},
}
)
})
})