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/#127 about domain, service testcode 구현 #128

Merged
merged 7 commits into from
Dec 8, 2024

Conversation

minjo-on
Copy link
Contributor

@minjo-on minjo-on commented Dec 5, 2024

Summary

close #127

Tasks

  • AboutDomainTest 구현
  • AboutServiceTest 구현
  • FakeAboutRepository 구현
  • 수정 요정 객체 AboutRequest -> AboutUpdateRequest 수정
  • 카테고리 체크 메소드 최적화

To Reviewer

    1. categoryMatchCheck 메서드 수정
      기존 코드의 불필요한 return을 제거하고 조건문을 간결하게 변경하여 가독성과 명확성을 높였습니다. 조건이 맞지 않을 경우 바로 예외를 던지는 구조로 개선하였습니다.
    1. updateAbout 메서드 수정
      수정 작업에는 content 필드만 필요하므로, 불필요한 데이터를 포함한 AboutRequest 대신 AboutUpdateRequest를 사용하도록 변경하였습니다. 또한, 생성(createAbout)과 수정(updateAbout)의 목적에 따라 요청 객체를 분리하여, 필요한 데이터만 포함하도록 설계함으로써 API의 명확성을 높이고 유지보수성을 강화했습니다.

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

coderabbitai bot commented Dec 5, 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

이 변경 사항은 AboutServiceAboutController 클래스에서 updateAbout 메서드의 요청 본문 매개변수 타입을 AboutRequest에서 AboutUpdateRequest로 변경하는 것을 포함합니다. 또한, categoryMatchCheck 메서드의 제어 흐름이 개선되었으며, 새로운 AboutUpdateRequest 클래스가 추가되었습니다. 이와 함께 AboutRequest 클래스에는 Lombok의 @Builder 주석이 추가되어 인스턴스 생성을 용이하게 합니다. 테스트 파일도 추가되어 기능 검증이 강화되었습니다.

Changes

파일 경로 변경 요약
aics-api/src/main/java/kgu/developers/api/about/application/AboutService.java updateAbout 메서드의 매개변수 타입을 AboutUpdateRequest로 변경하고 불필요한 import 제거. categoryMatchCheck 메서드의 제어 흐름 수정.
aics-api/src/main/java/kgu/developers/api/about/presentation/AboutController.java updateAbout 메서드의 요청 본문 매개변수 타입을 AboutUpdateRequest로 변경하고 여러 import 추가.
aics-api/src/main/java/kgu/developers/api/about/presentation/request/AboutRequest.java AboutRequest 클래스에 Lombok의 @Builder 주석 추가.
aics-api/src/main/java/kgu/developers/api/about/presentation/request/AboutUpdateRequest.java 새로운 AboutUpdateRequest 레코드 클래스 추가, content 필드 포함.
aics-api/src/testFixtures/java/about/application/AboutServiceTest.java AboutService 클래스에 대한 단위 테스트 추가.
aics-domain/src/testFixtures/java/about/application/AboutServiceTest.java 빈 클래스 AboutServiceTest 추가.
aics-domain/src/testFixtures/java/about/domain/AboutDomainTest.java About 클래스에 대한 단위 테스트 추가. createAbout_SuccessupdateContent_Success 메서드 포함.
aics-domain/src/testFixtures/java/mock/FakeAboutRepository.java AboutRepository 인터페이스를 구현하는 FakeAboutRepository 클래스 추가.

Assessment against linked issues

Objective Addressed Explanation
AboutServiceTest 작성 (#127) AboutServiceTest 클래스가 추가되었으나, 구현 내용이 없음.
AboutDomainTest 작성 (#127) AboutDomainTest 클래스가 작성되어 기능 검증이 이루어짐.

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: 2

🧹 Outside diff range and nitpick comments (9)
aics-domain/src/testFixtures/java/about/domain/AboutDomainTest.java (3)

14-32: 테스트 케이스 보완이 필요합니다.

createAbout_Success 테스트는 기본적인 생성 케이스만 다루고 있습니다. 다음과 같은 추가 테스트 케이스를 고려해 보시기 바랍니다:

  1. 필수 필드가 null인 경우
  2. detailCategory가 null인 경우의 정상 동작
  3. 유효하지 않은 카테고리 조합

테스트 케이스 예시:

@Test
@DisplayName("필수 필드가 null일 경우 예외가 발생한다")
void createAbout_WithNullRequiredFields() {
    assertThrows(IllegalArgumentException.class, () -> 
        About.create(null, HISTORY, "test", "content"));
}

34-49: 테스트 메소드 명명 규칙 개선이 필요합니다.

현재 테스트 메소드 이름이 updateContent_Success로 되어 있는데, 더 명확한 의미 전달을 위해 shouldUpdateContentSuccessfully와 같은 형태로 변경하는 것을 추천드립니다.

또한 다음과 같은 실패 케이스도 테스트에 포함하면 좋을 것 같습니다:

  1. null content로 업데이트 시도
  2. 빈 문자열로 업데이트 시도

1-50: 테스트 데이터 관리 개선이 필요합니다.

테스트 클래스 전반에 걸쳐 테스트 데이터가 하드코딩되어 있습니다. TestFixture나 @beforeeach를 활용하여 테스트 데이터를 중앙 집중화하면 유지보수가 더 용이할 것 같습니다.

예시:

class AboutDomainTest {
    private MainCategory mainCategory;
    private SubCategory subCategory;
    private String detailCategory;
    private String content;

    @BeforeEach
    void setUp() {
        mainCategory = DEPT_INTRO;
        subCategory = HISTORY;
        detailCategory = "test";
        content = "testContent";
    }
    // ... 테스트 메소드들
}
aics-domain/src/testFixtures/java/mock/FakeAboutRepository.java (1)

16-17: 동시성 처리 개선 제안

Collections.synchronizedListAtomicLong을 사용한 동시성 처리는 좋은 접근이지만, 더 나은 성능을 위해 ConcurrentHashMap을 고려해 보세요.

-private final List<About> data = Collections.synchronizedList(new ArrayList<>());
+private final Map<Long, About> data = new ConcurrentHashMap<>();
aics-api/src/main/java/kgu/developers/api/about/application/AboutService.java (2)

Line range hint 34-39: 카테고리 매핑 개선 제안

카테고리 매핑을 별도의 설정 파일이나 enum 내부로 이동하는 것을 고려해 보세요. 현재 구현은 유지보수가 어려울 수 있습니다.


Line range hint 54-54: System.out.println 제거 필요

프로덕션 코드에서 System.out.println을 제거하고 적절한 로깅 프레임워크를 사용하세요.

-System.out.println(detail);
+log.debug("Detail parameter: {}", detail);
aics-api/src/main/java/kgu/developers/api/about/presentation/AboutController.java (1)

Line range hint 32-33: API 버전 관리 전략 검토 필요

URL에 버전을 하드코딩하는 대신 헤더 기반 버전 관리를 고려해 보세요.

aics-api/src/testFixtures/java/about/application/AboutServiceTest.java (2)

28-39: 테스트 데이터 상수화 제안

테스트의 가독성과 유지보수성을 높이기 위해 초기 테스트 데이터를 상수로 정의하는 것이 좋습니다.

다음과 같이 개선해보세요:

 public class AboutServiceTest {
+    private static final String INIT_DETAIL = "initDetail";
+    private static final String INIT_CONTENT = "initContent";
     private AboutService aboutService;

     @BeforeEach
     public void init() {
         FakeAboutRepository fakeAboutRepository = new FakeAboutRepository();
         this.aboutService = new AboutService(fakeAboutRepository);

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

105-122: updateAbout 테스트의 검증 강화 필요

현재 테스트는 content 업데이트만 확인하고 있습니다. 다른 필드들이 변경되지 않았는지도 검증이 필요합니다.

다음과 같이 검증을 강화해보세요:

     // then
     AboutResponse response = aboutService.getAbout(EDU_ACTIVITIES, CURRICULUM, "initDetail");

     assertEquals(response.content(), "updateContent");
+    assertEquals(response.mainCategory(), EDU_ACTIVITIES);
+    assertEquals(response.subCategory(), CURRICULUM);
+    assertEquals(response.detailCategory(), "initDetail");
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 722083a and 3fd38e4.

📒 Files selected for processing (8)
  • aics-api/src/main/java/kgu/developers/api/about/application/AboutService.java (2 hunks)
  • aics-api/src/main/java/kgu/developers/api/about/presentation/AboutController.java (3 hunks)
  • aics-api/src/main/java/kgu/developers/api/about/presentation/request/AboutRequest.java (1 hunks)
  • aics-api/src/main/java/kgu/developers/api/about/presentation/request/AboutUpdateRequest.java (1 hunks)
  • aics-api/src/testFixtures/java/about/application/AboutServiceTest.java (1 hunks)
  • aics-domain/src/testFixtures/java/about/application/AboutServiceTest.java (1 hunks)
  • aics-domain/src/testFixtures/java/about/domain/AboutDomainTest.java (1 hunks)
  • aics-domain/src/testFixtures/java/mock/FakeAboutRepository.java (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • aics-domain/src/testFixtures/java/about/application/AboutServiceTest.java
🔇 Additional comments (6)
aics-api/src/main/java/kgu/developers/api/about/presentation/request/AboutUpdateRequest.java (1)

9-14: 구조가 잘 설계되었습니다!

레코드 클래스의 구조가 명확하고 간단하며, 필요한 유효성 검사와 문서화가 잘 되어 있습니다. Builder 패턴의 사용도 적절합니다.

aics-api/src/main/java/kgu/developers/api/about/presentation/request/AboutRequest.java (1)

10-12: 필드 사용 여부 검토가 필요합니다.

AboutUpdateRequest가 도입됨에 따라 AboutRequest의 일부 필드들이 여전히 필요한지 검토가 필요합니다. 특히 content 필드가 두 클래스에 중복되어 있는 것으로 보입니다.

aics-domain/src/testFixtures/java/mock/FakeAboutRepository.java (2)

35-42: 조회 메서드 구현이 잘 되었습니다

리포지토리 조회 메서드들이 스트림 API를 적절히 활용하여 깔끔하게 구현되었습니다.

Also applies to: 44-50, 52-57


29-29: TestEntityUtils 사용 검증 필요

TestEntityUtils.setCreatedAt() 메서드의 구현을 확인하고 테스트해야 합니다.

✅ Verification successful

TestEntityUtils.setCreatedAt() 메서드 검증 완료

TestEntityUtils.setCreatedAt() 메서드는 다음과 같이 안전하게 구현되어 있습니다:

  • null 체크를 통한 유효성 검사
  • 리플렉션을 사용한 BaseTimeEntity의 createdAt 필드 설정
  • 적절한 예외 처리
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# TestEntityUtils 구현 확인
rg -l "class TestEntityUtils" 

Length of output: 91


Script:

#!/bin/bash
# TestEntityUtils.setCreatedAt() 메서드 구현 확인
rg -A 10 "setCreatedAt" aics-domain/src/testFixtures/java/mock/TestEntityUtils.java

Length of output: 566

aics-api/src/main/java/kgu/developers/api/about/application/AboutService.java (1)

71-76: 예외 처리 개선 필요

updateContent 메서드 호출 시 발생할 수 있는 예외에 대한 처리가 필요합니다.

aics-api/src/main/java/kgu/developers/api/about/presentation/AboutController.java (1)

Line range hint 73-78: 업데이트 API 구현이 깔끔합니다

AboutUpdateRequest를 사용한 업데이트 구현이 명확하고 간단합니다. 응답 상태 코드도 적절히 사용되었습니다.

Copy link
Contributor

@LeeShinHaeng LeeShinHaeng left a comment

Choose a reason for hiding this comment

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

LGTM 👍

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.

리뷰어로 등록이 되어있지 않아서 확인이 늦었습니다!
기존의 미흡했던 API 개선 해주셔서 감사해요 👍

@minjo-on minjo-on merged commit 51e932f into develop Dec 8, 2024
2 checks passed
@minjo-on minjo-on deleted the feature/#127-about-testcode branch December 8, 2024 10:45
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.

About 소개글 TestCode 작성
3 participants