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

feature/#122 연구실 테스트 코드 작성 #124

Merged
merged 8 commits into from
Dec 3, 2024

Conversation

LeeShinHaeng
Copy link
Contributor

Summary

close #122

testFixtures 기반 연구실 테스트 코드 작성

Tasks

  • LabDomainTest 구현
  • LabServiceTest 구현
  • 여타 테스트 클래스 생성
  • LabService createLab 메서드 아이디 반환 부분 수정

@LeeShinHaeng LeeShinHaeng added the ✨feature create new feature label Dec 3, 2024
@LeeShinHaeng LeeShinHaeng requested a review from a team December 3, 2024 04:34
@LeeShinHaeng LeeShinHaeng self-assigned this Dec 3, 2024
@LeeShinHaeng LeeShinHaeng linked an issue Dec 3, 2024 that may be closed by this pull request
2 tasks
Copy link
Contributor

coderabbitai bot commented Dec 3, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

이 풀 리퀘스트에서는 LabService 클래스의 createLab 메소드가 수정되었습니다. 새로운 변수 createLab이 도입되어 labRepository.save(lab)의 결과를 저장하고, 반환 문에서는 lab.getId() 대신 createLab.getId()를 사용합니다. LabRequest 클래스에는 Lombok의 @Builder 주석이 추가되어 인스턴스 생성을 위한 빌더 패턴을 지원합니다. 또한, LabService와 관련된 단위 테스트가 포함된 새로운 테스트 파일들이 추가되었습니다.

Changes

파일 경로 변경 요약
aics-api/src/main/java/kgu/developers/api/lab/application/LabService.java createLab 메소드에서 lab 대신 createLab을 사용하여 반환 문 수정.
aics-api/src/main/java/kgu/developers/api/lab/presentation/request/LabRequest.java LabRequest 클래스에 Lombok의 @Builder 주석 추가.
aics-api/src/testFixtures/java/lab/application/LabServiceTest.java LabService에 대한 단위 테스트 추가.
aics-api/src/testFixtures/java/lab/presentation/LabControllerTest.java 빈 클래스 LabControllerTest 추가.
aics-domain/src/testFixtures/java/lab/application/LabServiceTest.java 빈 클래스 LabServiceTest 추가.
aics-domain/src/testFixtures/java/lab/domain/LabDomainTest.java Lab 클래스에 대한 단위 테스트 추가.
aics-domain/src/testFixtures/java/mock/FakeLabRepository.java LabRepository 인터페이스를 구현하는 FakeLabRepository 추가.

Assessment against linked issues

Objective Addressed Explanation
LabDomainTest 작성 (#122)
LabServiceTest 작성 (#122)

Possibly related PRs

Suggested reviewers

  • LeeHanEum

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (6)
aics-api/src/main/java/kgu/developers/api/lab/application/LabService.java (1)

24-26: 변수명 개선이 필요합니다.

createLab이라는 변수명은 메서드명과 유사하여 혼란을 줄 수 있습니다. 저장된 엔티티임을 더 명확히 표현하는 것이 좋겠습니다.

다음과 같이 변경을 제안드립니다:

-		Lab createLab = labRepository.save(lab);
-		return LabPersistResponse.of(createLab.getId());
+		Lab savedLab = labRepository.save(lab);
+		return LabPersistResponse.of(savedLab.getId());
aics-domain/src/testFixtures/java/mock/FakeLabRepository.java (1)

19-26: 유효성 검증 메시지를 더 구체적으로 개선해주세요.

현재 예외 메시지가 다소 일반적입니다. 각 필드별로 구체적인 검증 메시지를 제공하면 테스트 실패 시 원인 파악이 더 용이할 것 같습니다.

다음과 같이 개선을 제안드립니다:

-		if (lab.getName() == null
-			|| lab.getLoc() == null
-			|| lab.getSite() == null) {
-			throw new IllegalArgumentException("이름, 위치, 사이트는 필수 입력값입니다.");
+		if (lab.getName() == null) {
+			throw new IllegalArgumentException("연구실 이름은 필수 입력값입니다.");
+		}
+		if (lab.getLoc() == null) {
+			throw new IllegalArgumentException("연구실 위치는 필수 입력값입니다.");
+		}
+		if (lab.getSite() == null) {
+			throw new IllegalArgumentException("연구실 사이트는 필수 입력값입니다.");
aics-domain/src/testFixtures/java/lab/domain/LabDomainTest.java (2)

11-27: 테스트 케이스 보완이 필요합니다

현재 테스트는 기본적인 성공 케이스만 다루고 있습니다. 다음과 같은 케이스들을 추가하면 좋을 것 같습니다:

  • 잘못된 입력값 (빈 문자열, null 등)에 대한 검증
  • 실제 연구실 데이터와 유사한 테스트 데이터 사용

31-31: 오타를 수정해 주세요

DisplayName의 "얀구실명"을 "연구실명"으로 수정해 주세요.

aics-api/src/testFixtures/java/lab/application/LabServiceTest.java (2)

21-42: 테스트 데이터를 상수로 분리하면 좋을 것 같습니다

테스트에서 사용되는 문자열 값들을 클래스 상수로 분리하면 유지보수성이 향상될 것 같습니다.

예시:

 public class LabServiceTest {
+    private static final String LAB_A_NAME = "Lab A";
+    private static final String LAB_A_LOC = "8500";
+    private static final String LAB_A_SITE = "http://lab1.kyonggi.ac.kr";
+    private static final String LAB_B_NAME = "Lab B";
+    private static final String LAB_B_LOC = "8520";
+    private static final String LAB_B_SITE = "https://lab2.kyonggi.ac.kr";

90-112: 정렬 의존성을 명시적으로 테스트해 주세요

현재 테스트는 이름순 정렬에 의존하고 있습니다. 정렬 로직이 변경될 경우 테스트가 실패할 수 있으므로, 정렬과 무관하게 특정 Lab을 찾아서 검증하는 것이 좋을 것 같습니다.

-//then - 이름순이기 때문에 순서까지 바뀌어서 리턴
-assertEquals(newName, contents.get(1).name());
-assertEquals(newLoc, contents.get(1).loc());
-assertEquals(newSite, contents.get(1).site());
+//then
+LabDetailResponse updatedLab = contents.stream()
+    .filter(lab -> lab.name().equals(newName))
+    .findFirst()
+    .orElseThrow();
+assertEquals(newLoc, updatedLab.loc());
+assertEquals(newSite, updatedLab.site());
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ffac8eb and c37c2da.

📒 Files selected for processing (7)
  • aics-api/src/main/java/kgu/developers/api/lab/application/LabService.java (1 hunks)
  • aics-api/src/main/java/kgu/developers/api/lab/presentation/request/LabRequest.java (1 hunks)
  • aics-api/src/testFixtures/java/lab/application/LabServiceTest.java (1 hunks)
  • aics-api/src/testFixtures/java/lab/presentation/LabControllerTest.java (1 hunks)
  • aics-domain/src/testFixtures/java/lab/application/LabServiceTest.java (1 hunks)
  • aics-domain/src/testFixtures/java/lab/domain/LabDomainTest.java (1 hunks)
  • aics-domain/src/testFixtures/java/mock/FakeLabRepository.java (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • aics-domain/src/testFixtures/java/lab/application/LabServiceTest.java
  • aics-api/src/testFixtures/java/lab/presentation/LabControllerTest.java
🔇 Additional comments (2)
aics-api/src/main/java/kgu/developers/api/lab/presentation/request/LabRequest.java (1)

9-11: 빌더 패턴 적용이 적절합니다!

테스트 코드 작성을 위한 @Builder 어노테이션 추가가 적절합니다. 이를 통해 테스트 픽스처 생성이 더욱 용이해질 것입니다.

aics-api/src/testFixtures/java/lab/application/LabServiceTest.java (1)

114-127: 테스트가 잘 작성되었습니다

삭제 후 컬렉션의 크기와 남은 항목을 모두 검증하고 있어 완성도가 높습니다.

Copy link
Member

@LeeHanEum LeeHanEum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

깔끔한 테코 감사합니다 👍
한가지 코멘트만 검토 부탁드려요~

Copy link
Member

@LeeHanEum LeeHanEum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM👍

@LeeShinHaeng LeeShinHaeng merged commit 6530567 into develop Dec 3, 2024
2 checks passed
@LeeShinHaeng LeeShinHaeng deleted the feature/#122-lab-test-code branch December 3, 2024 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨feature create new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lab 연구실 TestCode 작성
2 participants