fix: 어드민이 문의 채팅방 나가고 다시 메시지가 오면 못보는 문제 해결#499
Conversation
- `@BeforeEach` 수정: System Admin(ID=1)을 먼저 생성
- `createAdminChatRoomAndGetRoomsSuccess` 테스트 수정
- `adminLeftInquiryRoomReappearsWhenUserSendsNewMessage` 테스트 추가:
어드민이 나간 문의 채팅방에 사용자가 새 메시지를 보내 어드민 목록에 다시 노출되는 시나리오 검증
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthrough관리자 전용 조회 JPQL의 뷰어별 필터링을 수정하여, 관리자가 퇴장한 이후라도 Changes
Estimated code review effort🎯 3 (중간) | ⏱️ ~20분 Possibly related PRs
Suggested labels
개요챗룸 저장소의 JPQL 필터링 조건을 수정하여 관리자가 퇴장한 후에도 새로운 메시지가 송신되면 챗룸이 다시 표시되도록 변경하고, 이를 검증하는 통합 테스트를 추가했습니다. 변경사항
예상 코드 리뷰 난이도🎯 3 (중간) | ⏱️ ~20분 관련 가능성 있는 PR
제안 레이블
래빗의 축시
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/test/java/gg/agit/konect/integration/domain/chat/ChatApiTest.java`:
- Around line 20-22: The file ChatApiTest has a duplicated import of
org.springframework.transaction.annotation.Transactional; remove the redundant
import so the import list only contains a single
org.springframework.transaction.annotation.Transactional entry (locate the
duplicate import statements in ChatApiTest and delete one of them).
- Around line 79-91: Replace the hardcoded literal 1 for the system admin ID
with a named constant (e.g., SYSTEM_ADMIN_ID) and use it wherever the code
currently checks or inserts ID=1: update the check adminUser.getId() != 1, the
native SQL WHERE NOT EXISTS and INSERT SELECT id value, and any comments to
reference SYSTEM_ADMIN_ID; declare the constant near the test class fields so
adminUser, persist(UserFixture.createAdmin(...)), and the
entityManager.createNativeQuery(...) calls all reference SYSTEM_ADMIN_ID instead
of the literal 1.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 1791f1b7-2aba-4ae6-b3b3-00d98fd12333
📒 Files selected for processing (2)
src/main/java/gg/agit/konect/domain/chat/repository/ChatRoomRepository.javasrc/test/java/gg/agit/konect/integration/domain/chat/ChatApiTest.java
📜 Review details
⏰ 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: Analyze (java-kotlin)
🧰 Additional context used
📓 Path-based instructions (2)
src/main/java/**/*.java
⚙️ CodeRabbit configuration file
src/main/java/**/*.java: 아래 원칙으로 리뷰 코멘트를 작성한다.
- 코멘트는 반드시 한국어로 작성한다.
- 반드시 수정이 필요한 항목만 코멘트로 남기고, 단순 취향 차이는 지적하지 않는다.
- 각 코멘트 첫 줄에 심각도를
[LEVEL: high|medium|low]형식으로 반드시 표기한다.- 심각도 기준: high=운영 장애 가능, medium=품질 저하, low=개선 권고.
- 각 코멘트는 "문제 -> 영향 -> 제안" 순서로 3문장 이내로 간결하게 작성한다.
- 가능하면 재현 조건 및 실패 시나리오도 포함한다.
- 제안은 현재 코드베이스(Spring Boot + JPA + Flyway) 패턴과 일치해야 한다.
- 보안, 트랜잭션 경계, 예외 처리, N+1, 성능 회귀 가능성을 우선 점검한다.
- 가독성: 변수/메서드 이름이 의도를 바로 드러내는지, 중첩과 메서드 길이가 과도하지 않은지 점검한다.
- 단순화: 불필요한 추상화, 중복 로직, 과한 방어 코드가 있으면 더 단순한 대안을 제시한다.
- 확장성: 새 요구사항 추가 시 변경 범위가 최소화되는 구조인지(하드코딩 분기/값 여부 포함) 점검한다.
Files:
src/main/java/gg/agit/konect/domain/chat/repository/ChatRoomRepository.java
**/*
⚙️ CodeRabbit configuration file
**/*: 공통 리뷰 톤 가이드:
- 모든 코멘트는 첫 줄에
[LEVEL: ...]태그를 포함한다.- 과장된 표현 없이 사실 기반으로 작성한다.
- 한 코멘트에는 하나의 이슈만 다룬다.
- 코드 예시가 필요하면 최소 수정 예시를 제시한다.
- 가독성/단순화/확장성 이슈를 발견하면 우선순위를 높여 코멘트한다.
Files:
src/main/java/gg/agit/konect/domain/chat/repository/ChatRoomRepository.javasrc/test/java/gg/agit/konect/integration/domain/chat/ChatApiTest.java
🔇 Additional comments (3)
src/main/java/gg/agit/konect/domain/chat/repository/ChatRoomRepository.java (1)
182-189: [LEVEL: low] 쿼리 로직이 도메인 로직과 일관성 있게 구현됨
ChatRoomMember.hasVisibleMessages()메서드의lastMessageSentAt > visibleMessageFrom비교 로직을 JPQL 쿼리에 올바르게 반영했습니다.LEFT JOIN으로 인해 멤버십이 없는 경우(viewerAdminCrm.id.userId IS NULL)도 정상 처리됩니다.src/test/java/gg/agit/konect/integration/domain/chat/ChatApiTest.java (2)
261-277: [LEVEL: low] LGTM - 헬퍼 메서드 구현
parseChatRoomId와extractRoomIds헬퍼 메서드가 응답 파싱을 적절히 캡슐화합니다.chatRoomId와roomId필드 모두 처리하여 API 응답 형식 차이에 대응합니다.
242-246: 테스트에서 프로덕션 API가 호출되고 실행되므로, 본 코멘트는 부정확합니다.테스트는 라인 238-240에서
performPost("/chats/rooms/{id}/messages")를 통해 실제 메시지 전송 API를 호출하며, 이는 프로덕션 코드의ChatService.sendDirectMessage()→chatRoom.updateLastMessage()를 정상적으로 실행합니다.native SQL 쿼리는 프로덕션 코드의 실행을 우회하는 것이 아니라, 메서드의
@Transactional(propagation = Propagation.REQUIRES_NEW)트랜잭션 격리로 인해 API가 별도 트랜잭션에서 커밋한 timestamp 변경사항을 테스트 트랜잭션에서 가시화하기 위한 보조 조치입니다. 이는 일반적인 Spring 통합 테스트 패턴입니다.> Likely an incorrect or invalid review comment.
🔍 개요
🚀 주요 변경 내용
ChatRoomRepository.java:
findAdminChatRoomsOptimized쿼리의 가시성 조건 수정viewerAdminCrm.leftAt IS NULL만 체크하여 나간 어드민은 영구히 목록에서 제외leftAt IS NULL OR lastMessageSentAt > visibleMessageFrom조건으로 수정ChatApiTest.java: 관리자 문의 채팅방 재가시화 테스트 추가
adminLeftInquiryRoomReappearsWhenUserSendsNewMessage테스트 메서드 추가💬 참고 사항
✅ Checklist (완료 조건)