forked from codesquad-members-2023/second-hand-max
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bug] 채팅 메시지 목록 조회시 제 3자가 읽을 수 없도록 검증문 추가 (#156)
* #153 fix: 채팅창 목록 조회 문제 해결 - 채팅창만이 존재하고 채팅 로그가 없는 경우가 원인이었습니다. * #153 fix: nextMessageId가 응답되도록 수정 * #153 fix: 필드멤버 명 변경 * #153 fix: 오타 수정 * #153 fix: 채팅 메시지 목록 조회시 새로운 메시지가 없는 경우 408 -> 200으로 변경 * #153 feat; 채팅방에 없는 회원이 채팅 메시지 목록 조회 요청시 인가 오류 구현 * #153 feat; equalItemId 조건절 별도의 메소드로 구현
- Loading branch information
1 parent
9c4d16c
commit 52b662a
Showing
5 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/codesquard/app/domain/chat/ChatRoomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
import codesquard.app.api.chat.request.ChatLogSendRequest; | ||
import codesquard.app.api.chat.response.ChatLogListResponse; | ||
import codesquard.app.api.chat.response.ChatLogSendResponse; | ||
import codesquard.app.api.errors.exception.ForBiddenException; | ||
import codesquard.app.domain.category.Category; | ||
import codesquard.app.domain.category.CategoryRepository; | ||
import codesquard.app.domain.chat.ChatLog; | ||
|
@@ -176,4 +177,50 @@ public void readMessage() { | |
); | ||
} | ||
|
||
@DisplayName("구매자와 판매자가 아닌 제 3자가 채팅방의 채팅 메시지를 읽을 수 없다.") | ||
@Test | ||
public void readMessageWithOtherMember() { | ||
// given | ||
Member seller = memberRepository.save(createMember("avatarUrlValue1", "[email protected]", "23Yong")); | ||
Member buyer = memberRepository.save(createMember("avatarUrlValue2", "[email protected]", "bruni")); | ||
Member anonymous = memberRepository.save(createMember("avatarUrlValue3", "[email protected]", "lee1234")); | ||
|
||
Region region = regionRepository.save(RegionTestSupport.createRegion("서울 종로구 청운동")); | ||
|
||
memberTownRepository.saveAll(List.of( | ||
createMemberTown(seller, region, true), | ||
createMemberTown(buyer, region, true))); | ||
|
||
Category sport = categoryRepository.save(findByName("스포츠/레저")); | ||
Item item = createItem("빈티지 롤러 블레이드", "어린시절 추억의향수를 불러 일으키는 롤러 스케이트입니다.", 200000L, ON_SALE, | ||
"가락동", "thumbnailUrl", seller, sport); | ||
|
||
Item saveItem = itemRepository.save(item); | ||
List<Image> images = List.of( | ||
new Image("imageUrlValue1", saveItem, true), | ||
new Image("imageUrlValue2", saveItem, false)); | ||
imageRepository.saveAll(images); | ||
|
||
ChatRoom chatRoom = chatRoomRepository.save(new ChatRoom(buyer, item)); | ||
|
||
chatLogRepository.saveAll(List.of( | ||
ChatLog.createBySender("롤러 블레이드 사고 싶음", chatRoom, Principal.from(buyer)), | ||
ChatLog.createBySender("깍아주세요.", chatRoom, Principal.from(buyer)) | ||
)); | ||
|
||
Long cursor = null; | ||
Pageable pageable = Pageable.ofSize(10); | ||
|
||
// when | ||
Throwable throwable = catchThrowable( | ||
() -> chatLogService.readMessages(chatRoom.getId(), Principal.from(anonymous), cursor, | ||
pageable)); | ||
|
||
// then | ||
assertThat(throwable) | ||
.isInstanceOf(ForBiddenException.class) | ||
.extracting("errorCode.message") | ||
.isEqualTo("채팅에 대한 권한이 없습니다."); | ||
} | ||
|
||
} |