Skip to content

Commit 7b5b054

Browse files
integration(@nestjs) add typeorm integration test
1 parent 17a609c commit 7b5b054

File tree

20 files changed

+2263
-13
lines changed

20 files changed

+2263
-13
lines changed

integration/docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,13 @@ services:
2121
ports:
2222
- "1883:1883"
2323
- "9001:9001"
24+
restart: always
25+
mysql:
26+
image: mysql:5.7.22
27+
restart: always
28+
environment:
29+
MYSQL_ROOT_PASSWORD: root
30+
MYSQL_DATABASE: test
31+
ports:
32+
- "3306:3306"
2433
restart: always

integration/microservices/e2e/sum-grpc.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import * as express from 'express';
2-
import * as request from 'supertest';
3-
import { Test } from '@nestjs/testing';
41
import { INestApplication } from '@nestjs/common';
52
import { Transport } from '@nestjs/microservices';
3+
import { Test } from '@nestjs/testing';
4+
import * as express from 'express';
65
import { join } from 'path';
6+
import * as request from 'supertest';
77
import { GrpcController } from '../src/grpc/grpc.controller';
88

99
describe('GRPC transport', () => {
@@ -21,7 +21,7 @@ describe('GRPC transport', () => {
2121
transport: Transport.GRPC,
2222
options: {
2323
package: 'math',
24-
protoPath: join(__dirname, './../src/grpc/math.proto')
24+
protoPath: join(__dirname, './../src/grpc/math.proto'),
2525
},
2626
});
2727
await app.startAllMicroservicesAsync();

integration/typeorm/.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# dependencies
2+
/node_modules
3+
4+
# IDE
5+
/.idea
6+
/.awcache
7+
/.vscode
8+
9+
# misc
10+
npm-debug.log
11+
12+
# example
13+
/quick-start
14+
15+
# tests
16+
/test
17+
/coverage
18+
/.nyc_output
19+
20+
# dist
21+
/dist
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { INestApplication } from '@nestjs/common';
2+
import { Test } from '@nestjs/testing';
3+
import * as request from 'supertest';
4+
import { ApplicationModule } from './../src/app.module';
5+
6+
describe('TypeOrm', () => {
7+
let server;
8+
let app: INestApplication;
9+
10+
beforeEach(async () => {
11+
const module = await Test.createTestingModule({
12+
imports: [ApplicationModule],
13+
}).compile();
14+
15+
app = module.createNestApplication();
16+
server = app.getHttpServer();
17+
await app.init();
18+
});
19+
20+
it(`should return created entity`, () => {
21+
return request(server)
22+
.post('/photo')
23+
.expect(201, { name: 'Nest', description: 'Is great!', views: 6000 });
24+
});
25+
26+
afterEach(async () => {
27+
await app.close();
28+
});
29+
});

integration/typeorm/ormconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"type": "mysql",
3+
"host": "localhost",
4+
"port": 3306,
5+
"username": "root",
6+
"password": "root",
7+
"database": "test",
8+
"entities": ["src/**/**.entity{.ts,.js}"],
9+
"synchronize": true
10+
}

0 commit comments

Comments
 (0)