Skip to content

Commit

Permalink
test: fetch user chatroom using banned, exploded condition
Browse files Browse the repository at this point in the history
  • Loading branch information
geneaky committed May 21, 2024
1 parent 86c537e commit 905ab61
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ class ChatRoomControllerTest extends ControllerTestExtension {
fieldWithPath("userChatRoomResponseList[].senderDefaultProfileImageType").type(NUMBER).description("마지막 채팅 보낸 사람 기본 프로필 이미지 타입"),
fieldWithPath("userChatRoomResponseList[].lastChatId").type(NUMBER).description("마지막 채팅 ID"),
fieldWithPath("userChatRoomResponseList[].lastChatContent").type(STRING).description("마지막 채팅 내용"),
fieldWithPath("userChatRoomResponseList[].lastChatDispatchTime").type(STRING).description("마지막 채팅 발송 시간")
fieldWithPath("userChatRoomResponseList[].lastChatDispatchTime").type(STRING).description("마지막 채팅 발송 시간"),
fieldWithPath("userChatRoomResponseList[].isBanned").type(BOOLEAN).description("사용자가 차단된 채팅방인지 여부"),
fieldWithPath("userChatRoomResponseList[].isExploded").type(BOOLEAN).description("채팅방 폭파 여부")
).and(getCursorField())));
}

Expand Down Expand Up @@ -595,6 +597,8 @@ private UserChatRoomResponse getChatRoomResponse(ChatRoom chatRoom, Chat chat) {
.lastChatId(chat.getId())
.lastChatContent(chat.getMessage())
.lastChatDispatchTime(LocalDateTime.now())
.isExploded(false)
.isBanned(false)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class ChatRoomRepositoryTest {
.roomSid("IwZrRxR5")
.roomSize(110)
.defaultRoomImageType(2)
.isDeleted(true)
.build();
ChatRoom chatRoom3 = ChatRoom.builder()
.book(book1)
Expand All @@ -114,6 +115,12 @@ class ChatRoomRepositoryTest {
chatRoomRepository.save(chatRoom2);
chatRoomRepository.save(chatRoom3);

ChatRoomBlockedUser chatRoomBlockedUser = ChatRoomBlockedUser.builder()
.user(user1)
.chatRoom(chatRoom3)
.build();
chatRoomBlockedUserRepository.save(chatRoomBlockedUser);

Participant participant1 = Participant.builder().user(user1).chatRoom(chatRoom1)
.participantStatus(HOST).build();
Participant participant2 = Participant.builder().user(user1).chatRoom(chatRoom2)
Expand Down Expand Up @@ -167,6 +174,8 @@ class ChatRoomRepositoryTest {
.lastChatId(chat4.getId())
.lastChatContent(chat4.getMessage())
.lastChatDispatchTime(chat4.getCreatedAt())
.isBanned(true)
.isExploded(false)
.build();

UserChatRoomResponse userChatRoomResponse2 = UserChatRoomResponse.builder()
Expand All @@ -184,14 +193,16 @@ class ChatRoomRepositoryTest {
.lastChatId(chat2.getId())
.lastChatContent(chat2.getMessage())
.lastChatDispatchTime(chat2.getCreatedAt())
.isBanned(false)
.isExploded(true)
.build();

PageRequest pageRequest = PageRequest.of(0, 2, Sort.by("id").descending());
List<UserChatRoomResponse> contents = List.of(userChatRoomResponse1, userChatRoomResponse2);
Slice<UserChatRoomResponse> result = toSlice(contents, pageRequest);

Slice<UserChatRoomResponse> slice = chatRoomRepository.findUserChatRoomsWithLastChat(
pageRequest, null, null, user1.getId());
Slice<UserChatRoomResponse> slice = chatRoomRepository.findUserChatRoomsWithLastChat(pageRequest, null, null, user1.getId());

assertThat(slice.getContent()).usingRecursiveComparison()
.ignoringFieldsOfTypes(LocalDateTime.class)
.isEqualTo(result.getContent());
Expand Down Expand Up @@ -219,6 +230,7 @@ class ChatRoomRepositoryTest {
.roomSid("4SyVX")
.roomSize(77)
.defaultRoomImageType(1)
.isDeleted(true)
.build();
ChatRoom chatRoom2 = ChatRoom.builder()
.book(book2)
Expand All @@ -236,6 +248,12 @@ class ChatRoomRepositoryTest {
.build();
chatRoomRepository.saveAll(List.of(chatRoom1, chatRoom2, chatRoom3));

ChatRoomBlockedUser chatRoomBlockedUser = ChatRoomBlockedUser.builder()
.chatRoom(chatRoom1)
.user(user1)
.build();
chatRoomBlockedUserRepository.save(chatRoomBlockedUser);

Participant participant1 = Participant.builder().user(user1).chatRoom(chatRoom1)
.participantStatus(HOST).build();
Participant participant2 = Participant.builder().user(user1).chatRoom(chatRoom2)
Expand All @@ -251,6 +269,8 @@ class ChatRoomRepositoryTest {
.roomSid(chatRoom1.getRoomSid())
.defaultRoomImageType(chatRoom1.getDefaultRoomImageType())
.roomMemberCount(1L)
.isExploded(true)
.isBanned(true)
.build();

PageRequest pageRequest = PageRequest.of(0, 2, Sort.by("id").ascending());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,16 @@ private static CreateChatRoomRequest getCreateChatRoomRequest(BookRequest bookRe
.roomName(chatRoom1.getRoomName())
.roomMemberCount(1L)
.defaultRoomImageType(chatRoom1.getDefaultRoomImageType())
.isBanned(false)
.isExploded(false)
.build();
List<UserChatRoomResponse> result = List.of(userChatRoomResponse);
PageRequest pageRequest = PageRequest.of(0, 1, Sort.by("id").descending());
Slice<UserChatRoomResponse> slice = new SliceImpl<>(result, pageRequest, true);
when(chatRoomRepository.findUserChatRoomsWithLastChat(any(), any(), any(),
any())).thenReturn(
slice);
UserChatRoomsResponseSlice userChatRoomsResponseSlice = chatRoomService.getUserChatRooms(
any(), any(), any(), any());

assertThat(userChatRoomsResponseSlice).usingRecursiveComparison()
.isEqualTo(UserChatRoomsResponseSlice.of(slice));
when(chatRoomRepository.findUserChatRoomsWithLastChat(any(), any(), any(), any())).thenReturn(slice);
UserChatRoomsResponseSlice userChatRoomsResponseSlice = chatRoomService.getUserChatRooms(any(), any(), any(), any());

assertThat(userChatRoomsResponseSlice).usingRecursiveComparison().isEqualTo(UserChatRoomsResponseSlice.of(slice));
}

@Test
Expand Down

0 comments on commit 905ab61

Please sign in to comment.