Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@testcontainers/mysql": "^10.16.0",
"@testcontainers/redis": "^10.16.0",
"@types/bcrypt": "^5.0.2",
"@types/cookie-parser": "^1.4.7",
"@types/eventsource": "^1.1.15",
Expand Down
6 changes: 3 additions & 3 deletions server/src/admin/service/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class AdminService {
const sessionId = uuid.v4();

if (cookie) {
this.redisService.del(`auth:${cookie}`);
await this.redisService.del(`auth:${cookie}`);
}

let cursor = '0';
Expand Down Expand Up @@ -74,7 +74,7 @@ export class AdminService {
}
} while (cursor !== '0');

this.redisService.set(
await this.redisService.set(
`auth:${sessionId}`,
admin.loginId,
`EX`,
Expand All @@ -86,7 +86,7 @@ export class AdminService {

async logoutAdmin(request: Request, response: Response) {
const sid = request.cookies['sessionId'];
this.redisService.del(`auth:${sid}`);
await this.redisService.del(`auth:${sid}`);
response.clearCookie('sessionId');
}

Expand Down
5 changes: 0 additions & 5 deletions server/src/common/redis/redis.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Global, Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { RedisService } from './redis.service';
import Redis from 'ioredis';
import Redis_Mock from 'ioredis-mock';

@Global()
@Module({
Expand All @@ -12,10 +11,6 @@ import Redis_Mock from 'ioredis-mock';
provide: 'REDIS_CLIENT',
inject: [ConfigService],
useFactory: async (configService: ConfigService) => {
const envType = process.env.NODE_ENV;
if (envType === 'test') {
return new Redis_Mock();
}
return new Redis({
host: configService.get<string>('REDIS_HOST'),
port: configService.get<number>('REDIS_PORT'),
Expand Down
8 changes: 8 additions & 0 deletions server/src/common/redis/redis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { RedisKey } from 'ioredis/built/utils/RedisCommander';
export class RedisService {
constructor(@Inject('REDIS_CLIENT') public readonly redisClient: Redis) {}

async disconnect(): Promise<void> {
await this.redisClient.disconnect();
}

async get(key: RedisKey): Promise<string | null> {
return this.redisClient.get(key);
}
Expand Down Expand Up @@ -116,6 +120,10 @@ export class RedisService {
return this.redisClient.flushdb();
}

async flushall(): Promise<void> {
this.redisClient.flushall();
}

async sismember(key: string, member: string | number): Promise<number> {
return this.redisClient.sismember(key, member);
}
Expand Down
2 changes: 1 addition & 1 deletion server/test/admin/e2e/logout.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('POST /api/admin/logout E2E Test', () => {
beforeAll(async () => {
app = global.testApp;
const redisService = app.get(RedisService);
await redisService.sadd('auth:sid', 'test1234');
await redisService.set('auth:sid', 'test1234');
});

it('관리자 로그인이 되어 있으면 로그아웃을 정상적으로 할 수 있다.', async () => {
Expand Down
38 changes: 38 additions & 0 deletions server/test/integration-test-global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { MySqlContainer, StartedMySqlContainer } from '@testcontainers/mysql';
import { RedisContainer, StartedRedisContainer } from '@testcontainers/redis';
const globalAny: any = global;

export default async () => {
console.log('Starting global setup...');
await createMysqlContainer();
await createRedisContainer();
console.log('Global setup completed.');
};

const createMysqlContainer = async () => {
console.log('Starting MySQL container...');
const mysqlContainer: StartedMySqlContainer = await new MySqlContainer(
'mysql:8.0.39',
)
.withDatabase('denamu')
.start();
globalAny.__MYSQL_CONTAINER__ = mysqlContainer;

process.env.DB_TYPE = 'mysql';
process.env.DB_HOST = mysqlContainer.getHost();
process.env.DB_PORT = mysqlContainer.getPort().toString();
process.env.DB_USERNAME = mysqlContainer.getUsername();
process.env.DB_PASSWORD = mysqlContainer.getUserPassword();
process.env.DB_DATABASE = mysqlContainer.getDatabase();
};

const createRedisContainer = async () => {
console.log('Starting Redis container...');
const redisContainer: StartedRedisContainer = await new RedisContainer(
'redis:6.0.16-alpine',
).start();
globalAny.__REDIS_CONTAINER__ = redisContainer;

process.env.REDIS_HOST = redisContainer.getHost();
process.env.REDIS_PORT = redisContainer.getPort().toString();
};
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const globalAny: any = global;

export default async () => {
console.log('Stopping NestJS application...');
if (globalAny.testApp) {
await globalAny.testApp.close();
delete globalAny.testApp;
}

console.log('Stopping MySQL container...');
if (globalAny.__MYSQL_CONTAINER__) {
await globalAny.__MYSQL_CONTAINER__.stop();
delete globalAny.__MYSQL_CONTAINER__;
}

console.log('Stopping Redis container...');
if (globalAny.__REDIS_CONTAINER__) {
await globalAny.__REDIS_CONTAINER__.stop();
delete globalAny.__REDIS_CONTAINER__;
}

console.log('Global teardown completed.');
};
4 changes: 2 additions & 2 deletions server/test/jest-e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"coverageDirectory": "test/coverage",
"setupFilesAfterEnv": ["./test/jest.setup.ts"],
"globalSetup": "./test/mysql-global-setup.ts",
"globalTeardown": "./test/mysql-global-teardown.ts",
"globalSetup": "./test/integration-test-global-setup.ts",
"globalTeardown": "./test/integration-test-global-teardown.ts",
"maxWorkers": 1
}
4 changes: 2 additions & 2 deletions server/test/jest-integration.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"coverageDirectory": "test/coverage",
"setupFilesAfterEnv": ["./test/jest.setup.ts"],
"globalSetup": "./test/mysql-global-setup.ts",
"globalTeardown": "./test/mysql-global-teardown.ts",
"globalSetup": "./test/integration-test-global-setup.ts",
"globalTeardown": "./test/integration-test-global-teardown.ts",
"maxWorkers": 1
}
7 changes: 6 additions & 1 deletion server/test/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { INestApplication, ValidationPipe } from '@nestjs/common';
import { ValidationPipe } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { AppModule } from '../src/app.module';
import { WinstonLoggerService } from '../src/common/logger/logger.service';
import { InternalExceptionsFilter } from '../src/common/filters/internal-exceptions.filter';
import { HttpExceptionsFilter } from '../src/common/filters/http-exception.filter';
import * as cookieParser from 'cookie-parser';
import { TestService } from '../src/common/test/test.service';
import { RedisService } from '../src/common/redis/redis.service';

const globalAny: any = global;

Expand Down Expand Up @@ -34,6 +35,10 @@ afterAll(async () => {
const testService = globalAny.testApp.get(TestService);
await testService.cleanDatabase();

const redisService: RedisService = globalAny.testApp.get(RedisService);
await redisService.flushall();
await redisService.disconnect();

console.log('Closing NestJS application...');
if (globalAny.testApp) {
await globalAny.testApp.close();
Expand Down
23 changes: 0 additions & 23 deletions server/test/mysql-global-setup.ts

This file was deleted.

2 changes: 1 addition & 1 deletion server/test/rss/e2e/history/accept.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('GET /api/rss/history/accept E2E Test', () => {
}
await Promise.all([
rssAcceptRepository.insert(rssAccepts),
redisService.sadd('auth:sid', 'test1234'),
redisService.set('auth:sid', 'test1234'),
]);
});

Expand Down
2 changes: 1 addition & 1 deletion server/test/rss/e2e/history/reject.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('GET /api/rss/history/reject E2E Test', () => {
}
await Promise.all([
rssRejectRepository.insert(rssAccepts),
redisService.sadd('auth:sid', 'test1234'),
redisService.set('auth:sid', 'test1234'),
]);
});

Expand Down