Skip to content

Commit

Permalink
test(!): write a working e2e test for the project for automation!
Browse files Browse the repository at this point in the history
  • Loading branch information
vimkim committed Feb 10, 2024
1 parent a08ab2d commit ba45527
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions server/test/app.e2e-spec.ts
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);
});
});

0 comments on commit ba45527

Please sign in to comment.