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([
{ kind: 'mention', userId: '12345', displayText: '프리리' },
{ kind: 'text', text: ' 사용법\n' },
{ kind: 'text', text: ' 내전 명령어 사용법\n' },
{ kind: 'emoticon', id: '1200281_035', altText: '스타' },
{ kind: 'text', text: ' !내전 일정\n' },
{ kind: 'text', text: ' !내전 일정\u3000\n' },
{ kind: 'emoticon', id: '1200281_035', altText: '스타' },
{
kind: 'text',
text: ' !내전 신청 코드 소환사이름#태그 포지션1,포지션2\n',
text: ' !내전 신청 코드 소환사이름#태그 포지션1,포지션2\u3000\n',
},
{ kind: 'emoticon', id: '1200281_035', altText: '스타' },
{ kind: 'text', text: ' !내전 계정등록 소환사이름#태그\n' },
{ kind: 'text', text: ' !내전 계정등록 소환사이름#태그\u3000\n' },
{ kind: 'emoticon', id: '1200281_035', altText: '스타' },
{
kind: 'text',
text: ' !내전 선호포지션등록 포지션1,포지션2\n',
text: ' !내전 선호포지션등록 포지션1,포지션2\u3000\n',
},
{ 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 { SecretService } from '../secret/secret.service';
import { tournamentModelDefinitions, TournamentModelTypes } from './schema';
@@ -36,13 +36,17 @@ export function resolveMongoConnectionOptions(
@Injectable({ scope: Scope.DEFAULT })
export class ConnectionService implements OnModuleInit {
private readonly logger = new Logger(ConnectionService.name);
private connection: mongoose.Connection | null = null;
constructor(private readonly secretService: SecretService) {}
private tournamentModels: Map<string, mongoose.Model<any>> | null = null;
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;
}
@@ -51,15 +55,15 @@ export class ConnectionService implements OnModuleInit {
);
const dbName = resolveMongoDbName();
const appName = resolveMongoAppName();
const connectionOptions = resolveMongoConnectionOptions(dbName, appName);
const defaultConnection = await mongoose
.createConnection(
connectionString,
resolveMongoConnectionOptions(dbName, appName),
)
.createConnection(connectionString, connectionOptions)
.asPromise();
this.connection = defaultConnection;
console.log(
`Default Connection이 새로 생성됨. dbName=${dbName} appName=${appName}`,
this.logger.log(
`MongoDB connection created. dbName=${dbName} appName=${appName} autoIndex=${
connectionOptions.autoIndex === true
}`,
);
return this.connection;
@@ -113,15 +117,24 @@ export class ConnectionService implements OnModuleInit {
const session = await connection.startSession(options);
return session as unknown as mongoose.ClientSession;
} catch (error) {
console.log(error);
this.logError('Failed to start MongoDB session', error);
}
}
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() {
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,
);
}
}