-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from HyoJongPark/be/test/e2e-init
[BE] e2e 테스트 초기 세팅
- Loading branch information
Showing
9 changed files
with
122 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,42 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { INestApplication } from '@nestjs/common'; | ||
import * as request from 'supertest'; | ||
import { AppModule } from './../src/app.module'; | ||
import { AppModule } from 'src/app.module'; | ||
import { DataSource, QueryRunner } from 'typeorm'; | ||
|
||
describe('AppController (e2e)', () => { | ||
let app: INestApplication; | ||
let queryRunner: QueryRunner; | ||
|
||
beforeEach(async () => { | ||
const moduleFixture: TestingModule = await Test.createTestingModule({ | ||
beforeAll(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
imports: [AppModule], | ||
}).compile(); | ||
const dataSource = module.get<DataSource>(DataSource); | ||
|
||
app = moduleFixture.createNestApplication(); | ||
app = module.createNestApplication(); | ||
queryRunner = dataSource.createQueryRunner(); | ||
await app.init(); | ||
}); | ||
|
||
it('/ (GET)', () => { | ||
return request(app.getHttpServer()) | ||
.get('/') | ||
.expect(200) | ||
.expect('Hello World!'); | ||
afterAll(async () => { | ||
await app.close(); | ||
}); | ||
|
||
beforeEach(async () => await queryRunner.startTransaction()); | ||
afterEach(async () => await queryRunner.rollbackTransaction()); | ||
|
||
it('/ (GET)', async () => { | ||
const response = await request(app.getHttpServer()).get('/'); | ||
|
||
expect(response.status).toEqual(404); | ||
}); | ||
|
||
it('/diaries/:id (GET)', async () => { | ||
const response = await request(app.getHttpServer()).get('/diaries/1'); | ||
const body = response.body; | ||
|
||
expect(response.status).toEqual(401); | ||
expect(body.message).toEqual('Unauthorized'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { INestApplication } from '@nestjs/common'; | ||
import * as request from 'supertest'; | ||
import { AppModule } from 'src/app.module'; | ||
import { DataSource, QueryRunner } from 'typeorm'; | ||
|
||
describe('AppController (e2e)', () => { | ||
let app: INestApplication; | ||
let queryRunner: QueryRunner; | ||
|
||
beforeAll(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
imports: [AppModule], | ||
}).compile(); | ||
const dataSource = module.get<DataSource>(DataSource); | ||
|
||
app = module.createNestApplication(); | ||
queryRunner = dataSource.createQueryRunner(); | ||
await app.init(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
}); | ||
|
||
beforeEach(async () => await queryRunner.startTransaction()); | ||
afterEach(async () => await queryRunner.rollbackTransaction()); | ||
|
||
it('/ (GET)', async () => { | ||
const response = await request(app.getHttpServer()).get('/'); | ||
|
||
expect(response.status).toEqual(404); | ||
}); | ||
|
||
it('/diaries/:id (GET)', async () => { | ||
const response = await request(app.getHttpServer()).get('/diaries/1'); | ||
const body = response.body; | ||
|
||
expect(response.status).toEqual(401); | ||
expect(body.message).toEqual('Unauthorized'); | ||
}); | ||
it('/diaries/:id (GET)', async () => { | ||
const response = await request(app.getHttpServer()).get('/diaries/1'); | ||
const body = response.body; | ||
|
||
expect(response.status).toEqual(401); | ||
expect(body.message).toEqual('Unauthorized'); | ||
}); | ||
}); |