Files
shields/services/github/github-auth-service.spec.js
dependabot[bot] b9d96755ec chore(deps-dev): bump prettier from 2.8.8 to 3.0.0 (#9357)
* chore(deps-dev): bump prettier from 2.8.8 to 3.0.0

Bumps [prettier](https://github.com/prettier/prettier) from 2.8.8 to 3.0.0.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.8.8...3.0.0)

---
updated-dependencies:
- dependency-name: prettier
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* reformat all the things (prettier 3)

* update tests to await calls to prettier.format()

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: chris48s <git@chris-shaw.dev>
2023-07-10 09:27:51 +00:00

67 lines
2.0 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',
restApiVersion: '2022-11-28',
})
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',
'X-GitHub-Api-Version': '2022-11-28',
},
},
)
})
})