Skip to content

Conversation

@leegwichan
Copy link
Member

@leegwichan leegwichan commented Jul 26, 2025

✨ 개요

  • 테스트 시 순차적으로 생성되지만, 간혹 같은 시각에 생성되는 객체가 존재하여 테스트가 실패함
  • createdAt을 Reflextion으로 지정하여 생성 시각을 지정하도록 함

🧾 관련 이슈

없음

🔍 참고 사항 (선택)

Summary by CodeRabbit

  • 버그 수정

    • 생성 일시(createdAt)가 이미 설정된 경우, 기존 값을 보존하도록 개선되어 불필요하게 덮어쓰지 않도록 수정되었습니다.
  • 테스트

    • 테스트 데이터(가게, 응원, 아티클 등)에 명시적인 생성 일시를 부여하여, 시간 순서에 따른 정렬 및 반환 결과를 더 명확하게 검증합니다.
    • 테스트용 유틸리티와 생성기(Generator)에 생성 일시를 지정할 수 있는 기능이 추가되었습니다.
    • 새로운 테스트 유틸리티 클래스가 도입되어 테스트 엔티티의 생성 일시를 손쉽게 설정할 수 있습니다.

@coderabbitai
Copy link

coderabbitai bot commented Jul 26, 2025

"""

Walkthrough

createdAt 타임스탬프를 명시적으로 설정할 수 있도록 테스트 픽스처와 테스트 코드가 전반적으로 개선되었습니다. 이를 위해 유틸리티 클래스가 추가되고, 엔티티 생성 시 타임스탬프를 지정하는 기능이 도입되었습니다. 또한, 엔티티의 생성 시점 로직이 조건적으로 변경되었습니다.

Changes

파일/경로 요약 변경 내용 요약
src/main/java/eatda/domain/AuditingEntity.java createdAt이 null일 때만 현재 시각으로 할당하도록 onCreate 메서드 수정
src/test/java/eatda/util/DomainUtils.java createdAt을 리플렉션으로 설정하는 static 유틸리티 클래스 및 메서드 추가
src/test/java/eatda/fixture/CheerGenerator.java generateAdmin 메서드에 createdAt 파라미터 추가, 생성된 Cheer의 타임스탬프 명시적 설정
src/test/java/eatda/fixture/StoreGenerator.java createdAt을 지정할 수 있는 generate 오버로드 메서드 추가
src/test/java/eatda/fixture/ArticleGenerator.java generate 메서드에 createdAt 파라미터를 받는 오버로드 메서드 추가
src/test/java/eatda/controller/store/CheerControllerTest.java
src/test/java/eatda/service/store/CheerServiceTest.java
Cheer 생성 시 명시적 타임스탬프 사용, 테스트 내 시간 순서 제어
src/test/java/eatda/controller/store/StoreControllerTest.java
src/test/java/eatda/service/store/StoreServiceTest.java
Store 생성 시 명시적 타임스탬프 사용, 테스트 내 시간 순서 제어
src/test/java/eatda/controller/article/ArticleControllerTest.java
src/test/java/eatda/service/article/ArticleServiceTest.java
Article 생성 시 명시적 타임스탬프 사용, 테스트 내 시간 순서 제어

Sequence Diagram(s)

sequenceDiagram
    participant 테스트코드
    participant Generator
    participant DomainUtils
    participant Entity

    테스트코드->>Generator: Store/Cheer/Article 생성 요청 (createdAt 전달)
    Generator->>Entity: 엔티티 생성
    Generator->>DomainUtils: setCreatedAt(Entity, createdAt)
    DomainUtils->>Entity: createdAt 필드 리플렉션 설정
    Generator->>테스트코드: 엔티티 반환
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Poem

🐰
시간의 발자국을 남기는 법,
이제는 내가 정해줄 수 있지!
리플렉션으로 톡톡, createdAt을 콕콕—
테스트의 질서가 반짝반짝,
토끼도 기뻐 깡총깡총!

🎉✨
"""

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/domain-utils

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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.

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
Member

@lvalentine6 lvalentine6 left a comment

Choose a reason for hiding this comment

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

이번 PR도 고생하셨습니다! 🌮
기존 테스트가 어긋나는 지점들이 잘 방어되겠군요

private DomainUtils() {
}

public static <T extends AuditingEntity> void setCreatedAt(T entity, LocalDateTime createdAt) {
Copy link
Member

Choose a reason for hiding this comment

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

지네릭 좋군요 👍🏻

@leegwichan leegwichan merged commit f062817 into develop Jul 28, 2025
2 of 3 checks passed
@leegwichan leegwichan deleted the test/domain-utils branch July 28, 2025 11:28
@sonarqubecloud
Copy link

Copy link

@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: 0

🧹 Nitpick comments (1)
src/test/java/eatda/fixture/ArticleGenerator.java (1)

32-36: 타임스탬프 설정 기능이 잘 구현됨

기존 로직을 재사용하여 DRY 원칙을 준수하고 있습니다. DomainUtils를 통한 리플렉션 기반 타임스탬프 설정도 적절합니다.

참고로, 현재 구현에서는 article이 두 번 저장됩니다(첫 번째는 generate 메서드에서, 두 번째는 타임스탬프 설정 후). 테스트 코드이므로 성능상 큰 문제는 없지만, 향후 최적화를 고려해볼 수 있습니다.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4fe587e and 684fecd.

📒 Files selected for processing (3)
  • src/test/java/eatda/controller/article/ArticleControllerTest.java (2 hunks)
  • src/test/java/eatda/fixture/ArticleGenerator.java (2 hunks)
  • src/test/java/eatda/service/article/ArticleServiceTest.java (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: lvalentine6
PR: YAPP-Github/26th-Web-Team-1-BE#76
File: src/main/java/eatda/domain/store/Cheer.java:50-61
Timestamp: 2025-07-15T09:42:54.091Z
Learning: Cheer 엔티티의 생성자는 데이터베이스 시딩을 위해 의도적으로 ID 매개변수를 받도록 설계되었습니다. 시드 데이터에서 명시적으로 ID를 설정하기 때문에 이 패턴이 필요합니다.
🧬 Code Graph Analysis (1)
src/test/java/eatda/fixture/ArticleGenerator.java (1)
src/test/java/eatda/util/DomainUtils.java (1)
  • DomainUtils (7-21)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (5)
src/test/java/eatda/controller/article/ArticleControllerTest.java (2)

6-6: LGTM! 타임스탬프 기능을 위한 필수 import 추가

LocalDateTime import가 올바르게 추가되었습니다.


17-19: 타임스탬프 명시적 설정으로 테스트 안정성 향상

명시적인 생성 시각 설정으로 테스트의 일관성과 안정성이 크게 개선되었습니다. 1시간 간격으로 설정하여 타임스탬프 충돌을 효과적으로 방지하고 있습니다.

src/test/java/eatda/fixture/ArticleGenerator.java (1)

6-7: 필요한 import 추가가 올바르게 구현됨

DomainUtils와 LocalDateTime import가 새로운 타임스탬프 기능을 위해 적절히 추가되었습니다.

src/test/java/eatda/service/article/ArticleServiceTest.java (2)

7-7: LGTM! 타임스탬프 기능을 위한 필수 import

LocalDateTime import가 올바르게 추가되었습니다.


22-27: 타임스탬프 기반 정렬 테스트가 체계적으로 구현됨

5개의 아티클을 1시간 간격으로 생성하여 최신순 정렬을 확실하게 테스트할 수 있도록 구현되었습니다. 명시적 타임스탬프 설정으로 테스트의 신뢰성이 크게 향상되었습니다.

@github-actions
Copy link

🎉 This PR is included in version 1.4.0-develop.31 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This PR is included in version 1.5.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants