Skip to content

Commit

Permalink
fix/#172 관리자 모듈 분리에 따른 테스트 코드 개선 (#173)
Browse files Browse the repository at this point in the history
* fix: aics-admin 모듈에 testFixtures 관련 의존성 및 디렉토리 추가

* refactor: lab domain test 오타 수정

* feat: club domain test 작성

* refactor: 회원가입 시 비밀번호 암호화 로직 수정

* refactor: comment Domain test 수정

* refactor: Post Domain test 수정

* refactor: FakeLabRepository 수정

* refactor: AboutFacade, AboutAdminFacade 수정

* refactor: AuthServiceTest 수정

* refactor: club facade test 작성

* Create FakeClubRepository.java

* refactor: 다른 테스트를 위해 주석처리

* refactor: club command, query Service 구현

* refactor: club query service 누락된 메소드 테스트 추가

* feat: About command, query service test code 작성

* refactor: comment command, query service test 구현

* refactor: lab command, query service test 작성

* refactor: Post command, query service test 작성

* refactor: Professor command, query service test 작성

* refactor: test container로 수정

* feat: User command, query service test 작성

* feat: ClubAdminFacadeTest 작성

* feat: UserAdminFacadeTest 작성

* feat: PostAdminFacadeTest 작성

* feat: jacoco.gradle 설정 변경

* refactor: clubFacadeTest 수정

* refactor: aboutFacadeTest 수정

* feat: file, lab, professor admin test 구조 설정

* feat: ProfessorAdminFacadeTest 작성

* feat: labAdminFacadeTest 작성

* feat: jacoco.gradle 설정 변경

* refactor: jacoco 커버리지 limit 제거

* refactor: 변경된 파일에 대한 최소 커버리지 기준 70%로 변경

* fix: UserDomainTest 컴파일 에러 픽스

* feat: LabFacadeTest 및 ProfessorFacadeTest 추가

* feat: supplier를 사용한 TestContainer 구현

* refactor: about command, query service test 수정

* refactor: club command, query service test 수정

* refactor: comment command, query service test 수정

* refactor: lab command, query service test 구현

* refactor: post command, query service test 수정

* refactor: professor command, query service test 작성

* refactor: user command, query

* refactor: 컨벤션 수정

* refactor: 컨벤션 수정

* refactor: admin 모듈 test code 수정

* refactor: about facade test 수정

* refactor: authservice test 수정

* refactor: 구현되어 있는 api 모듈 testcode 수정

* feat: comment, post facade testcode 작성

* feat: user facade testcode 작성

* refactor: labCommandService deleteLab testcode 작성

* refactor: mock 패키지 repository 디렉토리 생성

* refactor: 메서드 분리 및 builder 제거

* refactor: pageable response 검증 추가

* refactor: 데이터 개수를 넘어선 페이지 요청시 빈값 검사 추가

* refactor: 삭제 이전 null값 확인 추가

* refactor: 잘못된 람다식 수정

* refactor: 잘못된 메소드명 수정 및 테스트 추가

* refactor: clubDomainTest 수정

* refactor: 삭제된 게시물 제외하고 조회하는지 확인 추가

* refactor: 같은 카테고리의 게시글만 조회하는지 확인

* refactor: user domain test password 수정

* refactor: 각 도메인 test 중복 코드 정리

* refactor: domain test 코드 수정

* refactor: domain test 코드 수정

* refactor: comment query service test 에러 수정

* refactor: userdomain testcode 수정

* feat: 코멘트 반영 API 테스트 커버리지 상승

* refactor: FacadeTest DisplayName 일관성 수정

* refactor: 람다식 적용

* refactor: 순서 적용 및 람다식 추가 적용

* refactor: userQueryService testcode 추가

* refactor: aboutCommandService testcode 추가

* refactor: UserCommandService testcode 추가

* refactor: clubCommandService testcode 추가

* refactor: professorQueryServiceTest 추가 작성

* refactor: deletedAt 검증 추가

* refactor: commentQueryService getById 수정

* refactor: post getbyid 쿼리 수정

* refactor: 에러 수정

* refactor: user domain test 추가

* refactor: userDomain test code 추가

* refactor: 메서드 분리 및 검증 구체화

---------

Co-authored-by: minjo-on <[email protected]>
Co-authored-by: LeeShinHeang <[email protected]>
3 people authored Jan 18, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent c8f5a43 commit 38e9334
Showing 78 changed files with 3,524 additions and 1,411 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/pull-request-test-coverage.yml
Original file line number Diff line number Diff line change
@@ -42,12 +42,12 @@ jobs:
${{ github.workspace }}/aics-domain/build/jacoco/test/jacocoTestReport.xml
${{ github.workspace }}/aics-api/build/jacoco/test/jacocoTestReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 10
min-coverage-changed-files: 80
min-coverage-overall: 80
min-coverage-changed-files: 70
update-comment: true

- name: Fail PR if overall coverage is less than 80% (temporarily 10%)
if: ${{ steps.jacoco.outputs.coverage-overall < 10.0 }}
- name: Fail PR if overall coverage is less than 80%
if: ${{ steps.jacoco.outputs.coverage-overall < 80.0 }}
uses: actions/github-script@v6
with:
script: |
17 changes: 17 additions & 0 deletions aics-admin/build.gradle
Original file line number Diff line number Diff line change
@@ -11,4 +11,21 @@ dependencies {
implementation project(':aics-common')
implementation project(':aics-infra')
implementation project(':aics-global-utils')

testFixturesImplementation project(':aics-domain')
testFixturesImplementation project(':aics-common')
testFixturesImplementation project(':aics-infra')
testFixturesImplementation project(':aics-global-utils')

testFixturesImplementation testFixtures(project(':aics-domain'))
testFixturesImplementation testFixtures(project(':aics-global-utils'))
}
apply from: "../gradle/jacoco.gradle"

jacocoTestReport {
dependsOn test
reports {
xml.required = true
html.required = true
}
}
Original file line number Diff line number Diff line change
@@ -18,13 +18,13 @@ public class LabAdminFacade {
private final LabQueryService labQueryService;

public LabPersistResponse createLab(LabRequest request) {
Long id = labCommandService.createLab(request.name(), request.location(), request.site(), request.professor());
Long id = labCommandService.createLab(request.name(), request.loc(), request.site(), request.advisor());
return LabPersistResponse.of(id);
}

public void updateLab(Long id, LabRequest request) {
Lab lab = labQueryService.getById(id);
labCommandService.updateLab(lab, request.name(), request.location(), request.site(), request.professor());
labCommandService.updateLab(lab, request.name(), request.loc(), request.site(), request.advisor());
}

public void deleteLab(Long id) {
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ public record LabRequest(
@Schema(description = "연구실 위치", example = "8502, 8503", requiredMode = REQUIRED)
@NotBlank
@Size(max = 10)
String location,
String loc,

@Schema(description = "연구실 홈페이지", example = "http://ailab.kyonggi.ac.kr", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank
@@ -28,6 +28,6 @@ public record LabRequest(
@Schema(description = "연구실 담당교수", example = "박민준", requiredMode = REQUIRED)
@NotBlank
@Size(max = 15)
String professor
String advisor
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package about.application;

import static kgu.developers.domain.about.domain.MainCategory.DEPT_INTRO;
import static kgu.developers.domain.about.domain.MainCategory.EDU_ACTIVITIES;
import static kgu.developers.domain.about.domain.SubCategory.CURRICULUM;
import static kgu.developers.domain.about.domain.SubCategory.HISTORY;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import kgu.developers.admin.about.application.AboutAdminFacade;
import kgu.developers.admin.about.presentation.request.AboutCreateRequest;
import kgu.developers.admin.about.presentation.request.AboutUpdateRequest;
import kgu.developers.admin.about.presentation.response.AboutPersistResponse;
import kgu.developers.domain.about.application.command.AboutCommandService;
import kgu.developers.domain.about.domain.About;
import kgu.developers.domain.about.domain.MainCategory;
import kgu.developers.domain.about.domain.SubCategory;
import kgu.developers.domain.about.exception.AboutNotFoundException;
import kgu.developers.domain.about.exception.CategoryNotMatchException;
import mock.repository.FakeAboutRepository;

public class AboutAdminFacadeTest {
private AboutAdminFacade aboutAdminFacade;
private FakeAboutRepository fakeAboutRepository;

@BeforeEach
public void init() {
fakeAboutRepository = new FakeAboutRepository();
aboutAdminFacade = new AboutAdminFacade(
new AboutCommandService(fakeAboutRepository)
);

fakeAboutRepository.save(About.builder()
.mainCategory(EDU_ACTIVITIES)
.subCategory(CURRICULUM)
.detailCategory("initDetail")
.content("initContent")
.build());
}

@Test
@DisplayName("createAbout은 about을 생성한다")
public void createAbout_Success() {
// given
MainCategory main = DEPT_INTRO;
SubCategory sub = HISTORY;
String detail = "detail";
String content = "content";

AboutCreateRequest request = AboutCreateRequest.builder()
.main(main)
.sub(sub)
.detail(detail)
.content(content)
.build();

// when
AboutPersistResponse result = aboutAdminFacade.createAbout(request);

// then
assertEquals(2L, result.id());
}

@Test
@DisplayName("createAbout은 메인 카테고리와 서브 카테고리의 관계가 올바르지 않은 생성 요청 시 CategoryNotMatchException을 발생시킨다")
public void createAbout_CategoryNotMatch_ThrowsException() {
// given
MainCategory main = DEPT_INTRO;
SubCategory sub = CURRICULUM;
String detail = "detail";
String content = "content";

AboutCreateRequest request = AboutCreateRequest.builder()
.main(main)
.sub(sub)
.detail(detail)
.content(content)
.build();

// when
// then
assertThatThrownBy(() -> aboutAdminFacade.createAbout(request))
.isInstanceOf(CategoryNotMatchException.class);
}

@Test
@DisplayName("updateAbout은 About의 content를 수정한다")
public void updateAbout_Success() {
// given
Long id = 1L;

AboutUpdateRequest request = AboutUpdateRequest.builder()
.content("updateContent")
.build();

// when
aboutAdminFacade.updateAbout(id, request);

// then
About about = fakeAboutRepository.findById(id).orElseThrow();
assertEquals(request.content(), about.getContent());
}

@Test
@DisplayName("updateAbout은 존재하지 않는 id로 수정 요청 시 AboutNotFoundException을 발생시킨다")
public void updateAbout_AboutNotFound_ThrowsException() {
// given
Long id = 0L;

AboutUpdateRequest request = AboutUpdateRequest.builder()
.content("updateContent")
.build();

// when
// then
assertThatThrownBy(() -> aboutAdminFacade.updateAbout(id, request))
.isInstanceOf(AboutNotFoundException.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package club.application;

import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import kgu.developers.admin.club.application.ClubAdminFacade;
import kgu.developers.admin.club.presentation.request.ClubRequest;
import kgu.developers.admin.club.presentation.response.ClubPersistResponse;
import kgu.developers.domain.club.application.command.ClubCommandService;
import kgu.developers.domain.club.application.query.ClubQueryService;
import kgu.developers.domain.club.domain.Club;
import kgu.developers.domain.club.exception.ClubNotFoundException;
import mock.repository.FakeClubRepository;

public class ClubAdminFacadeTest {
private ClubAdminFacade clubAdminFacade;
private FakeClubRepository fakeClubRepository;

@BeforeEach
public void init() {
this.fakeClubRepository = new FakeClubRepository();
this.clubAdminFacade = new ClubAdminFacade(
new ClubCommandService(fakeClubRepository),
new ClubQueryService(fakeClubRepository)
);

fakeClubRepository.save(
Club.create(
"C-Lab", "경기대학교 AI컴퓨터공학부 개발동아리입니다.", "https://www.clab.page"
)
);
}

@Test
@DisplayName("createClub은 Club을 생성한다")
void createClub_Success() {
// given
ClubRequest clubRequest = new ClubRequest(
"newClub",
"New Club Description",
"https://www.new-club.page"
);

// when
ClubPersistResponse result = clubAdminFacade.createClub(clubRequest);
List<Club> resultData = fakeClubRepository.findAll();

// then
assertEquals(2, resultData.size());
assertEquals(2L, result.id());
}

@Test
@DisplayName("updateClub은 Club을 수정한다")
void updateClub_Success() {
// given
ClubRequest clubRequest = new ClubRequest(
"newClub",
"New Club Description",
"https://www.new-club.page"
);

// when
clubAdminFacade.updateClub(1L, clubRequest);
Club saved = fakeClubRepository.findById(1L).get();

// then
assertEquals("newClub", saved.getName());
assertEquals("New Club Description", saved.getDescription());
assertEquals("https://www.new-club.page", saved.getSite());
}

@Test
@DisplayName("updateClub은 존재하지 않은 id을 수정하면 ClubNotFoundException을 발생시킨다")
void updateClub_throws_ClubNotFoundException() {
// given
ClubRequest clubRequest = new ClubRequest(
"newClub",
"New Club Description",
"https://www.new-club.page"
);

// when
// then
assertThatThrownBy(() -> clubAdminFacade.updateClub(2L, clubRequest))
.isInstanceOf(ClubNotFoundException.class);
}

@Test
@DisplayName("deleteClub은 Club을 삭제한다")
void deleteClub_Success() {
// when
clubAdminFacade.deleteClub(1L);

// then
List<Club> all = fakeClubRepository.findAll();
assertEquals(0, all.size());
}
}
Loading

0 comments on commit 38e9334

Please sign in to comment.