Skip to content

fix: 어드민이 문의 채팅방 나가고 다시 메시지가 오면 못보는 문제 해결#499

Merged
dh2906 merged 4 commits intodevelopfrom
fix/admin-inquiry-room-reappear
Apr 5, 2026
Merged

fix: 어드민이 문의 채팅방 나가고 다시 메시지가 오면 못보는 문제 해결#499
dh2906 merged 4 commits intodevelopfrom
fix/admin-inquiry-room-reappear

Conversation

@dh2906
Copy link
Copy Markdown
Contributor

@dh2906 dh2906 commented Apr 5, 2026

🔍 개요

  • 어드민이 문의 채팅방을 나간 후 사용자가 새 메시지를 보내, 해당 어드민의 채팅방 목록에 다시 노출되지 않는 버그를 수정합니다.

🚀 주요 변경 내용

  • ChatRoomRepository.java: findAdminChatRoomsOptimized 쿼리의 가시성 조건 수정

    • 기존: viewerAdminCrm.leftAt IS NULL만 체크하여 나간 어드민은 영구히 목록에서 제외
    • 변경: leftAt IS NULL OR lastMessageSentAt > visibleMessageFrom 조건으로 수정
    • 나간 후 새 메시지가 오면 다시 목록에 노출되도록 개선
  • ChatApiTest.java: 관리자 문의 채팅방 재가시화 테스트 추가

    • adminLeftInquiryRoomReappearsWhenUserSendsNewMessage 테스트 메서드 추가
    • 어드민이 나간 후 사용자가 새 메시지를 보내 목록에 다시 보이는 시나리오 검증

💬 참고 사항


✅ Checklist (완료 조건)

  • 코드 스타일 가이드 준수
  • 테스트 코드 포함됨
  • Reviewers / Assignees / Labels 지정 완료
  • 보안 및 민감 정보 검증 (API 키, 환경 변수, 개인정보 등)

dh2906 added 2 commits April 5, 2026 20:16
  - `@BeforeEach` 수정: System Admin(ID=1)을 먼저 생성
  - `createAdminChatRoomAndGetRoomsSuccess` 테스트 수정
  - `adminLeftInquiryRoomReappearsWhenUserSendsNewMessage` 테스트 추가:
    어드민이 나간 문의 채팅방에 사용자가 새 메시지를 보내 어드민 목록에 다시 노출되는 시나리오 검증
@dh2906 dh2906 self-assigned this Apr 5, 2026
@dh2906 dh2906 added the 버그 정상적으로 동작하지 않는 문제 상황 관련 이슈입니다. label Apr 5, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 5, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

관리자 전용 조회 JPQL의 뷰어별 필터링을 수정하여, 관리자가 퇴장한 이후라도 cr.lastMessageSentAt > viewerAdminCrm.visibleMessageFrom이면 챗룸을 포함하도록 변경하고, 해당 동작을 검증하는 통합 테스트를 추가했습니다.

Changes

Cohort / File(s) 요약
저장소 쿼리 조건 수정
src/main/java/.../chat/repository/ChatRoomRepository.java
findAdminChatRoomsOptimized의 JPQL 필터를 변경: 이전에 leftAt IS NULL 또는 멤버십 없음인 경우만 포함하던 로직에, leftAt IS NOT NULL이더라도 cr.lastMessageSentAt > viewerAdminCrm.visibleMessageFrom이면 포함하도록 추가 조건을 도입했습니다.
통합 테스트 확대
src/test/java/.../integration/domain/chat/ChatApiTest.java
관리자 초기화 로직(상수 SYSTEM_ADMIN_ID, 시스템 관리자 보장), 거래 전파 설정 일부, 헬퍼(parseChatRoomId, extractRoomIds) 재배치 및 adminLeftInquiryRoomReappearsWhenUserSendsNewMessage 테스트 추가로 관리자 퇴장 후 새 메시지 전송 시 챗룸 재표시 동작을 검증합니다.

Estimated code review effort

🎯 3 (중간) | ⏱️ ~20분

Possibly related PRs

Suggested labels

테스트

개요

챗룸 저장소의 JPQL 필터링 조건을 수정하여 관리자가 퇴장한 후에도 새로운 메시지가 송신되면 챗룸이 다시 표시되도록 변경하고, 이를 검증하는 통합 테스트를 추가했습니다.

변경사항

Cohort / File(s) 요약
저장소 쿼리 조건 수정
src/main/java/.../chat/repository/ChatRoomRepository.java
findAdminChatRoomsOptimized 메서드의 JPQL 필터링 조건을 수정하여, 관리자 멤버십이 leftAt IS NOT NULL이더라도 cr.lastMessageSentAt > viewerAdminCrm.visibleMessageFrom 조건을 만족하면 챗룸을 포함하도록 변경했습니다.
통합 테스트 확대
src/test/java/.../integration/domain/chat/ChatApiTest.java
adminLeftInquiryRoomReappearsWhenUserSendsNewMessage 테스트를 추가하여 관리자 퇴장 후 새 메시지 송신 시 챗룸 재표시 동작을 검증하고, 헬퍼 메서드(parseChatRoomId, extractRoomIds)와 관리자 사용자 초기화 로직을 추가했습니다.

예상 코드 리뷰 난이도

🎯 3 (중간) | ⏱️ ~20분

관련 가능성 있는 PR

제안 레이블

테스트

래빗의 축시

🐇 새 메시지로 다시 빛나는 방이여,
내가 폴짝폴짝 기쁜 발자국 남기네.
쿼리 한 줄이 길을 열고,
테스트 한 편이 문을 닫네.
달빛 아래 깡총, 환영하노라!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.88% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목이 변경 내용과 명확하게 일치합니다. '어드민이 문의 채팅방을 나가고 다시 메시지가 오면 못보는 문제 해결'은 코드의 주요 변경 사항(어드민이 나간 방에서 새 메시지 수신 시 목록 재노출)을 정확하게 설명합니다.
Description check ✅ Passed PR 설명이 변경 사항과 관련되어 있으며, 구체적인 파일, 쿼리 조건 변경, 테스트 추가 등을 상세히 설명합니다. 제목과 일치하고 명확한 맥락을 제공합니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/admin-inquiry-room-reappear

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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between d020892 and bb4ec39.

📒 Files selected for processing (2)
  • src/main/java/gg/agit/konect/domain/chat/repository/ChatRoomRepository.java
  • src/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.java
  • src/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 - 헬퍼 메서드 구현

parseChatRoomIdextractRoomIds 헬퍼 메서드가 응답 파싱을 적절히 캡슐화합니다. chatRoomIdroomId 필드 모두 처리하여 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.

@dh2906 dh2906 merged commit 1b49315 into develop Apr 5, 2026
3 of 4 checks passed
@dh2906 dh2906 deleted the fix/admin-inquiry-room-reappear branch April 5, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

버그 정상적으로 동작하지 않는 문제 상황 관련 이슈입니다.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant