-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(!): write a working e2e test for the project for automation!
- Loading branch information
Showing
1 changed file
with
28 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,45 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import * as request from 'supertest'; | ||
import Redis from 'ioredis'; | ||
import { | ||
makeRedisStore, | ||
makeSessionMiddleware, | ||
} from 'src/common/middleware/session'; | ||
import { CustomLogger } from 'src/logger/custom.logger'; | ||
import request from 'supertest'; | ||
import { AppModule } from './../src/app.module'; | ||
|
||
Error.stackTraceLimit = Infinity; | ||
|
||
describe('AppController (e2e)', () => { | ||
let app: INestApplication; | ||
let redisClient: Redis; | ||
const logger = new CustomLogger(); | ||
|
||
beforeEach(async () => { | ||
beforeAll(async () => { | ||
const moduleFixture: TestingModule = await Test.createTestingModule({ | ||
imports: [AppModule], | ||
}).compile(); | ||
|
||
app = moduleFixture.createNestApplication(); | ||
|
||
const { redis, redisStore } = makeRedisStore(); | ||
const sessionMiddleware = makeSessionMiddleware(redisStore); | ||
redisClient = redis; | ||
app.use(sessionMiddleware); | ||
|
||
app.useLogger(logger); | ||
|
||
await app.init(); | ||
}); | ||
|
||
it('/ (GET)', () => { | ||
return request(app.getHttpServer()) | ||
.get('/') | ||
.expect(200) | ||
.expect('Hello World!'); | ||
afterAll(async () => { | ||
await app.close(); | ||
await redisClient.quit(); | ||
}); | ||
|
||
it('/ (GET)', async () => { | ||
logger.log('test'); | ||
return request(app.getHttpServer()).get('/').expect(403); | ||
}); | ||
}); |