Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[기능] interview post #9

Merged
merged 4 commits into from
Sep 11, 2024
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
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MikroOrmModule } from '@mikro-orm/nestjs';
import { AuthModule } from './auth/auth.module';
import mikroOrmConfig, { testConfig } from './mikro-orm.config';
import { ReviewersModule } from './reviewers/reviewers.module';
import { InterviewModule } from './interview/interview.module';

@Module({
imports: [
Expand All @@ -13,6 +14,7 @@ import { ReviewersModule } from './reviewers/reviewers.module';
),
AuthModule,
ReviewersModule,
InterviewModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
4 changes: 4 additions & 0 deletions src/interview/dto/createInterview.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class CreateInterviewDTO {
interviewerId: bigint;
reviewerId: bigint;
}
41 changes: 41 additions & 0 deletions src/interview/interview.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Test, TestingModule } from '@nestjs/testing';
import { InterviewController } from './interview.controller';
import { InterviewService } from './interview.service';
import { EntityRepository, MikroORM } from '@mikro-orm/core';
import { MikroOrmModule, getRepositoryToken } from '@mikro-orm/nestjs';
import { Reviewer } from '../entities/reviewer';
import { testConfig } from '../mikro-orm.config';
import { Interview } from '../entities/interview';
import { Interviewer } from '../entities/interviewer';

describe('InterviewController', () => {
let controller: InterviewController;
let reviewerRepository: EntityRepository<Reviewer>;
let orm: MikroORM;

beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
MikroOrmModule.forRoot(testConfig),
MikroOrmModule.forFeature([Reviewer, Interviewer, Interview]),
],
providers: [InterviewService],
controllers: [InterviewController],
}).compile();

controller = module.get<InterviewController>(InterviewController);
reviewerRepository = module.get<EntityRepository<Reviewer>>(
getRepositoryToken(Reviewer),
);
orm = module.get(MikroORM);
});

beforeEach(async () => {
await orm.getSchemaGenerator().dropSchema();
await orm.getSchemaGenerator().createSchema();
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
7 changes: 7 additions & 0 deletions src/interview/interview.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Controller } from '@nestjs/common';
import { InterviewService } from './interview.service';

@Controller('interview')
export class InterviewController {
constructor(private readonly interviewService: InterviewService) {}
}
13 changes: 13 additions & 0 deletions src/interview/interview.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { InterviewService } from './interview.service';
import { InterviewController } from './interview.controller';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { Interview } from '../entities/interview';
import { Reviewer } from '../entities/reviewer';

@Module({
imports: [MikroOrmModule.forFeature([Interview, Reviewer])],
controllers: [InterviewController],
providers: [InterviewService],
})
export class InterviewModule {}
77 changes: 77 additions & 0 deletions src/interview/interview.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { Test, TestingModule } from '@nestjs/testing';
import { InterviewService } from './interview.service';
import { getRepositoryToken, MikroOrmModule } from '@mikro-orm/nestjs';
import { Reviewer } from '../entities/reviewer';
import { testConfig } from '../mikro-orm.config';
import { Interview } from '../entities/interview';
import { EntityRepository, MikroORM } from '@mikro-orm/sqlite';
import { plainToInstance } from 'class-transformer';
import { Interviewer } from '../entities/interviewer';
import { REVIEWER_LIST } from '../../test/fixture/reviewers.common';
import { INTERVIEWER_LIST } from '../../test/fixture/interviewer.common';
import { CreateInterviewDTO } from './dto/createInterview.dto';

describe('InterviewService', () => {
let service: InterviewService;
let reviewerRepository: EntityRepository<Reviewer>;
let interviewerRepository: EntityRepository<Interviewer>;
let orm: MikroORM;

let reviewerList: Reviewer[];
let interviewerList: Interviewer[];

beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
MikroOrmModule.forRoot(testConfig),
MikroOrmModule.forFeature([Reviewer, Interviewer, Interview]),
],
providers: [InterviewService],
}).compile();

orm = module.get(MikroORM);
service = module.get<InterviewService>(InterviewService);
reviewerRepository = module.get<EntityRepository<Reviewer>>(
getRepositoryToken(Reviewer),
);
interviewerRepository = module.get<EntityRepository<Interviewer>>(
getRepositoryToken(Interviewer),
);
});

beforeEach(async () => {
await orm.getSchemaGenerator().dropSchema();
await orm.getSchemaGenerator().createSchema();

await Promise.all(
REVIEWER_LIST.map((reviewer) => reviewerRepository.create(reviewer)),
);

await Promise.all(
INTERVIEWER_LIST.map((interviewer) =>
interviewerRepository.create(interviewer),
),
);

await orm.em.flush();
reviewerList = await reviewerRepository.findAll();
interviewerList = await interviewerRepository.findAll();
});

it('should be defined', () => {
expect(service).toBeDefined();
});

it('interviewer 생성', async () => {
const createDTO = plainToInstance(CreateInterviewDTO, {
reviewerId: reviewerList[0].id,
interviewerId: interviewerList[0].id,
});

const response = await service.create(createDTO);

expect(response).toBeInstanceOf(Interview);
expect(response.interviewer.id).toBe(interviewerList[0].id);
expect(response.reviewer.id).toBe(reviewerList[0].id);
});
});
36 changes: 36 additions & 0 deletions src/interview/interview.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Injectable } from '@nestjs/common';
import { CreateInterviewDTO } from './dto/createInterview.dto';
import { EntityRepository } from '@mikro-orm/core';
import { Interview } from '../entities/interview';
import { InjectRepository } from '@mikro-orm/nestjs';
import { Interviewer } from '../entities/interviewer';
import { Reviewer } from '../entities/reviewer';

@Injectable()
export class InterviewService {
constructor(
@InjectRepository(Interview)
private readonly interviewRepository: EntityRepository<Interview>,
@InjectRepository(Interviewer)
private readonly interviewerRepository: EntityRepository<Interview>,
@InjectRepository(Reviewer)
private readonly reviewerRepository: EntityRepository<Interview>,
) {}

async create(createDTO: CreateInterviewDTO) {
const [interviewer, reviewer] = await Promise.all([
this.interviewerRepository.findOneOrFail({
id: createDTO.interviewerId,
}),
this.reviewerRepository.findOneOrFail({
id: createDTO.reviewerId,
}),
]);

return this.interviewRepository.create({
title: 'test',
interviewer,
reviewer,
});
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ReviewersController } from '../reviewers.controller';
import { ReviewersService } from '../reviewers.service';
import { ReviewersController } from './reviewers.controller';
import { ReviewersService } from './reviewers.service';
import { getRepositoryToken, MikroOrmModule } from '@mikro-orm/nestjs';
import { Reviewer } from '../../entities/reviewer';
import { testConfig } from '../../mikro-orm.config';
import { REVIEWER_LIST } from './reviewers.common';
import { Reviewer } from '../entities/reviewer';
import { testConfig } from '../mikro-orm.config';
import { REVIEWER_LIST } from '../../test/fixture/reviewers.common';
import { EntityRepository } from '@mikro-orm/core';
import { MikroORM } from '@mikro-orm/sqlite';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ReviewersService } from '../reviewers.service';
import { ReviewersService } from './reviewers.service';
import { MikroOrmModule, getRepositoryToken } from '@mikro-orm/nestjs';
import { testConfig } from '../../mikro-orm.config';
import { Reviewer } from '../../entities/reviewer';
import { testConfig } from '../mikro-orm.config';
import { Reviewer } from '../entities/reviewer';
import { EntityRepository } from '@mikro-orm/postgresql';
import { MikroORM } from '@mikro-orm/sqlite';
import { REVIEWER_LIST } from './reviewers.common';
import { REVIEWER_LIST } from '../../test/fixture/reviewers.common';

describe('ReviwersService', () => {
let service: ReviewersService;
Expand Down
10 changes: 10 additions & 0 deletions test/fixture/interviewer.common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Interviewer } from 'src/entities/interviewer';

export const INTERVIEWER_LIST: Partial<Interviewer>[] = [
{
name: 'test1',
},
{
name: 'test',
},
];
2 changes: 1 addition & 1 deletion test/reviewers.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AppModule } from './../src/app.module';
import { EntityRepository } from '@mikro-orm/core';
import { getRepositoryToken } from '@mikro-orm/nestjs';
import { Reviewer } from '../src/entities/reviewer';
import { REVIEWER_LIST } from '../src/reviewers/test/reviewers.common';
import { REVIEWER_LIST } from './fixture/reviewers.common';
import { MikroORM } from '@mikro-orm/sqlite';

describe('ReviewerController (e2e)', () => {
Expand Down