From e7bb234b71b16a1e9b2cf914cc00bff4e241d346 Mon Sep 17 00:00:00 2001 From: sjy2335 Date: Wed, 13 Nov 2024 13:57:08 +0900 Subject: [PATCH] =?UTF-8?q?style:=20=ED=83=AD=20=EC=82=AC=EC=9D=B4?= =?UTF-8?q?=EC=A6=88=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/console-server/src/app.controller.ts | 10 +-- .../src/config/mailer.config.ts | 38 +++++---- backend/console-server/src/log/log.module.ts | 4 +- .../console-server/src/mail/mail.module.ts | 22 ++--- .../src/mail/mail.service.spec.ts | 80 +++++++++---------- .../console-server/src/mail/mail.service.ts | 38 +++++---- .../dto/create-project-response.dto.ts | 4 +- .../src/project/dto/create-project.dto.ts | 24 +++--- .../src/project/project.controller.spec.ts | 78 +++++++++--------- .../src/project/project.controller.ts | 2 +- .../src/project/project.module.ts | 6 +- .../src/project/project.service.spec.ts | 2 +- .../src/project/project.service.ts | 3 +- 13 files changed, 152 insertions(+), 159 deletions(-) diff --git a/backend/console-server/src/app.controller.ts b/backend/console-server/src/app.controller.ts index 62a2f2c8..7eb09679 100644 --- a/backend/console-server/src/app.controller.ts +++ b/backend/console-server/src/app.controller.ts @@ -3,10 +3,10 @@ import { AppService } from './app.service'; @Controller() export class AppController { - constructor(private readonly appService: AppService) {} + constructor(private readonly appService: AppService) {} - @Get() - getHello() { - return this.appService.getHello(); - } + @Get() + getHello() { + return this.appService.getHello(); + } } diff --git a/backend/console-server/src/config/mailer.config.ts b/backend/console-server/src/config/mailer.config.ts index 357868a7..415a71b8 100644 --- a/backend/console-server/src/config/mailer.config.ts +++ b/backend/console-server/src/config/mailer.config.ts @@ -3,26 +3,24 @@ import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handleba import { join } from 'path'; export default registerAs('mailer', () => ({ - transport: { - host: process.env.EMAIL_HOST, - port: Number(process.env.EMAIL_PORT) || 587, - secure: false, - auth: { - user: process.env.EMAIL_USER, - pass: process.env.EMAIL_PASS, + transport: { + host: process.env.EMAIL_HOST, + port: Number(process.env.EMAIL_PORT) || 587, + secure: false, + auth: { + user: process.env.EMAIL_USER, + pass: process.env.EMAIL_PASS, + }, }, - }, - defaults: { - from: process.env.EMAIL_FROM, - }, - template: { - dir: join(__dirname, '../mail/templates'), - adapter: new HandlebarsAdapter(), - options: { - strict: true, + defaults: { + from: process.env.EMAIL_FROM, }, - }, - nameServers: (process.env.NAME_SERVERS || '') - .split(',') - .map((item) => item.trim()), + template: { + dir: join(__dirname, '../mail/templates'), + adapter: new HandlebarsAdapter(), + options: { + strict: true, + }, + }, + nameServers: (process.env.NAME_SERVERS || '').split(',').map((item) => item.trim()), })); diff --git a/backend/console-server/src/log/log.module.ts b/backend/console-server/src/log/log.module.ts index 87815d73..98713be1 100644 --- a/backend/console-server/src/log/log.module.ts +++ b/backend/console-server/src/log/log.module.ts @@ -3,7 +3,7 @@ import { LogService } from './log.service'; import { LogController } from './log.controller'; @Module({ - controllers: [LogController], - providers: [LogService], + controllers: [LogController], + providers: [LogService], }) export class LogModule {} diff --git a/backend/console-server/src/mail/mail.module.ts b/backend/console-server/src/mail/mail.module.ts index a0dd84f6..9f8075a8 100644 --- a/backend/console-server/src/mail/mail.module.ts +++ b/backend/console-server/src/mail/mail.module.ts @@ -4,16 +4,16 @@ import { MailService } from './mail.service'; import { ConfigModule, ConfigService } from '@nestjs/config'; @Module({ - imports: [ - ConfigModule, - MailerModule.forRootAsync({ - imports: [ConfigModule], - inject: [ConfigService], - useFactory: (configService: ConfigService) => - configService.get('mailer') as MailerOptions, - }), - ], - providers: [MailService], - exports: [MailService], + imports: [ + ConfigModule, + MailerModule.forRootAsync({ + imports: [ConfigModule], + inject: [ConfigService], + useFactory: (configService: ConfigService) => + configService.get('mailer') as MailerOptions, + }), + ], + providers: [MailService], + exports: [MailService], }) export class MailModule {} diff --git a/backend/console-server/src/mail/mail.service.spec.ts b/backend/console-server/src/mail/mail.service.spec.ts index c84f7604..75057b94 100644 --- a/backend/console-server/src/mail/mail.service.spec.ts +++ b/backend/console-server/src/mail/mail.service.spec.ts @@ -5,51 +5,51 @@ import { MailerService } from '@nestjs-modules/mailer'; import { MailService } from './mail.service'; describe('MailService의', () => { - let mailService: MailService; - let mailerService: MailerService; + let mailService: MailService; + let mailerService: MailerService; - const mockMailerService = { - sendMail: jest.fn(), - }; - const mockConfigService = { - get: jest.fn((key: string) => { - if (key === 'mailer.nameServers') return ['ns.test.site']; - return null; - }), - }; + const mockMailerService = { + sendMail: jest.fn(), + }; + const mockConfigService = { + get: jest.fn((key: string) => { + if (key === 'mailer.nameServers') return ['ns.test.site']; + return null; + }), + }; - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: [ - MailService, - { provide: MailerService, useValue: mockMailerService }, - { provide: ConfigService, useValue: mockConfigService }, - ], - }).compile(); - mailService = module.get(MailService); - mailerService = module.get(MailerService); - }); + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [ + MailService, + { provide: MailerService, useValue: mockMailerService }, + { provide: ConfigService, useValue: mockConfigService }, + ], + }).compile(); + mailService = module.get(MailService); + mailerService = module.get(MailerService); + }); - afterEach(() => { - jest.clearAllMocks(); - }); + afterEach(() => { + jest.clearAllMocks(); + }); - describe('sendNameServerInfo()는', () => { - it('mailer 모듈의 sendMail()을 호출합니다.', async () => { - const email = 'test@test.com'; - const projectName = 'test'; + describe('sendNameServerInfo()는', () => { + it('mailer 모듈의 sendMail()을 호출합니다.', async () => { + const email = 'test@test.com'; + const projectName = 'test'; - await mailService.sendNameServerInfo(email, projectName); + await mailService.sendNameServerInfo(email, projectName); - expect(mailerService.sendMail).toHaveBeenCalledWith({ - to: email, - subject: '[와치덕스] 네임서버 정보를 전송합니다.', - template: './nameserver', - context: { - projectName: projectName, - nameServers: ['ns.test.site'], - }, - }); + expect(mailerService.sendMail).toHaveBeenCalledWith({ + to: email, + subject: '[와치덕스] 네임서버 정보를 전송합니다.', + template: './nameserver', + context: { + projectName: projectName, + nameServers: ['ns.test.site'], + }, + }); + }); }); - }); }); diff --git a/backend/console-server/src/mail/mail.service.ts b/backend/console-server/src/mail/mail.service.ts index 3557d379..9fdb86a9 100644 --- a/backend/console-server/src/mail/mail.service.ts +++ b/backend/console-server/src/mail/mail.service.ts @@ -4,26 +4,24 @@ import { ConfigService } from '@nestjs/config'; @Injectable() export class MailService { - private readonly nameServers: string[]; + private readonly nameServers: string[]; - constructor( - private readonly mailerService: MailerService, - private readonly configService: ConfigService, - ) { - this.nameServers = this.configService.get( - 'mailer.nameServers', - ) as string[]; - } + constructor( + private readonly mailerService: MailerService, + private readonly configService: ConfigService, + ) { + this.nameServers = this.configService.get('mailer.nameServers') as string[]; + } - async sendNameServerInfo(email: string, projectName: string) { - await this.mailerService.sendMail({ - to: email, - subject: '[와치덕스] 네임서버 정보를 전송합니다.', - template: './nameserver', - context: { - projectName: projectName, - nameServers: this.nameServers, - }, - }); - } + async sendNameServerInfo(email: string, projectName: string) { + await this.mailerService.sendMail({ + to: email, + subject: '[와치덕스] 네임서버 정보를 전송합니다.', + template: './nameserver', + context: { + projectName: projectName, + nameServers: this.nameServers, + }, + }); + } } diff --git a/backend/console-server/src/project/dto/create-project-response.dto.ts b/backend/console-server/src/project/dto/create-project-response.dto.ts index 9e68c3f1..bb02451a 100644 --- a/backend/console-server/src/project/dto/create-project-response.dto.ts +++ b/backend/console-server/src/project/dto/create-project-response.dto.ts @@ -2,6 +2,6 @@ import { Exclude, Expose } from 'class-transformer'; @Exclude() export class ProjectResponseDto { - @Expose() - id: number; + @Expose() + id: number; } diff --git a/backend/console-server/src/project/dto/create-project.dto.ts b/backend/console-server/src/project/dto/create-project.dto.ts index 624c8d51..13372d87 100644 --- a/backend/console-server/src/project/dto/create-project.dto.ts +++ b/backend/console-server/src/project/dto/create-project.dto.ts @@ -1,19 +1,19 @@ import { IsEmail, IsIP, IsNotEmpty, IsString } from 'class-validator'; export class CreateProjectDto { - @IsString() - @IsNotEmpty() - name: string; + @IsString() + @IsNotEmpty() + name: string; - @IsIP() - @IsNotEmpty() - ip: string; + @IsIP() + @IsNotEmpty() + ip: string; - @IsString() - @IsNotEmpty() - domain: string; + @IsString() + @IsNotEmpty() + domain: string; - @IsEmail() - @IsNotEmpty() - email: string; + @IsEmail() + @IsNotEmpty() + email: string; } diff --git a/backend/console-server/src/project/project.controller.spec.ts b/backend/console-server/src/project/project.controller.spec.ts index 6a014fb5..ee1fd6a3 100644 --- a/backend/console-server/src/project/project.controller.spec.ts +++ b/backend/console-server/src/project/project.controller.spec.ts @@ -6,52 +6,50 @@ import type { CreateProjectDto } from './dto/create-project.dto'; import { ConflictException } from '@nestjs/common'; describe('ProjectController의', () => { - let projectController: ProjectController; - - const mockProjectService = { - create: jest.fn(), - }; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [ProjectController], - providers: [{ provide: ProjectService, useValue: mockProjectService }], - }).compile(); - - projectController = module.get(ProjectController); - }); - - afterEach(() => { - jest.clearAllMocks(); - }); - - describe('create()는', () => { - const createProjectDto: CreateProjectDto = { - name: '테스트 프로젝트', - email: 'test@test.com', - ip: '127.0.0.1', - domain: 'host.test.com', + let projectController: ProjectController; + + const mockProjectService = { + create: jest.fn(), }; - it('올바른 프로젝트 정보가 들어왔을 때 서비스의 create() 메소드를 호출해 프로젝트를 생성합니다.', async () => { - const result = { id: 1, ...createProjectDto }; - (mockProjectService.create as jest.Mock).mockResolvedValue(result); + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [ProjectController], + providers: [{ provide: ProjectService, useValue: mockProjectService }], + }).compile(); - const response = await projectController.create(createProjectDto); + projectController = module.get(ProjectController); + }); - expect(response).toEqual(result); - expect(mockProjectService.create).toHaveBeenCalledWith(createProjectDto); + afterEach(() => { + jest.clearAllMocks(); }); - it('이미 존재하는 프로젝트 정보가 들어왔을 때 ConflictException을 던집니다.', async () => { - (mockProjectService.create as jest.Mock).mockRejectedValue( - new ConflictException(), - ); + describe('create()는', () => { + const createProjectDto: CreateProjectDto = { + name: '테스트 프로젝트', + email: 'test@test.com', + ip: '127.0.0.1', + domain: 'host.test.com', + }; + + it('올바른 프로젝트 정보가 들어왔을 때 서비스의 create() 메소드를 호출해 프로젝트를 생성합니다.', async () => { + const result = { id: 1, ...createProjectDto }; + (mockProjectService.create as jest.Mock).mockResolvedValue(result); + + const response = await projectController.create(createProjectDto); + + expect(response).toEqual(result); + expect(mockProjectService.create).toHaveBeenCalledWith(createProjectDto); + }); + + it('이미 존재하는 프로젝트 정보가 들어왔을 때 ConflictException을 던집니다.', async () => { + (mockProjectService.create as jest.Mock).mockRejectedValue(new ConflictException()); - await expect(projectController.create(createProjectDto)).rejects.toThrow( - ConflictException, - ); - expect(mockProjectService.create).toHaveBeenCalledWith(createProjectDto); + await expect(projectController.create(createProjectDto)).rejects.toThrow( + ConflictException, + ); + expect(mockProjectService.create).toHaveBeenCalledWith(createProjectDto); + }); }); - }); }); diff --git a/backend/console-server/src/project/project.controller.ts b/backend/console-server/src/project/project.controller.ts index 22e486b4..ed631ea1 100644 --- a/backend/console-server/src/project/project.controller.ts +++ b/backend/console-server/src/project/project.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, HttpCode, HttpStatus, Param, Query } from '@nestjs/common'; +import { Controller, Get, HttpCode, HttpStatus, Query } from '@nestjs/common'; import { Post } from '@nestjs/common'; import { Body } from '@nestjs/common'; import { ProjectService } from './project.service'; diff --git a/backend/console-server/src/project/project.module.ts b/backend/console-server/src/project/project.module.ts index 040b9398..a11e10d5 100644 --- a/backend/console-server/src/project/project.module.ts +++ b/backend/console-server/src/project/project.module.ts @@ -6,8 +6,8 @@ import { Project } from './entities/project.entity'; import { MailModule } from '../mail/mail.module'; @Module({ - imports: [TypeOrmModule.forFeature([Project]), MailModule], - controllers: [ProjectController], - providers: [ProjectService], + imports: [TypeOrmModule.forFeature([Project]), MailModule], + controllers: [ProjectController], + providers: [ProjectService], }) export class ProjectModule {} diff --git a/backend/console-server/src/project/project.service.spec.ts b/backend/console-server/src/project/project.service.spec.ts index d044ca2c..921d1ec7 100644 --- a/backend/console-server/src/project/project.service.spec.ts +++ b/backend/console-server/src/project/project.service.spec.ts @@ -9,7 +9,7 @@ import { QueryFailedError } from 'typeorm'; import type { CreateProjectDto } from './dto/create-project.dto'; import { ProjectResponseDto } from './dto/create-project-response.dto'; import { ConflictException } from '@nestjs/common'; -import { FindByGenerationDto } from './dto/find-by-generation.dto'; +import type { FindByGenerationDto } from './dto/find-by-generation.dto'; import { FindByGenerationResponseDto } from './dto/find-by-generation-response.dto'; import { plainToInstance } from 'class-transformer'; diff --git a/backend/console-server/src/project/project.service.ts b/backend/console-server/src/project/project.service.ts index 8159315f..bc4729e1 100644 --- a/backend/console-server/src/project/project.service.ts +++ b/backend/console-server/src/project/project.service.ts @@ -17,7 +17,6 @@ export class ProjectService { private readonly mailService: MailService, ) {} - async create(createProjectDto: CreateProjectDto) { try { const project = this.projectRepository.create(createProjectDto); @@ -47,7 +46,7 @@ export class ProjectService { }); return projects.map((p) => plainToInstance(FindByGenerationResponseDto, p.name)); - + } } function isUniqueConstraintViolation(error: Error): boolean {