Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Segaran committed May 13, 2020
1 parent ac74c76 commit b3ca921
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 25 deletions.
58 changes: 39 additions & 19 deletions packages/apollo-engine-reporting/src/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,18 @@ it('trace construction', async () => {
async function addTrace(args: AddTraceArgs) {
traces.push(args);
}
const startSchemaReporting = jest.fn();
const executableSchemaIdGenerator = jest.fn();

const pluginInstance = plugin({ /* no options!*/ }, addTrace);
const pluginInstance = plugin(
{
/* no options!*/
},
addTrace,
startSchemaReporting,
null,
executableSchemaIdGenerator,
);

pluginTestHarness({
pluginInstance,
Expand All @@ -64,7 +74,7 @@ it('trace construction', async () => {
},
http: new Request('http://localhost:123/foo'),
},
executor: async ({ request: { query: source }}) => {
executor: async ({ request: { query: source } }) => {
return await graphql({
schema,
source,
Expand Down Expand Up @@ -129,17 +139,21 @@ describe('check variableJson output for sendVariableValues all/none type', () =>
});

it('Case 4: Check behavior for invalid inputs', () => {
expect(makeTraceDetails(variables,
// @ts-ignore Testing untyped usage; only `{ none: true }` is legal.
{ none: false }
)).toEqual(
nonFilteredOutput,
);
expect(
makeTraceDetails(
variables,
// @ts-ignore Testing untyped usage; only `{ none: true }` is legal.
{ none: false },
),
).toEqual(nonFilteredOutput);

expect(makeTraceDetails(variables,
// @ts-ignore Testing untyped usage; only `{ all: true }` is legal.
{ all: false }
)).toEqual(filteredOutput);
expect(
makeTraceDetails(
variables,
// @ts-ignore Testing untyped usage; only `{ all: true }` is legal.
{ all: false },
),
).toEqual(filteredOutput);
});
});

Expand Down Expand Up @@ -260,7 +274,7 @@ describe('variableJson output for sendVariableValues transform: custom function
).toEqual(JSON.stringify(null));
});

const errorThrowingModifier = (input: {
const errorThrowingModifier = (_input: {
variables: Record<string, any>;
}): Record<string, any> => {
throw new GraphQLError('testing error handling');
Expand Down Expand Up @@ -318,9 +332,11 @@ const headersOutput = { name: new Trace.HTTP.Values({ value: ['value'] }) };
describe('tests for the sendHeaders reporting option', () => {
it('sendHeaders defaults to hiding all', () => {
const http = makeTestHTTP();
makeHTTPRequestHeaders(http, headers,
makeHTTPRequestHeaders(
http,
headers,
// @ts-ignore: `null` is not a valid type; check output on invalid input.
null
null,
);
expect(http.requestHeaders).toEqual({});
makeHTTPRequestHeaders(http, headers, undefined);
Expand All @@ -341,16 +357,20 @@ describe('tests for the sendHeaders reporting option', () => {

it('invalid inputs for sendHeaders.all and sendHeaders.none', () => {
const httpSafelist = makeTestHTTP();
makeHTTPRequestHeaders(httpSafelist, headers,
makeHTTPRequestHeaders(
httpSafelist,
headers,
// @ts-ignore Testing untyped usage; only `{ none: true }` is legal.
{ none: false }
{ none: false },
);
expect(httpSafelist.requestHeaders).toEqual(headersOutput);

const httpBlocklist = makeTestHTTP();
makeHTTPRequestHeaders(httpBlocklist, headers,
makeHTTPRequestHeaders(
httpBlocklist,
headers,
// @ts-ignore Testing untyped usage; only `{ all: true }` is legal.
{ all: false }
{ all: false },
);
expect(httpBlocklist.requestHeaders).toEqual({});
});
Expand Down
12 changes: 8 additions & 4 deletions packages/apollo-engine-reporting/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,12 @@ export class EngineReportingAgent<TContext = any> {
private readonly logger: Logger = console;
private readonly graphVariant: string;

private reports: { [executableSchemaId: string]: Report } = Object.create(null);
private reportSizes: { [executableSchemaId: string]: number } = Object.create(null);
private reports: { [executableSchemaId: string]: Report } = Object.create(
null,
);
private reportSizes: { [executableSchemaId: string]: number } = Object.create(
null,
);

private reportTimer: any; // timer typing is weird and node-specific
private readonly sendReportsImmediately?: boolean;
Expand Down Expand Up @@ -560,7 +564,7 @@ export class EngineReportingAgent<TContext = any> {
});
});

const endpointUrl =
const metricsEndpointUrl =
(this.options.metricsEndpointUrl ||
'https://engine-report.apollodata.com') + '/api/ingress/traces';

Expand All @@ -569,7 +573,7 @@ export class EngineReportingAgent<TContext = any> {
// Retry on network errors and 5xx HTTP
// responses.
async () => {
const curResponse = await fetch(endpointUrl, {
const curResponse = await fetch(metricsEndpointUrl, {
method: 'POST',
headers: {
'user-agent': 'apollo-engine-reporting',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ export function testApolloServer<AS extends ApolloServerBase>(

public engineOptions(): Partial<EngineReportingOptions<any>> {
return {
endpointUrl: this.getUrl(),
metricsEndpointUrl: this.getUrl(),
};
}

Expand Down Expand Up @@ -2170,7 +2170,7 @@ export function testApolloServer<AS extends ApolloServerBase>(
resolvers: { Query: { something: () => 'hello' } },
engine: {
apiKey: 'service:my-app:secret',
endpointUrl: fakeEngineUrl,
metricsEndpointUrl: fakeEngineUrl,
reportIntervalMs: 1,
maxAttempts: 3,
requestAgent,
Expand Down

0 comments on commit b3ca921

Please sign in to comment.