Skip to content

Test: [BADA-208] 사용자 테스트 코드 작성#390

Merged
choyunju merged 1 commit intodevelopfrom
test/BADA-208-test-user
Aug 5, 2025
Merged

Test: [BADA-208] 사용자 테스트 코드 작성#390
choyunju merged 1 commit intodevelopfrom
test/BADA-208-test-user

Conversation

@choyunju
Copy link
Copy Markdown
Contributor

@choyunju choyunju commented Aug 5, 2025

#️⃣연관된 이슈

close: #199

🚀 작업 내용

  • 사용자 데이터량과 코인을 가져오는 테스트 코드입니다.

🔍 리뷰 요청 사항

@choyunju choyunju added this to the 👤 사용자 milestone Aug 5, 2025
@choyunju choyunju self-assigned this Aug 5, 2025
@choyunju choyunju added the ✅ Test test 관련(storybook, jest...) label Aug 5, 2025
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Aug 5, 2025

Failed to generate code suggestions for PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Aug 5, 2025

Walkthrough

이 변경사항은 com.TwoSeaU.BaData.domain.user.service 패키지 내의 UserService 클래스를 검증하는 새로운 테스트 클래스 UserServiceTest를 추가합니다. JUnit 5와 Mockito를 사용하여 UserRepository, PlanDataRepository, SosRepository, ReportRepository 등의 의존성을 모킹하고, getDatagetCoin 메서드의 정상 동작과 예외 상황을 각각 테스트합니다. 테스트 클래스는 중첩 클래스를 사용해 각 메서드별로 테스트를 분리하며, 예외 발생 시 적절한 예외와 HTTP 상태 코드가 반환되는지 확인합니다. 또한, 테스트용 엔티티 생성을 위한 헬퍼 메서드도 포함되어 있습니다.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

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/BADA-208-test-user

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.
  • 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.

Support

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

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.

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
Copy Markdown

@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/com/TwoSeaU/BaData/domain/user/service/UserServiceTest.java (1)

160-194: 헬퍼 메서드들이 현재 사용되지 않고 있습니다.

createTestUsercreateTestGifticon 메서드가 정의되어 있지만 현재 테스트에서 사용되지 않고 있습니다. 향후 확장을 위해 남겨둔 것으로 보이지만, 사용하지 않는 코드는 제거하는 것을 고려해보세요.

사용하지 않는 헬퍼 메서드들을 제거하려면:

-	private User createTestUser() {
-		return User.of(
-			"testNickName",
-			"testUser",
-			"encodedPassword",
-			100,
-			50,
-			Role.GENERAL,
-			SocialType.KAKAO,
-			"test@example.com",
-			"profileImageUrl",
-			PlanData.of("기본 요금제", 1000)
-		);
-	}
-
-	private Gifticon createTestGifticon(User user) {
-		GifticonCategory gifticonCategory = GifticonCategory.of("CAFE");
-
-		Gifticon gifticon = new Gifticon(
-			user,
-			"title",
-			"comment",
-			BigDecimal.valueOf(10000),
-			LocalDate.now().plusDays(10),
-			"http://image.url",
-			false,
-			"couponNumber",
-			"partner",
-			gifticonCategory,
-			null
-		);
-
-		return gifticon;
-	}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c44d11 and 0124a1a.

📒 Files selected for processing (1)
  • src/test/java/com/TwoSeaU/BaData/domain/user/service/UserServiceTest.java (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: dionisos198
PR: Ureca-Final-Project-Team2/be_badata#388
File: src/main/java/com/TwoSeaU/BaData/domain/rental/service/RestockDeleteTargetingService.java:37-60
Timestamp: 2025-08-05T05:48:10.418Z
Learning: dionisos198는 be_badata 프로젝트에서 PR의 주요 목적에 집중하기 위해 성능 최적화 이슈를 추후 수정으로 미루는 접근 방식을 선호한다. N+1 쿼리 최적화와 같은 성능 개선 사항은 별도 작업으로 분리하여 처리한다.
Learnt from: dionisos198
PR: Ureca-Final-Project-Team2/be_badata#366
File: src/main/java/com/TwoSeaU/BaData/global/fcm/FCMService.java:127-165
Timestamp: 2025-08-03T14:38:19.797Z
Learning: dionisos198는 be_badata 프로젝트에서 곧 삭제될 예정인 테스트 코드의 경우, 코드 중복이나 최적화보다는 개발 효율성을 우선시한다. 임시 코드에 대해서는 리팩토링을 고려하지 않는 것을 선호한다.
Learnt from: choyunju
PR: Ureca-Final-Project-Team2/be_badata#286
File: src/main/java/com/TwoSeaU/BaData/domain/user/service/UserService.java:0-0
Timestamp: 2025-07-28T16:46:37.983Z
Learning: choyunju의 애플리케이션에서는 User 객체 생성 시 PlanData를 무조건 함께 저장하는 설계를 사용한다. 따라서 비즈니스 로직상 user.getPlanData()가 null일 가능성이 없지만, 방어적 프로그래밍을 위해 null 체크를 추가하는 것을 선호한다.
Learnt from: dionisos198
PR: Ureca-Final-Project-Team2/be_badata#291
File: src/main/java/com/TwoSeaU/BaData/domain/user/entity/User.java:92-94
Timestamp: 2025-07-29T01:57:02.534Z
Learning: User 엔티티의 addCoin 메서드는 리뷰 작성 시 한 사람에게만 적용되는 단일 사용자 환경에서 사용되므로 멀티스레드 동시성 처리가 필요하지 않다.
Learnt from: dionisos198
PR: Ureca-Final-Project-Team2/be_badata#144
File: src/main/java/com/TwoSeaU/BaData/domain/rental/dto/response/ShowReviewResponse.java:34-34
Timestamp: 2025-07-18T05:16:04.655Z
Learning: Review-Reservation 간 1:1 관계에서 외래키 제약조건은 데이터 무결성을 보장하지만, JPA 지연 로딩으로 인한 LazyInitializationException 방지를 위해서는 연관된 User 엔티티도 함께 fetch해야 한다. NPE 체크보다는 쿼리 개선이 더 나은 해결책이다.
Learnt from: dionisos198
PR: Ureca-Final-Project-Team2/be_badata#275
File: src/test/java/com/TwoSeaU/BaData/domain/common/TestSecurityConfig.java:37-38
Timestamp: 2025-07-28T06:29:06.044Z
Learning: dionisos198는 TestSecurityConfig에서 exceptionHandling 설정을 분리해서 유지하는 것을 선호한다. 이는 메인 Security 설정의 형식과 일관성을 유지하기 위함이다.
Learnt from: choyunju
PR: Ureca-Final-Project-Team2/be_badata#132
File: src/main/java/com/TwoSeaU/BaData/domain/user/dto/response/GetFollowsResponse.java:25-25
Timestamp: 2025-07-17T13:03:43.601Z
Learning: choyunju prefers intuitive field naming in DTOs - even if the API response could use generic names like "username", they prefer to use descriptive field names like "nickname" that clearly indicate the actual data being returned for better code clarity and maintainability.
Learnt from: choyunju
PR: Ureca-Final-Project-Team2/be_badata#267
File: src/main/java/com/TwoSeaU/BaData/domain/user/controller/UserController.java:151-154
Timestamp: 2025-07-28T01:13:39.883Z
Learning: choyunju는 프론트엔드에서 토글 형식으로 구현된 Boolean 파라미터의 경우, null 값이 들어올 수 없다고 판단하여 별도의 null 검증 로직을 추가하지 않는 것을 선호한다. 프론트엔드와 백엔드 간의 계약이 명확할 때 중복 검증을 피하는 설계 접근법을 취한다.
📚 Learning: user 엔티티의 addcoin 메서드는 리뷰 작성 시 한 사람에게만 적용되는 단일 사용자 환경에서 사용되므로 멀티스레드 동시성 처리가 필요하지 않다....
Learnt from: dionisos198
PR: Ureca-Final-Project-Team2/be_badata#291
File: src/main/java/com/TwoSeaU/BaData/domain/user/entity/User.java:92-94
Timestamp: 2025-07-29T01:57:02.534Z
Learning: User 엔티티의 addCoin 메서드는 리뷰 작성 시 한 사람에게만 적용되는 단일 사용자 환경에서 사용되므로 멀티스레드 동시성 처리가 필요하지 않다.

Applied to files:

  • src/test/java/com/TwoSeaU/BaData/domain/user/service/UserServiceTest.java
📚 Learning: choyunju의 애플리케이션에서는 user 객체 생성 시 plandata를 무조건 함께 저장하는 설계를 사용한다. 따라서 비즈니스 로직상 user.getplandata()가 nu...
Learnt from: choyunju
PR: Ureca-Final-Project-Team2/be_badata#286
File: src/main/java/com/TwoSeaU/BaData/domain/user/service/UserService.java:0-0
Timestamp: 2025-07-28T16:46:37.983Z
Learning: choyunju의 애플리케이션에서는 User 객체 생성 시 PlanData를 무조건 함께 저장하는 설계를 사용한다. 따라서 비즈니스 로직상 user.getPlanData()가 null일 가능성이 없지만, 방어적 프로그래밍을 위해 null 체크를 추가하는 것을 선호한다.

Applied to files:

  • src/test/java/com/TwoSeaU/BaData/domain/user/service/UserServiceTest.java
📚 Learning: review-reservation 간 1:1 관계에서 외래키 제약조건은 데이터 무결성을 보장하지만, jpa 지연 로딩으로 인한 lazyinitializationexception 방...
Learnt from: dionisos198
PR: Ureca-Final-Project-Team2/be_badata#144
File: src/main/java/com/TwoSeaU/BaData/domain/rental/dto/response/ShowReviewResponse.java:34-34
Timestamp: 2025-07-18T05:16:04.655Z
Learning: Review-Reservation 간 1:1 관계에서 외래키 제약조건은 데이터 무결성을 보장하지만, JPA 지연 로딩으로 인한 LazyInitializationException 방지를 위해서는 연관된 User 엔티티도 함께 fetch해야 한다. NPE 체크보다는 쿼리 개선이 더 나은 해결책이다.

Applied to files:

  • src/test/java/com/TwoSeaU/BaData/domain/user/service/UserServiceTest.java
🔇 Additional comments (6)
src/test/java/com/TwoSeaU/BaData/domain/user/service/UserServiceTest.java (6)

1-35: 패키지 및 import 구성이 적절합니다.

테스트에 필요한 모든 의존성이 올바르게 import되어 있고, 패키지 구조가 적절합니다.


37-57: 테스트 클래스 설정이 올바릅니다.

MockitoExtension을 사용한 mock 설정과 @Injectmocks를 통한 의존성 주입이 적절하게 구성되어 있습니다.


58-84: getData 성공 테스트가 잘 구성되어 있습니다.

정상 흐름에서 사용자 데이터양을 올바르게 반환하는지 검증하는 테스트가 적절합니다. Mock 설정과 assertion이 정확합니다.


86-108: getData 예외 테스트가 올바르게 구현되어 있습니다.

사용자가 존재하지 않을 때 적절한 예외가 발생하는지 검증하는 테스트가 잘 구성되어 있습니다.


110-134: getCoin 성공 테스트가 적절합니다.

사용자의 코인 수를 올바르게 반환하는지 검증하는 테스트가 잘 구성되어 있습니다.


136-158: getCoin 예외 테스트가 올바르게 구현되어 있습니다.

사용자가 존재하지 않을 때의 예외 처리가 적절하게 테스트되어 있습니다.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Aug 5, 2025

Overall Project 18.14%

There is no coverage information present for the Files changed

@choyunju choyunju merged commit fc14696 into develop Aug 5, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✅ Test test 관련(storybook, jest...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BADA-208] [TEST] 사용자 관련 테스트 코드 작성

2 participants