Skip to content

Commit

Permalink
test(cli): checking request ID is included in outgoing calls
Browse files Browse the repository at this point in the history
  • Loading branch information
turnabout committed Jan 10, 2025
1 parent c1aa482 commit 88e5e4c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cli/src/core/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface ClientOptions {
baseUrl: string;
apiKey?: string;
proxyUrl?: string;
interceptors?: Interceptor[];
}

export interface Client {
Expand Down Expand Up @@ -66,7 +67,7 @@ export const CreateClient = (opts: ClientOptions): Client => {
sendCompression: compressionBrotli,

// Interceptors apply to all calls running through this transport.
interceptors: [requestIdInterceptor],
interceptors: [requestIdInterceptor, ...(opts.interceptors || [])],
defaultTimeoutMs: 75_000,
});

Expand Down
39 changes: 39 additions & 0 deletions cli/test/request-header.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { describe, test, expect } from 'vitest';
import { Command } from 'commander';
import { Response, WhoAmIResponse } from '@wundergraph/cosmo-connect/dist/platform/v1/platform_pb';
import type { Interceptor } from '@connectrpc/connect';
import { CreateClient } from '../src/core/client/client.js';
import WhoAmI from '../src/commands/auth/commands/whoami.js';
import { config } from '../src/core/config.js';


const interceptor = (req) => {
expect(req.header.get('x-request-id'), "must be a valid UUID").toMatch(/^[\da-f]{8}-[\da-f]{4}-[0-5][\da-f]{3}-[089ab][\da-f]{3}-[\da-f]{12}$/i);

return {
message: new WhoAmIResponse({
response: new Response( { code: 0, details: 'OK' } )
})
};
};

describe('Schema Command', () => {
test('Check subgraph schema', async () => {
const client = CreateClient({
baseUrl: config.baseURL,
apiKey: config.apiKey,
interceptors: [(next) => interceptor]
});

const program = new Command();

await program.addCommand(
WhoAmI({
client,
}),
).parseAsync(['whoami'], {
from: 'user',
});
});
});

0 comments on commit 88e5e4c

Please sign in to comment.