Skip to content

Commit

Permalink
style: 탭 사이즈 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
sjy2335 committed Nov 13, 2024
1 parent 7175a69 commit e7bb234
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 159 deletions.
10 changes: 5 additions & 5 deletions backend/console-server/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
38 changes: 18 additions & 20 deletions backend/console-server/src/config/mailer.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}));
4 changes: 2 additions & 2 deletions backend/console-server/src/log/log.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
22 changes: 11 additions & 11 deletions backend/console-server/src/mail/mail.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
80 changes: 40 additions & 40 deletions backend/console-server/src/mail/mail.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>(MailService);
mailerService = module.get<MailerService>(MailerService);
});
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
MailService,
{ provide: MailerService, useValue: mockMailerService },
{ provide: ConfigService, useValue: mockConfigService },
],
}).compile();
mailService = module.get<MailService>(MailService);
mailerService = module.get<MailerService>(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'],
},
});
});
});
});
});
38 changes: 18 additions & 20 deletions backend/console-server/src/mail/mail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>(
'mailer.nameServers',
) as string[];
}
constructor(
private readonly mailerService: MailerService,
private readonly configService: ConfigService,
) {
this.nameServers = this.configService.get<string[]>('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,
},
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { Exclude, Expose } from 'class-transformer';

@Exclude()
export class ProjectResponseDto {
@Expose()
id: number;
@Expose()
id: number;
}
24 changes: 12 additions & 12 deletions backend/console-server/src/project/dto/create-project.dto.ts
Original file line number Diff line number Diff line change
@@ -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;
}
78 changes: 38 additions & 40 deletions backend/console-server/src/project/project.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>(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>(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);
});
});
});
});
2 changes: 1 addition & 1 deletion backend/console-server/src/project/project.controller.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
6 changes: 3 additions & 3 deletions backend/console-server/src/project/project.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
2 changes: 1 addition & 1 deletion backend/console-server/src/project/project.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Loading

0 comments on commit e7bb234

Please sign in to comment.