-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop attempting to override Accept header in [GitHub] API provider (#…
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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: 'https://github-api.example.com/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 sendAndCacheRequestWithCallbacks = sinon.stub().returns( | ||
Promise.resolve({ | ||
buffer: '{"requiredString": "some-string"}', | ||
res: { statusCode: 200 }, | ||
}) | ||
) | ||
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({ | ||
sendAndCacheRequestWithCallbacks, | ||
githubApiProvider, | ||
}) | ||
|
||
expect(sendAndCacheRequestWithCallbacks).to.have.been.calledOnceWith({ | ||
headers: { | ||
'User-Agent': 'Shields.io/2003a', | ||
Accept: 'application/vnd.github.antiope-preview+json', | ||
Authorization: 'token undefined', | ||
}, | ||
url: 'https://github-api.example.com/repos/badges/shields/check-runs', | ||
baseUrl: 'https://github-api.example.com', | ||
}) | ||
}) | ||
}) |