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

fix/#172 관리자 모듈 분리에 따른 테스트 코드 개선 #173

Merged
merged 84 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
1c5c3ae
fix: aics-admin 모듈에 testFixtures 관련 의존성 및 디렉토리 추가
LeeHanEum Jan 12, 2025
e88b43a
refactor: lab domain test 오타 수정
minjo-on Jan 13, 2025
d0d301d
feat: club domain test 작성
minjo-on Jan 13, 2025
c99c5bf
refactor: 회원가입 시 비밀번호 암호화 로직 수정
minjo-on Jan 13, 2025
20b8c88
refactor: comment Domain test 수정
minjo-on Jan 13, 2025
5d1317b
refactor: Post Domain test 수정
minjo-on Jan 13, 2025
133c8f1
refactor: FakeLabRepository 수정
minjo-on Jan 13, 2025
3274307
refactor: AboutFacade, AboutAdminFacade 수정
minjo-on Jan 13, 2025
2dd996c
refactor: AuthServiceTest 수정
minjo-on Jan 13, 2025
7cfb8ab
refactor: club facade test 작성
minjo-on Jan 13, 2025
2959718
Create FakeClubRepository.java
minjo-on Jan 13, 2025
eab248e
refactor: 다른 테스트를 위해 주석처리
minjo-on Jan 13, 2025
8594795
refactor: club command, query Service 구현
minjo-on Jan 13, 2025
94e10f0
refactor: club query service 누락된 메소드 테스트 추가
minjo-on Jan 13, 2025
d115420
feat: About command, query service test code 작성
minjo-on Jan 13, 2025
d5c6431
refactor: comment command, query service test 구현
minjo-on Jan 13, 2025
1e3756a
refactor: lab command, query service test 작성
minjo-on Jan 13, 2025
a5b164b
refactor: Post command, query service test 작성
minjo-on Jan 13, 2025
f2ae290
refactor: Professor command, query service test 작성
minjo-on Jan 13, 2025
3f78967
refactor: test container로 수정
minjo-on Jan 13, 2025
31917ea
feat: User command, query service test 작성
minjo-on Jan 13, 2025
f09341d
feat: ClubAdminFacadeTest 작성
LeeShinHaeng Jan 13, 2025
a4632c6
feat: UserAdminFacadeTest 작성
LeeShinHaeng Jan 13, 2025
bff695f
feat: PostAdminFacadeTest 작성
LeeShinHaeng Jan 13, 2025
15469ac
feat: jacoco.gradle 설정 변경
LeeShinHaeng Jan 14, 2025
7481275
refactor: clubFacadeTest 수정
minjo-on Jan 14, 2025
ac9fbf0
refactor: aboutFacadeTest 수정
minjo-on Jan 14, 2025
ce522c6
feat: file, lab, professor admin test 구조 설정
minjo-on Jan 14, 2025
89f078e
feat: ProfessorAdminFacadeTest 작성
minjo-on Jan 14, 2025
1285aa8
feat: labAdminFacadeTest 작성
minjo-on Jan 14, 2025
ddeb0e2
feat: jacoco.gradle 설정 변경
minjo-on Jan 14, 2025
769a558
refactor: jacoco 커버리지 limit 제거
LeeHanEum Jan 15, 2025
da16fce
refactor: 변경된 파일에 대한 최소 커버리지 기준 70%로 변경
LeeHanEum Jan 15, 2025
2d5a6a2
fix: UserDomainTest 컴파일 에러 픽스
LeeHanEum Jan 15, 2025
b9679c0
feat: LabFacadeTest 및 ProfessorFacadeTest 추가
LeeHanEum Jan 15, 2025
a200f50
feat: supplier를 사용한 TestContainer 구현
minjo-on Jan 15, 2025
18e6de1
refactor: about command, query service test 수정
minjo-on Jan 15, 2025
3c8757f
refactor: club command, query service test 수정
minjo-on Jan 15, 2025
d809bb5
refactor: comment command, query service test 수정
minjo-on Jan 15, 2025
ff13301
refactor: lab command, query service test 구현
minjo-on Jan 15, 2025
5d9b00c
refactor: post command, query service test 수정
minjo-on Jan 15, 2025
457f884
refactor: professor command, query service test 작성
minjo-on Jan 15, 2025
27761d8
refactor: user command, query
minjo-on Jan 15, 2025
a667347
refactor: 컨벤션 수정
minjo-on Jan 15, 2025
18feff5
refactor: 컨벤션 수정
minjo-on Jan 15, 2025
ba315d8
refactor: admin 모듈 test code 수정
minjo-on Jan 15, 2025
8750070
refactor: about facade test 수정
minjo-on Jan 15, 2025
739c8a5
refactor: authservice test 수정
minjo-on Jan 15, 2025
20f1c24
refactor: 구현되어 있는 api 모듈 testcode 수정
minjo-on Jan 15, 2025
c9e2cee
feat: comment, post facade testcode 작성
minjo-on Jan 15, 2025
8e93354
feat: user facade testcode 작성
minjo-on Jan 15, 2025
3a60a8a
refactor: labCommandService deleteLab testcode 작성
minjo-on Jan 15, 2025
3091f26
refactor: mock 패키지 repository 디렉토리 생성
minjo-on Jan 15, 2025
3b0ab20
refactor: 메서드 분리 및 builder 제거
LeeHanEum Jan 15, 2025
e74b29f
refactor: pageable response 검증 추가
minjo-on Jan 16, 2025
7ff6c72
refactor: 데이터 개수를 넘어선 페이지 요청시 빈값 검사 추가
minjo-on Jan 16, 2025
282d02f
refactor: 삭제 이전 null값 확인 추가
minjo-on Jan 16, 2025
f291153
refactor: 잘못된 람다식 수정
minjo-on Jan 16, 2025
748cb65
refactor: 잘못된 메소드명 수정 및 테스트 추가
minjo-on Jan 16, 2025
730e338
refactor: clubDomainTest 수정
minjo-on Jan 16, 2025
3278f08
refactor: 삭제된 게시물 제외하고 조회하는지 확인 추가
minjo-on Jan 16, 2025
ed5b9e3
refactor: 같은 카테고리의 게시글만 조회하는지 확인
minjo-on Jan 16, 2025
3bbea57
refactor: user domain test password 수정
minjo-on Jan 16, 2025
f4dcf97
refactor: 각 도메인 test 중복 코드 정리
minjo-on Jan 16, 2025
4ef0001
refactor: domain test 코드 수정
minjo-on Jan 16, 2025
3b0d7f1
refactor: domain test 코드 수정
minjo-on Jan 16, 2025
57bf2db
refactor: comment query service test 에러 수정
minjo-on Jan 16, 2025
4e959d4
refactor: userdomain testcode 수정
minjo-on Jan 16, 2025
2a415ad
feat: 코멘트 반영 API 테스트 커버리지 상승
LeeShinHaeng Jan 16, 2025
7db2e5d
refactor: FacadeTest DisplayName 일관성 수정
LeeShinHaeng Jan 16, 2025
28f22da
refactor: 람다식 적용
LeeShinHaeng Jan 16, 2025
9f09902
refactor: 순서 적용 및 람다식 추가 적용
LeeShinHaeng Jan 16, 2025
13dcd0f
refactor: userQueryService testcode 추가
minjo-on Jan 17, 2025
f1ab7f3
refactor: aboutCommandService testcode 추가
minjo-on Jan 17, 2025
bc41e69
refactor: UserCommandService testcode 추가
minjo-on Jan 17, 2025
bc0a046
refactor: clubCommandService testcode 추가
minjo-on Jan 17, 2025
799b0fb
refactor: professorQueryServiceTest 추가 작성
minjo-on Jan 17, 2025
536f5c2
refactor: deletedAt 검증 추가
minjo-on Jan 17, 2025
0623ba0
refactor: commentQueryService getById 수정
minjo-on Jan 17, 2025
0e016b1
refactor: post getbyid 쿼리 수정
minjo-on Jan 17, 2025
6f144ea
refactor: 에러 수정
minjo-on Jan 17, 2025
00c16b6
refactor: user domain test 추가
minjo-on Jan 17, 2025
7d9d3cb
refactor: userDomain test code 추가
minjo-on Jan 17, 2025
e721544
refactor: 메서드 분리 및 검증 구체화
LeeHanEum Jan 17, 2025
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
8 changes: 4 additions & 4 deletions .github/workflows/pull-request-test-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
17 changes: 17 additions & 0 deletions aics-admin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Loading