Skip to content

Comments

[test] 동아리 활동사진 이미지 다중업로드 기능 테스트코드를 작성한다#910

Merged
lepitaaar merged 2 commits intodevelop/befrom
test/#909-club-photos-multi-upload-test-MOA-403
Dec 7, 2025
Merged

[test] 동아리 활동사진 이미지 다중업로드 기능 테스트코드를 작성한다#910
lepitaaar merged 2 commits intodevelop/befrom
test/#909-club-photos-multi-upload-test-MOA-403

Conversation

@yw6938
Copy link
Collaborator

@yw6938 yw6938 commented Dec 3, 2025

#️⃣연관된 이슈

ex) #909

📝작업 내용

이미지 업로드 서비스 중에서 피드 업로드 갯수 초과했을 때, 파일 이름이 잘못되었을 때, 파일 삭제할 때 관련해서 테스트 코드를 집중적으로 만들었습니다.

중점적으로 리뷰받고 싶은 부분(선택)

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요

ex) 메서드 XXX의 이름을 더 잘 짓고 싶은데 혹시 좋은 명칭이 있을까요?

논의하고 싶은 부분(선택)

논의하고 싶은 부분이 있다면 작성해주세요.

🫡 참고사항

Summary by CodeRabbit

릴리스 노트

  • Tests
    • 이미지 서비스의 파일명 유효성 검사 및 삭제 기능에 대한 단위 테스트 추가
    • 피드 이미지 업로드 제한 기능에 대한 단위 테스트 추가

✏️ Tip: You can customize this high-level summary in your review settings.

@yw6938 yw6938 requested a review from alsdddk December 3, 2025 06:58
@yw6938 yw6938 added ✅ Test test 관련(storybook, jest...) 💾 BE Backend labels Dec 3, 2025
@vercel
Copy link

vercel bot commented Dec 3, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
moadong Ready Ready Preview Comment Dec 3, 2025 6:58am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 3, 2025

Warning

.coderabbit.yaml has a parsing error

The CodeRabbit configuration file in this repository has a parsing error and default settings were used instead. Please fix the error(s) in the configuration file. You can initialize chat with CodeRabbit to get help with the configuration file.

💥 Parsing errors (1)
Validation error: Invalid regex pattern for base branch. Received: "**" at "reviews.auto_review.base_branches[0]"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • 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

Walkthrough

CloudflareImageService에 대한 두 개의 새로운 단위 테스트 클래스를 추가합니다. CloudFlareImageServiceTest에서는 파일명 검증 및 S3 파일 삭제 동작을, CloudflareImageServiceUpdateFeedsLimitTest에서는 최대 피드 이미지 업로드 제한을 검증합니다.

Changes

Cohort / File(s) Summary
CloudflareImageService 단위 테스트
backend/src/test/java/moadong/media/service/CloudFlareImageServiceTest.java, backend/src/test/java/moadong/media/service/CloudflareImageServiceUpdateFeedsLimitTest.java
CloudFlareImageServiceTest: 파일명 검증(UNSUPPORTED_FILE_TYPE, FILE_NOT_FOUND), deleteFile 동작(null/올바르지 않은 URL 처리, 유효한 URL로 정상 삭제) 검증. CloudflareImageServiceUpdateFeedsLimitTest: 최대 피드 이미지 개수(MAX_FEED_COUNT=15) 초과 시 TOO_MANY_FILES 예외 발생 검증

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10분

  • 테스트 코드만 추가된 변경으로 기존 기능에 대한 영향 최소화
  • Mockito, Spring ReflectionTestUtils 등 표준 테스팅 도구 사용
  • 각 테스트 케이스가 명확한 검증 목표를 가짐

Possibly related PRs

Suggested reviewers

  • alsdddk
  • lepitaaar
  • Zepelown

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목은 '동아리 활동사진 이미지 다중업로드 기능 테스트코드를 작성한다'로, 추가된 두 개의 테스트 클래스(CloudFlareImageServiceTest와 CloudflareImageServiceUpdateFeedsLimitTest)의 목적을 명확하게 설명하고 있습니다.
Linked Issues check ✅ Passed PR에서 추가된 테스트 코드들이 연관 이슈 MOA-403의 목표인 '동아리 활동사진 이미지 다중업로드 기능 테스트코드 작성'을 완벽하게 충족하고 있습니다.
Out of Scope Changes check ✅ Passed 모든 변경사항이 테스트 코드 작성에만 한정되어 있으며, 연관 이슈의 범위 내에서 이루어진 변경입니다.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/#909-club-photos-multi-upload-test-MOA-403

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Dec 3, 2025

Test Results

74 tests   71 ✅  17s ⏱️
13 suites   3 💤
13 files     0 ❌

Results for commit 11cd9c6.

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

🧹 Nitpick comments (5)
backend/src/test/java/moadong/media/service/CloudFlareImageServiceTest.java (3)

27-49: 테스트 클래스/초기화 패턴 전반적으로 적절합니다

@Spy @InjectMocksReflectionTestUtils로 private 필드/init을 맞춰주는 패턴 덕분에 실제 환경과 거의 같은 상태에서 CloudflareImageService 를 exercise 하고 있어서 좋습니다.
다만 테스트 클래스/파일 이름이 CloudFlareImageServiceTest 로, 서비스명 CloudflareImageService 와 대소문자/철자가 살짝 다른데, IDE 검색/네비게이션을 생각하면 CloudflareImageServiceTest 로 통일하는 것도 고려해 볼 만합니다.


52-75: 파일명 검증 테스트가 명확하고 에러 코드 매핑도 잘 드러납니다

잘못된 확장자와 빈 문자열에 대해 각각 UNSUPPORTED_FILE_TYPE, FILE_NOT_FOUND 를 직접 검증해서 도메인 요구사항이 테스트에 잘 녹아 있습니다.
다만 validateFileName 이 private 메서드라 ReflectionTestUtils.invokeMethod 를 사용하고 있는데, 가능하다면 향후에는 이 검증이 노출되는 public API(예: 업로드 메서드) 단에서 같은 시나리오를 검증하도록 리팩터링하면 구현 변경에도 덜 민감한 테스트가 될 것 같습니다.


77-115: deleteFile 방어 로직/정상 플로우 테스트 구성이 적절합니다

  • filePath == null 인 경우와 view endpoint 접두어가 다른 경우에 S3 deleteObject 가 호출되지 않는 것을 검증한 부분이 실제 운영 시 오동작 방지에 도움이 될 것 같습니다.
  • 정상 URL 케이스에서 ArgumentCaptor<DeleteObjectRequest>bucketkey 를 정확히 검증한 것도 좋습니다. 특히 key 에서 도메인/프리픽스 제거가 원하는 대로 되는지 명확히 보장되네요.

추가로 커버하고 싶다면, filePath 가 빈 문자열이거나 공백만 있는 경우 같은 엣지 케이스도 하나 정도 더 넣어두면 방어 범위가 조금 더 넓어질 것 같습니다(필수는 아니고 선택 사항으로 보입니다).

backend/src/test/java/moadong/media/service/CloudflareImageServiceUpdateFeedsLimitTest.java (2)

32-57: 서비스 초기화 방식이 다른 테스트와 살짝 달라, 향후 변경 시 차이가 날 수 있습니다

다른 클래스(CloudFlareImageServiceTest)에서는 viewEndpoint, bucketNameReflectionTestUtils.setField 로 주입하고 init() 까지 호출해 실제 빈과 유사하게 초기화하고 있는데, 여기서는 그런 설정 없이 바로 updateFeeds 를 호출하고 있습니다.
현재 구현이 업로드 개수 제한을 먼저 검사한다면 문제 없겠지만, 나중에 updateFeeds 내부에서 presigner/bucket 설정을 더 일찍 참조하도록 바뀌면 이 테스트만 NPE 등으로 깨질 여지가 있어, 동일한 초기화 패턴을 맞춰두는 것도 한 번 고려해 볼 만합니다.


59-75: 업로드 제한 시나리오를 잘 검증하지만, 테스트 데이터 표현을 조금 더 명확히 할 여지가 있습니다

  • Arrays.asList(new String[MAX_FEED_COUNT]) 로 길이만 맞춘 null 리스트를 만들고, 이를 기존 feedImages 와 업로드 파라미터 모두에 재사용하는 방식은 개수 제한 관점에서는 충분하지만, 나중에 구현이 각 URL 에 문자열 연산을 수행하면 null 때문에 다른 예외가 먼저 날 수도 있습니다.
  • 또한 현재는 "이미 MAX 개가 저장된 상태에서 MAX 개를 더 올리려다" 예외가 나는 시나리오라, 테스트 이름의 "MAX_FEED_COUNT 이상의 피드를 업로드" 와는 뉘앙스가 조금 다릅니다.

가독성과 의도를 더 분명히 하려면, 예를 들어:

  • 기존 feedImagesMAX_FEED_COUNT 개(혹은 0개)로 두고,
  • 업로드 리스트는 "image-0", "image-1", ... 같은 dummy 값으로 MAX_FEED_COUNT + 1 개를 채워서

"총 개수가 제한을 초과할 때" 를 직접적으로 표현하는 것도 고려해 볼 수 있습니다. 로직 자체는 지금도 잘 검증되고 있어서 반드시 바꿔야 하는 수준은 아닙니다.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a92091b and 11cd9c6.

📒 Files selected for processing (2)
  • backend/src/test/java/moadong/media/service/CloudFlareImageServiceTest.java (1 hunks)
  • backend/src/test/java/moadong/media/service/CloudflareImageServiceUpdateFeedsLimitTest.java (1 hunks)

Copy link
Collaborator

@alsdddk alsdddk left a comment

Choose a reason for hiding this comment

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

수고하셨어요!!
다음 스터디에서 테스트코드 네이밍 규칙에 대해서 정하는게 좋을 거 같네여
예를 들어, 파일 관련해서 영어 단어를 쓸 지, 'File_이름'을 'FILE_NAME'이나 '파일이름' 중에 통일 시킬지 같은 거요!

@Mock
private S3Presigner s3Presigner;

private final int MAX_FEED_COUNT = 15;
Copy link
Collaborator

Choose a reason for hiding this comment

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

프로덕션 코드 쪽 상수를 직접 참조하는건 어떨까요??
테스트 코드와 도메인 제약이 자동으로 동기화되도록 만드는 것도 유지보수 측면에서 좋을 거 같아요!


//then
ArgumentCaptor<DeleteObjectRequest> captor = ArgumentCaptor.forClass(DeleteObjectRequest.class);
verify(s3Client).deleteObject(captor.capture());
Copy link
Collaborator

Choose a reason for hiding this comment

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

찾아보니 메서드 호출 시 전달된 인자를 가로채서 들고 있는 객체네요! 좋은 거 같아요~

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

감사합니다!

@lepitaaar lepitaaar merged commit 79d50ba into develop/be Dec 7, 2025
5 checks passed
Copy link
Member

@oesnuj oesnuj left a comment

Choose a reason for hiding this comment

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

LGTM

@coderabbitai coderabbitai bot mentioned this pull request Dec 23, 2025
@lepitaaar lepitaaar deleted the test/#909-club-photos-multi-upload-test-MOA-403 branch January 18, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💾 BE Backend ✅ Test test 관련(storybook, jest...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants