mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import { INestApplication } from '@nestjs/common';
|
|
import { Transport } from '@nestjs/microservices';
|
|
import { Test } from '@nestjs/testing';
|
|
import { join } from 'path';
|
|
import * as request from 'supertest';
|
|
import { GrpcController } from '../src/grpc/grpc.controller';
|
|
|
|
describe('GRPC transport', () => {
|
|
let server;
|
|
let app: INestApplication;
|
|
|
|
beforeEach(async () => {
|
|
const module = await Test.createTestingModule({
|
|
controllers: [GrpcController],
|
|
}).compile();
|
|
|
|
app = module.createNestApplication();
|
|
server = app.getHttpAdapter().getInstance();
|
|
|
|
app.connectMicroservice({
|
|
transport: Transport.GRPC,
|
|
options: {
|
|
package: 'math',
|
|
protoPath: join(__dirname, '../src/grpc/math.proto'),
|
|
},
|
|
});
|
|
await app.startAllMicroservicesAsync();
|
|
await app.init();
|
|
});
|
|
|
|
it(`/POST`, () => {
|
|
return request(server)
|
|
.post('/')
|
|
.send([1, 2, 3, 4, 5])
|
|
.expect(200, { result: '15' });
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await app.close();
|
|
});
|
|
});
|