I am trying to test a GRPC method but I am getting this error when running in Jest: TypeError: Cannot read property 'gprcFindAll' of undefined
This is the documentation I am referencing: https://docs.nestjs.com/microservices/grpc
Here is my controller:
@Controller('benchmarks')
export class BenchmarksController {
@GrpcMethod('HelloWorldGRPCService', 'findAll')
async gprcFindAll(metadata?: any): Promise<Benchmarks[]> {
const benchmarks = [];
return benchmarks;
}
}
Here is my Jest test:
describe('Benchmarks Controller', () => {
let controller: BenchmarksController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [BenchmarksController]
}).compile();
controller = module.get<BenchmarksController>(BenchmarksController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
it('GRPC Should Find All', async function() {
const result = await controller.gprcFindAll();
console.log(result);
});
});
Here is my Proto 3 file:
syntax = "proto3";
package helloWorldGRPC;
service HelloWorldGRPCService {
rpc findAll () returns (repeated Benchmarks);
}
message Benchmarks {
string trans_id = 1;
string protocol = 2;
string database = 3;
Timestamp updated_at = 4;
Timestamp created_at = 5;
repeated Action actions = 6;
}
message Action {
string trans_id = 1;
int32 payload_length = 2;
string payload = 3;
string status = 4;
Timestamp updated_at = 5;
Timestamp created_at = 6;
}