rename sendAndCacheRequest (#7277)
This commit is contained in:
@@ -29,9 +29,9 @@ class DummyGraphqlService extends BaseGraphqlService {
|
||||
|
||||
describe('BaseGraphqlService', function () {
|
||||
describe('Making requests', function () {
|
||||
let sendAndCacheRequest
|
||||
let requestFetcher
|
||||
beforeEach(function () {
|
||||
sendAndCacheRequest = sinon.stub().returns(
|
||||
requestFetcher = sinon.stub().returns(
|
||||
Promise.resolve({
|
||||
buffer: '{"some": "json"}',
|
||||
res: { statusCode: 200 },
|
||||
@@ -39,13 +39,13 @@ describe('BaseGraphqlService', function () {
|
||||
)
|
||||
})
|
||||
|
||||
it('invokes _sendAndCacheRequest', async function () {
|
||||
it('invokes _requestFetcher', async function () {
|
||||
await DummyGraphqlService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
|
||||
expect(sendAndCacheRequest).to.have.been.calledOnceWith(
|
||||
expect(requestFetcher).to.have.been.calledOnceWith(
|
||||
'http://example.com/graphql',
|
||||
{
|
||||
body: '{"query":"{\\n requiredString\\n}\\n","variables":{}}',
|
||||
@@ -55,7 +55,7 @@ describe('BaseGraphqlService', function () {
|
||||
)
|
||||
})
|
||||
|
||||
it('forwards options to _sendAndCacheRequest', async function () {
|
||||
it('forwards options to _requestFetcher', async function () {
|
||||
class WithOptions extends DummyGraphqlService {
|
||||
async handle() {
|
||||
const { value } = await this._requestGraphql({
|
||||
@@ -73,11 +73,11 @@ describe('BaseGraphqlService', function () {
|
||||
}
|
||||
|
||||
await WithOptions.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
|
||||
expect(sendAndCacheRequest).to.have.been.calledOnceWith(
|
||||
expect(requestFetcher).to.have.been.calledOnceWith(
|
||||
'http://example.com/graphql',
|
||||
{
|
||||
body: '{"query":"{\\n requiredString\\n}\\n","variables":{}}',
|
||||
@@ -91,13 +91,13 @@ describe('BaseGraphqlService', function () {
|
||||
|
||||
describe('Making badges', function () {
|
||||
it('handles valid json responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: '{"requiredString": "some-string"}',
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await DummyGraphqlService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
@@ -106,13 +106,13 @@ describe('BaseGraphqlService', function () {
|
||||
})
|
||||
|
||||
it('handles json responses which do not match the schema', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: '{"unexpectedKey": "some-string"}',
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await DummyGraphqlService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
@@ -123,13 +123,13 @@ describe('BaseGraphqlService', function () {
|
||||
})
|
||||
|
||||
it('handles unparseable json responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: 'not json',
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await DummyGraphqlService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
@@ -142,13 +142,13 @@ describe('BaseGraphqlService', function () {
|
||||
|
||||
describe('Error handling', function () {
|
||||
it('handles generic error', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: '{ "errors": [ { "message": "oh noes!!" } ] }',
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await DummyGraphqlService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
@@ -181,13 +181,13 @@ describe('BaseGraphqlService', function () {
|
||||
}
|
||||
}
|
||||
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: '{ "errors": [ { "message": "oh noes!!" } ] }',
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await WithErrorHandler.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
|
||||
@@ -22,9 +22,9 @@ class DummyJsonService extends BaseJsonService {
|
||||
|
||||
describe('BaseJsonService', function () {
|
||||
describe('Making requests', function () {
|
||||
let sendAndCacheRequest
|
||||
let requestFetcher
|
||||
beforeEach(function () {
|
||||
sendAndCacheRequest = sinon.stub().returns(
|
||||
requestFetcher = sinon.stub().returns(
|
||||
Promise.resolve({
|
||||
buffer: '{"some": "json"}',
|
||||
res: { statusCode: 200 },
|
||||
@@ -32,13 +32,13 @@ describe('BaseJsonService', function () {
|
||||
)
|
||||
})
|
||||
|
||||
it('invokes _sendAndCacheRequest', async function () {
|
||||
it('invokes _requestFetcher', async function () {
|
||||
await DummyJsonService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
|
||||
expect(sendAndCacheRequest).to.have.been.calledOnceWith(
|
||||
expect(requestFetcher).to.have.been.calledOnceWith(
|
||||
'http://example.com/foo.json',
|
||||
{
|
||||
headers: { Accept: 'application/json' },
|
||||
@@ -46,7 +46,7 @@ describe('BaseJsonService', function () {
|
||||
)
|
||||
})
|
||||
|
||||
it('forwards options to _sendAndCacheRequest', async function () {
|
||||
it('forwards options to _requestFetcher', async function () {
|
||||
class WithOptions extends DummyJsonService {
|
||||
async handle() {
|
||||
const { value } = await this._requestJson({
|
||||
@@ -59,11 +59,11 @@ describe('BaseJsonService', function () {
|
||||
}
|
||||
|
||||
await WithOptions.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
|
||||
expect(sendAndCacheRequest).to.have.been.calledOnceWith(
|
||||
expect(requestFetcher).to.have.been.calledOnceWith(
|
||||
'http://example.com/foo.json',
|
||||
{
|
||||
headers: { Accept: 'application/json' },
|
||||
@@ -76,13 +76,13 @@ describe('BaseJsonService', function () {
|
||||
|
||||
describe('Making badges', function () {
|
||||
it('handles valid json responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: '{"requiredString": "some-string"}',
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await DummyJsonService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
@@ -91,13 +91,13 @@ describe('BaseJsonService', function () {
|
||||
})
|
||||
|
||||
it('handles json responses which do not match the schema', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: '{"unexpectedKey": "some-string"}',
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await DummyJsonService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
@@ -108,13 +108,13 @@ describe('BaseJsonService', function () {
|
||||
})
|
||||
|
||||
it('handles unparseable json responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: 'not json',
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await DummyJsonService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
|
||||
@@ -34,9 +34,9 @@ describe('BaseSvgScrapingService', function () {
|
||||
})
|
||||
|
||||
describe('Making requests', function () {
|
||||
let sendAndCacheRequest
|
||||
let requestFetcher
|
||||
beforeEach(function () {
|
||||
sendAndCacheRequest = sinon.stub().returns(
|
||||
requestFetcher = sinon.stub().returns(
|
||||
Promise.resolve({
|
||||
buffer: exampleSvg,
|
||||
res: { statusCode: 200 },
|
||||
@@ -44,13 +44,13 @@ describe('BaseSvgScrapingService', function () {
|
||||
)
|
||||
})
|
||||
|
||||
it('invokes _sendAndCacheRequest with the expected header', async function () {
|
||||
it('invokes _requestFetcher with the expected header', async function () {
|
||||
await DummySvgScrapingService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
|
||||
expect(sendAndCacheRequest).to.have.been.calledOnceWith(
|
||||
expect(requestFetcher).to.have.been.calledOnceWith(
|
||||
'http://example.com/foo.svg',
|
||||
{
|
||||
headers: { Accept: 'image/svg+xml' },
|
||||
@@ -58,7 +58,7 @@ describe('BaseSvgScrapingService', function () {
|
||||
)
|
||||
})
|
||||
|
||||
it('forwards options to _sendAndCacheRequest', async function () {
|
||||
it('forwards options to _requestFetcher', async function () {
|
||||
class WithCustomOptions extends DummySvgScrapingService {
|
||||
async handle() {
|
||||
const { message } = await this._requestSvg({
|
||||
@@ -74,11 +74,11 @@ describe('BaseSvgScrapingService', function () {
|
||||
}
|
||||
|
||||
await WithCustomOptions.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
|
||||
expect(sendAndCacheRequest).to.have.been.calledOnceWith(
|
||||
expect(requestFetcher).to.have.been.calledOnceWith(
|
||||
'http://example.com/foo.svg',
|
||||
{
|
||||
method: 'POST',
|
||||
@@ -91,13 +91,13 @@ describe('BaseSvgScrapingService', function () {
|
||||
|
||||
describe('Making badges', function () {
|
||||
it('handles valid svg responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: exampleSvg,
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await DummySvgScrapingService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
@@ -117,13 +117,13 @@ describe('BaseSvgScrapingService', function () {
|
||||
})
|
||||
}
|
||||
}
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: '<desc>a different message</desc>',
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await WithValueMatcher.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
@@ -132,13 +132,13 @@ describe('BaseSvgScrapingService', function () {
|
||||
})
|
||||
|
||||
it('handles unparseable svg responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: 'not svg yo',
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await DummySvgScrapingService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
|
||||
@@ -22,9 +22,9 @@ class DummyXmlService extends BaseXmlService {
|
||||
|
||||
describe('BaseXmlService', function () {
|
||||
describe('Making requests', function () {
|
||||
let sendAndCacheRequest
|
||||
let requestFetcher
|
||||
beforeEach(function () {
|
||||
sendAndCacheRequest = sinon.stub().returns(
|
||||
requestFetcher = sinon.stub().returns(
|
||||
Promise.resolve({
|
||||
buffer: '<requiredString>some-string</requiredString>',
|
||||
res: { statusCode: 200 },
|
||||
@@ -32,13 +32,13 @@ describe('BaseXmlService', function () {
|
||||
)
|
||||
})
|
||||
|
||||
it('invokes _sendAndCacheRequest', async function () {
|
||||
it('invokes _requestFetcher', async function () {
|
||||
await DummyXmlService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
|
||||
expect(sendAndCacheRequest).to.have.been.calledOnceWith(
|
||||
expect(requestFetcher).to.have.been.calledOnceWith(
|
||||
'http://example.com/foo.xml',
|
||||
{
|
||||
headers: { Accept: 'application/xml, text/xml' },
|
||||
@@ -46,7 +46,7 @@ describe('BaseXmlService', function () {
|
||||
)
|
||||
})
|
||||
|
||||
it('forwards options to _sendAndCacheRequest', async function () {
|
||||
it('forwards options to _requestFetcher', async function () {
|
||||
class WithCustomOptions extends BaseXmlService {
|
||||
static route = {}
|
||||
|
||||
@@ -61,11 +61,11 @@ describe('BaseXmlService', function () {
|
||||
}
|
||||
|
||||
await WithCustomOptions.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
|
||||
expect(sendAndCacheRequest).to.have.been.calledOnceWith(
|
||||
expect(requestFetcher).to.have.been.calledOnceWith(
|
||||
'http://example.com/foo.xml',
|
||||
{
|
||||
headers: { Accept: 'application/xml, text/xml' },
|
||||
@@ -78,13 +78,13 @@ describe('BaseXmlService', function () {
|
||||
|
||||
describe('Making badges', function () {
|
||||
it('handles valid xml responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: '<requiredString>some-string</requiredString>',
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await DummyXmlService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
@@ -104,14 +104,14 @@ describe('BaseXmlService', function () {
|
||||
return { message: requiredString }
|
||||
}
|
||||
}
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer:
|
||||
'<requiredString>some-string with trailing whitespace </requiredString>',
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await DummyXmlServiceWithParserOption.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
@@ -120,13 +120,13 @@ describe('BaseXmlService', function () {
|
||||
})
|
||||
|
||||
it('handles xml responses which do not match the schema', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: '<unexpectedAttribute>some-string</unexpectedAttribute>',
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await DummyXmlService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
@@ -137,13 +137,13 @@ describe('BaseXmlService', function () {
|
||||
})
|
||||
|
||||
it('handles unparseable xml responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: 'not xml',
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await DummyXmlService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
|
||||
@@ -38,9 +38,9 @@ foo: baz
|
||||
|
||||
describe('BaseYamlService', function () {
|
||||
describe('Making requests', function () {
|
||||
let sendAndCacheRequest
|
||||
let requestFetcher
|
||||
beforeEach(function () {
|
||||
sendAndCacheRequest = sinon.stub().returns(
|
||||
requestFetcher = sinon.stub().returns(
|
||||
Promise.resolve({
|
||||
buffer: expectedYaml,
|
||||
res: { statusCode: 200 },
|
||||
@@ -48,13 +48,13 @@ describe('BaseYamlService', function () {
|
||||
)
|
||||
})
|
||||
|
||||
it('invokes _sendAndCacheRequest', async function () {
|
||||
it('invokes _requestFetcher', async function () {
|
||||
await DummyYamlService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
|
||||
expect(sendAndCacheRequest).to.have.been.calledOnceWith(
|
||||
expect(requestFetcher).to.have.been.calledOnceWith(
|
||||
'http://example.com/foo.yaml',
|
||||
{
|
||||
headers: {
|
||||
@@ -65,7 +65,7 @@ describe('BaseYamlService', function () {
|
||||
)
|
||||
})
|
||||
|
||||
it('forwards options to _sendAndCacheRequest', async function () {
|
||||
it('forwards options to _requestFetcher', async function () {
|
||||
class WithOptions extends DummyYamlService {
|
||||
async handle() {
|
||||
const { requiredString } = await this._requestYaml({
|
||||
@@ -78,11 +78,11 @@ describe('BaseYamlService', function () {
|
||||
}
|
||||
|
||||
await WithOptions.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
|
||||
expect(sendAndCacheRequest).to.have.been.calledOnceWith(
|
||||
expect(requestFetcher).to.have.been.calledOnceWith(
|
||||
'http://example.com/foo.yaml',
|
||||
{
|
||||
headers: {
|
||||
@@ -98,13 +98,13 @@ describe('BaseYamlService', function () {
|
||||
|
||||
describe('Making badges', function () {
|
||||
it('handles valid yaml responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: expectedYaml,
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await DummyYamlService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
@@ -113,13 +113,13 @@ describe('BaseYamlService', function () {
|
||||
})
|
||||
|
||||
it('handles yaml responses which do not match the schema', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: unexpectedYaml,
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await DummyYamlService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
@@ -130,13 +130,13 @@ describe('BaseYamlService', function () {
|
||||
})
|
||||
|
||||
it('handles unparseable yaml responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: invalidYaml,
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
expect(
|
||||
await DummyYamlService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
{ handleInternalErrors: false }
|
||||
)
|
||||
).to.deep.equal({
|
||||
|
||||
@@ -207,10 +207,10 @@ class BaseService {
|
||||
}
|
||||
|
||||
constructor(
|
||||
{ sendAndCacheRequest, authHelper, metricHelper },
|
||||
{ requestFetcher, authHelper, metricHelper },
|
||||
{ handleInternalErrors }
|
||||
) {
|
||||
this._requestFetcher = sendAndCacheRequest
|
||||
this._requestFetcher = requestFetcher
|
||||
this.authHelper = authHelper
|
||||
this._handleInternalErrors = handleInternalErrors
|
||||
this._metricHelper = metricHelper
|
||||
@@ -278,7 +278,7 @@ class BaseService {
|
||||
/**
|
||||
* Asynchronous function to handle requests for this service. Take the route
|
||||
* parameters (as defined in the `route` property), perform a request using
|
||||
* `this._sendAndCacheRequest`, and return the badge data.
|
||||
* `this._requestFetcher`, and return the badge data.
|
||||
*
|
||||
* @abstract
|
||||
* @param {object} namedParams Params parsed from route pattern
|
||||
@@ -453,7 +453,7 @@ class BaseService {
|
||||
const namedParams = namedParamsForMatch(captureNames, match, this)
|
||||
const serviceData = await this.invoke(
|
||||
{
|
||||
sendAndCacheRequest: fetcher, // TODO: rename sendAndCacheRequest
|
||||
requestFetcher: fetcher,
|
||||
githubApiProvider,
|
||||
librariesIoApiProvider,
|
||||
metricHelper,
|
||||
|
||||
@@ -430,12 +430,12 @@ describe('BaseService', function () {
|
||||
})
|
||||
|
||||
it('logs appropriate information', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: '',
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
const serviceInstance = new DummyService(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
defaultConfig
|
||||
)
|
||||
|
||||
@@ -458,12 +458,12 @@ describe('BaseService', function () {
|
||||
})
|
||||
|
||||
it('handles errors', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: '',
|
||||
res: { statusCode: 404 },
|
||||
})
|
||||
const serviceInstance = new DummyService(
|
||||
{ sendAndCacheRequest },
|
||||
{ requestFetcher },
|
||||
defaultConfig
|
||||
)
|
||||
|
||||
@@ -490,13 +490,13 @@ describe('BaseService', function () {
|
||||
metricInstance: new PrometheusMetrics({ register }),
|
||||
ServiceClass: DummyServiceWithServiceResponseSizeMetricEnabled,
|
||||
})
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: 'x'.repeat(65536 + 1),
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
const serviceInstance =
|
||||
new DummyServiceWithServiceResponseSizeMetricEnabled(
|
||||
{ sendAndCacheRequest, metricHelper },
|
||||
{ requestFetcher, metricHelper },
|
||||
defaultConfig
|
||||
)
|
||||
|
||||
@@ -516,12 +516,12 @@ describe('BaseService', function () {
|
||||
metricInstance: new PrometheusMetrics({ register }),
|
||||
ServiceClass: DummyService,
|
||||
})
|
||||
const sendAndCacheRequest = async () => ({
|
||||
const requestFetcher = async () => ({
|
||||
buffer: 'x',
|
||||
res: { statusCode: 200 },
|
||||
})
|
||||
const serviceInstance = new DummyService(
|
||||
{ sendAndCacheRequest, metricHelper },
|
||||
{ requestFetcher, metricHelper },
|
||||
defaultConfig
|
||||
)
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ import { mergeQueries } from '../../core/base-service/graphql.js'
|
||||
import { BaseGraphqlService, BaseJsonService } from '../index.js'
|
||||
|
||||
function createRequestFetcher(context) {
|
||||
const { sendAndCacheRequest, githubApiProvider } = context
|
||||
return githubApiProvider.fetch.bind(githubApiProvider, sendAndCacheRequest)
|
||||
const { requestFetcher, githubApiProvider } = context
|
||||
return githubApiProvider.fetch.bind(githubApiProvider, requestFetcher)
|
||||
}
|
||||
|
||||
class GithubAuthV3Service extends BaseJsonService {
|
||||
|
||||
@@ -26,7 +26,7 @@ describe('GithubAuthV3Service', function () {
|
||||
}
|
||||
|
||||
it('forwards custom Accept header', async function () {
|
||||
const sendAndCacheRequest = sinon.stub().returns(
|
||||
const requestFetcher = sinon.stub().returns(
|
||||
Promise.resolve({
|
||||
buffer: '{"requiredString": "some-string"}',
|
||||
res: {
|
||||
@@ -46,11 +46,11 @@ describe('GithubAuthV3Service', function () {
|
||||
sinon.stub(githubApiProvider.standardTokens, 'next').returns(mockToken)
|
||||
|
||||
DummyGithubAuthV3Service.invoke({
|
||||
sendAndCacheRequest,
|
||||
requestFetcher,
|
||||
githubApiProvider,
|
||||
})
|
||||
|
||||
expect(sendAndCacheRequest).to.have.been.calledOnceWith(
|
||||
expect(requestFetcher).to.have.been.calledOnceWith(
|
||||
'https://github-api.example.com/repos/badges/shields/check-runs',
|
||||
{
|
||||
headers: {
|
||||
|
||||
@@ -13,10 +13,10 @@ const projectSchema = Joi.object({
|
||||
export default class LibrariesIoBase extends BaseJsonService {
|
||||
constructor(context, config) {
|
||||
super(context, config)
|
||||
const { sendAndCacheRequest, librariesIoApiProvider } = context
|
||||
const { requestFetcher, librariesIoApiProvider } = context
|
||||
this._requestFetcher = librariesIoApiProvider.fetch.bind(
|
||||
librariesIoApiProvider,
|
||||
sendAndCacheRequest
|
||||
requestFetcher
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ function noToken(serviceClass) {
|
||||
}
|
||||
}
|
||||
|
||||
const sendAndCacheRequest = fetchFactory(bytes(runnerConfig.public.fetchLimit))
|
||||
const requestFetcher = fetchFactory(bytes(runnerConfig.public.fetchLimit))
|
||||
|
||||
const defaultContext = { sendAndCacheRequest }
|
||||
const defaultContext = { requestFetcher }
|
||||
|
||||
export { cleanUpNockAfterEach, noToken, sendAndCacheRequest, defaultContext }
|
||||
export { cleanUpNockAfterEach, noToken, defaultContext }
|
||||
|
||||
Reference in New Issue
Block a user