11import { GRPCHealthIndicator } from './grpc.health' ;
22import { checkPackages } from '../../utils/checkPackage.util' ;
3- import { Transport } from '@nestjs/microservices' ;
3+ import { GrpcOptions , Transport } from '@nestjs/microservices' ;
44import { UnhealthyResponseCodeError , TimeoutError } from '../../errors' ;
55import { HealthCheckError } from '../../health-check/health-check.error' ;
66jest . mock ( '../../utils/checkPackage.util' ) ;
@@ -41,21 +41,21 @@ describe('GRPCHealthIndicator', () => {
4141 } ) ;
4242 describe ( 'checkService' , ( ) => {
4343 it ( 'should return a healthy result' , async ( ) => {
44- const result = await grpc . checkService ( 'grpc' , 'test' ) ;
44+ const result = await grpc . checkService < GrpcOptions > ( 'grpc' , 'test' ) ;
4545 expect ( result ) . toEqual ( {
4646 grpc : { servingStatus : 'SERVING' , status : 'up' , statusCode : 1 } ,
4747 } ) ;
4848 } ) ;
4949
5050 it ( 'should correctly call the ClientProxyFactory with default' , async ( ) => {
51- await grpc . checkService ( 'grpc' , 'test' ) ;
51+ await grpc . checkService < GrpcOptions > ( 'grpc' , 'test' ) ;
5252 expect ( clientProxyFactoryMock . create . mock . calls [ 0 ] [ 0 ] ) . toEqual ( {
5353 options : { package : 'grpc.health.v1' , protoPath : expect . anything ( ) } ,
5454 transport : Transport . GRPC ,
5555 } ) ;
5656 } ) ;
5757 it ( 'should correctly all the ClientProxyFactory with custom options' , async ( ) => {
58- await grpc . checkService ( 'grpc' , 'test' , {
58+ await grpc . checkService < GrpcOptions > ( 'grpc' , 'test' , {
5959 protoPath : 'test.proto' ,
6060 timeout : 100 ,
6161 package : 'grpc.health.v2' ,
@@ -70,14 +70,14 @@ describe('GRPCHealthIndicator', () => {
7070 toPromise : ( ) : any => Promise . resolve ( { status : 0 } ) ,
7171 } ) ) ;
7272 try {
73- await grpc . checkService ( 'grpc' , 'test' ) ;
73+ await grpc . checkService < GrpcOptions > ( 'grpc' , 'test' ) ;
7474 } catch ( err ) {
7575 expect ( err instanceof UnhealthyResponseCodeError ) . toBeTruthy ( ) ;
7676 }
7777 } ) ;
7878 it ( 'should throw an error when the timeout runs out' , async ( ) => {
7979 try {
80- await grpc . checkService ( 'grpc' , 'test' , { timeout : 0 } ) ;
80+ await grpc . checkService < GrpcOptions > ( 'grpc' , 'test' , { timeout : 0 } ) ;
8181 } catch ( err ) {
8282 expect ( err instanceof TimeoutError ) . toBeTruthy ( ) ;
8383 }
@@ -87,12 +87,16 @@ describe('GRPCHealthIndicator', () => {
8787 . fn ( )
8888 . mockImplementation ( ( ) : any => ( { status : 1 } ) ) ;
8989
90- await grpc . checkService ( 'grpc' , 'test' , { healthServiceCheck } ) ;
90+ await grpc . checkService < GrpcOptions > ( 'grpc' , 'test' , {
91+ healthServiceCheck,
92+ } ) ;
9193
9294 expect ( healthServiceCheck . mock . calls . length ) . toBe ( 1 ) ;
9395 } ) ;
9496 it ( 'should use the custom healthServiceName' , async ( ) => {
95- await grpc . checkService ( 'grpc' , 'test' , { healthServiceName : 'health2' } ) ;
97+ await grpc . checkService < GrpcOptions > ( 'grpc' , 'test' , {
98+ healthServiceName : 'health2' ,
99+ } ) ;
96100 expect ( grpcClientMock . getService . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'health2' ) ;
97101 } ) ;
98102 it ( 'should throw TypeError further in client.getService' , async ( ) => {
@@ -101,7 +105,7 @@ describe('GRPCHealthIndicator', () => {
101105 throw error ;
102106 } ) ;
103107 try {
104- await grpc . checkService ( 'grpc' , 'test' ) ;
108+ await grpc . checkService < GrpcOptions > ( 'grpc' , 'test' ) ;
105109 } catch ( err ) {
106110 expect ( err ) . toEqual ( error ) ;
107111 }
@@ -112,14 +116,14 @@ describe('GRPCHealthIndicator', () => {
112116 throw error ;
113117 } ) ;
114118 try {
115- await grpc . checkService ( 'grpc' , 'test' ) ;
119+ await grpc . checkService < GrpcOptions > ( 'grpc' , 'test' ) ;
116120 } catch ( err ) {
117121 expect ( err instanceof HealthCheckError ) . toBeTruthy ( ) ;
118122 }
119123 } ) ;
120124 it ( 'should throw HealthCheckError if the grpc check function fails' , async ( ) => {
121125 try {
122- await grpc . checkService ( 'grpc' , 'test' , {
126+ await grpc . checkService < GrpcOptions > ( 'grpc' , 'test' , {
123127 healthServiceCheck : ( ) => {
124128 throw new Error ( 'test' ) ;
125129 } ,
0 commit comments