Skip to content

Commit

Permalink
fix: adding method for metadata creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Farenheith committed Jan 8, 2023
1 parent 75ea9a0 commit ca80841
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export class Client<T extends GrpcServiceDefinition<keyof T>> {
return this.grpcInstance;
}

public createMetadata() {
const grpc = getGrpc(this.config.legacy);
return new grpc.Metadata();
}

private createClient(config: ClientConfig): T {
const grpc = getGrpc(config.legacy);
const credentials =
Expand Down
4 changes: 1 addition & 3 deletions test/unit/client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Server } from '@grpc/grpc-js';
import { Client, ClientPool, StreamCall, UnaryCall } from '../../src';
import { getGrpc } from '../../src/utils/grpc-lib';
import { createServer } from '../server';

describe('client.ts', () => {
Expand Down Expand Up @@ -194,8 +193,7 @@ describe('client.ts', () => {

const result = await chosenInstance.Unary({ foo: '1' });

const MetadataClass = getGrpc(legacy).Metadata;
const metadata = new MetadataClass();
const metadata = client.createMetadata();
metadata.set('myMeta', 'myValue');
expect(defaultMiddleware).toHaveCallsLike([[metadata, {}], 'Unary']);
expect(endingDefaultMiddleware).toHaveCallsLike([undefined]);
Expand Down

0 comments on commit ca80841

Please sign in to comment.