chore: restore api test baseline and logging

This commit is contained in:
dahyeon committed 2026-06-27 14:19:00 -07:00
1 parent 60a006008a
commit 871a5fe78a
3 files changed
+31 -18

No files matched your search

@@ -56,20 +56,20 @@ describe('DakaoSubscriber', () => {
expect(segments).toEqual([ expect(segments).toEqual([
{ kind: 'mention', userId: '12345', displayText: '프리리' }, { kind: 'mention', userId: '12345', displayText: '프리리' },
{ kind: 'text', text: ' 사용법\n' }, { kind: 'text', text: ' 내전 명령어 사용법\n' },
{ kind: 'emoticon', id: '1200281_035', altText: '스타' }, { kind: 'emoticon', id: '1200281_035', altText: '스타' },
{ kind: 'text', text: ' !내전 일정\n' }, { kind: 'text', text: ' !내전 일정\u3000\n' },
{ kind: 'emoticon', id: '1200281_035', altText: '스타' }, { kind: 'emoticon', id: '1200281_035', altText: '스타' },
{ {
kind: 'text', kind: 'text',
text: ' !내전 신청 코드 소환사이름#태그 포지션1,포지션2\n', text: ' !내전 신청 코드 소환사이름#태그 포지션1,포지션2\u3000\n',
}, },
{ kind: 'emoticon', id: '1200281_035', altText: '스타' }, { kind: 'emoticon', id: '1200281_035', altText: '스타' },
{ kind: 'text', text: ' !내전 계정등록 소환사이름#태그\n' }, { kind: 'text', text: ' !내전 계정등록 소환사이름#태그\u3000\n' },
{ kind: 'emoticon', id: '1200281_035', altText: '스타' }, { kind: 'emoticon', id: '1200281_035', altText: '스타' },
{ {
kind: 'text', kind: 'text',
text: ' !내전 선호포지션등록 포지션1,포지션2\n', text: ' !내전 선호포지션등록 포지션1,포지션2\u3000\n',
}, },
{ kind: 'emoticon', id: '1200281_035', altText: '스타' }, { kind: 'emoticon', id: '1200281_035', altText: '스타' },
{ {
@@ -1,4 +1,4 @@
import { Injectable, Scope, OnModuleInit } from '@nestjs/common'; import { Injectable, Logger, Scope, OnModuleInit } from '@nestjs/common';
import mongoose from 'mongoose'; import mongoose from 'mongoose';
import { SecretService } from '../secret/secret.service'; import { SecretService } from '../secret/secret.service';
import { tournamentModelDefinitions, TournamentModelTypes } from './schema'; import { tournamentModelDefinitions, TournamentModelTypes } from './schema';
@@ -36,13 +36,17 @@ export function resolveMongoConnectionOptions(
@Injectable({ scope: Scope.DEFAULT }) @Injectable({ scope: Scope.DEFAULT })
export class ConnectionService implements OnModuleInit { export class ConnectionService implements OnModuleInit {
private readonly logger = new Logger(ConnectionService.name);
private connection: mongoose.Connection | null = null; private connection: mongoose.Connection | null = null;
constructor(private readonly secretService: SecretService) {} constructor(private readonly secretService: SecretService) {}
private tournamentModels: Map<string, mongoose.Model<any>> | null = null; private tournamentModels: Map<string, mongoose.Model<any>> | null = null;
public async getConnection(): Promise<mongoose.Connection> { public async getConnection(): Promise<mongoose.Connection> {
if (this.connection !== null && this.connection.readyState === 1) { if (
this.connection !== null &&
this.connection.readyState === mongoose.ConnectionStates.connected
) {
return this.connection; return this.connection;
} }
@@ -51,15 +55,15 @@ export class ConnectionService implements OnModuleInit {
); );
const dbName = resolveMongoDbName(); const dbName = resolveMongoDbName();
const appName = resolveMongoAppName(); const appName = resolveMongoAppName();
const connectionOptions = resolveMongoConnectionOptions(dbName, appName);
const defaultConnection = await mongoose const defaultConnection = await mongoose
.createConnection( .createConnection(connectionString, connectionOptions)
connectionString,
resolveMongoConnectionOptions(dbName, appName),
)
.asPromise(); .asPromise();
this.connection = defaultConnection; this.connection = defaultConnection;
console.log( this.logger.log(
`Default Connection이 새로 생성됨. dbName=${dbName} appName=${appName}`, `MongoDB connection created. dbName=${dbName} appName=${appName} autoIndex=${
connectionOptions.autoIndex === true
}`,
); );
return this.connection; return this.connection;
@@ -113,15 +117,24 @@ export class ConnectionService implements OnModuleInit {
const session = await connection.startSession(options); const session = await connection.startSession(options);
return session as unknown as mongoose.ClientSession; return session as unknown as mongoose.ClientSession;
} catch (error) { } catch (error) {
console.log(error); this.logError('Failed to start MongoDB session', error);
} }
} }
public async onModuleInit() { public async onModuleInit() {
await this.getConnection().catch(console.error); await this.getConnection().catch((error: unknown) => {
this.logError('Failed to initialize MongoDB connection', error);
});
} }
public async onModuleDestroy() { public async onModuleDestroy() {
await this.connection?.close(); await this.connection?.close();
} }
private logError(message: string, error: unknown): void {
this.logger.error(
`${message}: ${error instanceof Error ? error.message : String(error)}`,
error instanceof Error ? error.stack : undefined,
);
}
} }
+3 -3
View File
@@ -1,7 +1,7 @@
import { INestApplicationContext } from '@nestjs/common'; import { INestApplicationContext } from '@nestjs/common';
import { IoAdapter } from '@nestjs/platform-socket.io'; import { IoAdapter } from '@nestjs/platform-socket.io';
import { createAdapter } from '@socket.io/redis-adapter'; import { createAdapter } from '@socket.io/redis-adapter';
import type { ServerOptions } from 'socket.io'; import type { Server, ServerOptions } from 'socket.io';
import { import {
AuctionRedisService, AuctionRedisService,
type AuctionRedisClient, type AuctionRedisClient,
@@ -26,8 +26,8 @@ export class RedisIoAdapter extends IoAdapter {
this.adapterConstructor = createAdapter(pubClient, this.subClient); this.adapterConstructor = createAdapter(pubClient, this.subClient);
} }
override createIOServer(port: number, options?: ServerOptions) { override createIOServer(port: number, options?: ServerOptions): Server {
const server = super.createIOServer(port, options); const server = super.createIOServer(port, options) as Server;
if (this.adapterConstructor) { if (this.adapterConstructor) {
server.adapter(this.adapterConstructor); server.adapter(this.adapterConstructor);
} }