-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
중복 모임 채팅방 생성 버그 픽스
- Loading branch information
Showing
6 changed files
with
176 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
23 changes: 23 additions & 0 deletions
23
backend/src/main/java/mouda/backend/chat/implement/ChatRoomValidator.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package mouda.backend.chat.implement; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import mouda.backend.chat.domain.ChatRoomType; | ||
import mouda.backend.chat.exception.ChatErrorMessage; | ||
import mouda.backend.chat.exception.ChatException; | ||
import mouda.backend.chat.infrastructure.ChatRoomRepository; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ChatRoomValidator { | ||
|
||
private final ChatRoomRepository chatRoomRepository; | ||
|
||
public void validateAlreadyExists(long targetId, ChatRoomType chatRoomType) { | ||
if (chatRoomRepository.existsByTargetIdAndType(targetId, chatRoomType)) { | ||
throw new ChatException(HttpStatus.BAD_REQUEST, ChatErrorMessage.CHATROOM_ALREADY_EXISTS); | ||
} | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
backend/src/test/java/mouda/backend/chat/implement/ChatRoomValidatorTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package mouda.backend.chat.implement; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import mouda.backend.bet.entity.BetEntity; | ||
import mouda.backend.bet.infrastructure.BetRepository; | ||
import mouda.backend.chat.domain.ChatRoomType; | ||
import mouda.backend.chat.entity.ChatRoomEntity; | ||
import mouda.backend.chat.exception.ChatException; | ||
import mouda.backend.chat.infrastructure.ChatRoomRepository; | ||
import mouda.backend.common.fixture.BetEntityFixture; | ||
import mouda.backend.common.fixture.ChatRoomEntityFixture; | ||
import mouda.backend.common.fixture.DarakbangSetUp; | ||
import mouda.backend.common.fixture.MoimFixture; | ||
import mouda.backend.moim.domain.Moim; | ||
import mouda.backend.moim.infrastructure.MoimRepository; | ||
|
||
@SpringBootTest | ||
class ChatRoomValidatorTest extends DarakbangSetUp { | ||
|
||
@Autowired | ||
ChatRoomValidator chatRoomValidator; | ||
|
||
@Autowired | ||
MoimRepository moimRepository; | ||
|
||
@Autowired | ||
BetRepository betRepository; | ||
|
||
@Autowired | ||
ChatRoomRepository chatRoomRepository; | ||
|
||
@DisplayName("이미 존재하는 채팅방인지 검증한다. - ChatRoomType.MOIM") | ||
@Test | ||
void existedChatRoom_typeMoim() { | ||
// given | ||
Moim moim = MoimFixture.getCoffeeMoim(darakbang.getId()); | ||
Moim savedMoim = moimRepository.save(moim); | ||
|
||
ChatRoomEntity chatRoomEntityOfMoim = ChatRoomEntityFixture.getChatRoomEntityOfMoim(savedMoim.getId(), darakbang.getId()); | ||
chatRoomRepository.save(chatRoomEntityOfMoim); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> chatRoomValidator.validateAlreadyExists(savedMoim.getId(), ChatRoomType.MOIM)) | ||
.isInstanceOf(ChatException.class); | ||
} | ||
|
||
@DisplayName("이미 존재하는 채팅방인지 검증한다. - ChatRoomType.BET") | ||
@Test | ||
void existedChatRoom_typeBet() { | ||
// given | ||
BetEntity betEntity = BetEntityFixture.getBetEntity(darakbang.getId(), darakbangAnna.getId()); | ||
BetEntity savedBet = betRepository.save(betEntity); | ||
|
||
ChatRoomEntity chatRoomEntityOfBet = ChatRoomEntityFixture.getChatRoomEntityOfBet(savedBet.getId(), darakbang.getId()); | ||
chatRoomRepository.save(chatRoomEntityOfBet); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> chatRoomValidator.validateAlreadyExists(savedBet.getId(), ChatRoomType.BET)) | ||
.isInstanceOf(ChatException.class); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
backend/src/test/java/mouda/backend/chat/implement/ChatRoomWriterTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package mouda.backend.chat.implement; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import java.util.Optional; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import mouda.backend.bet.entity.BetEntity; | ||
import mouda.backend.bet.infrastructure.BetRepository; | ||
import mouda.backend.chat.domain.ChatRoomType; | ||
import mouda.backend.chat.entity.ChatRoomEntity; | ||
import mouda.backend.chat.exception.ChatException; | ||
import mouda.backend.chat.infrastructure.ChatRoomRepository; | ||
import mouda.backend.common.fixture.BetEntityFixture; | ||
import mouda.backend.common.fixture.DarakbangSetUp; | ||
import mouda.backend.common.fixture.MoimFixture; | ||
import mouda.backend.moim.domain.Moim; | ||
import mouda.backend.moim.infrastructure.MoimRepository; | ||
|
||
class ChatRoomWriterTest extends DarakbangSetUp { | ||
|
||
@Autowired | ||
ChatRoomWriter chatRoomWriter; | ||
|
||
@Autowired | ||
MoimRepository moimRepository; | ||
|
||
@Autowired | ||
BetRepository betRepository; | ||
|
||
@Autowired | ||
ChatRoomRepository chatRoomRepository; | ||
|
||
@DisplayName("새로운 채팅방을 생성한다.") | ||
@Test | ||
void append() { | ||
// given | ||
Moim moim = MoimFixture.getCoffeeMoim(darakbang.getId()); | ||
Moim savedMoim = moimRepository.save(moim); | ||
|
||
// when | ||
chatRoomWriter.append(savedMoim.getId(), darakbang.getId(), ChatRoomType.MOIM); | ||
|
||
//then | ||
Optional<ChatRoomEntity> chatRoomEntity = chatRoomRepository.findByTargetIdAndType(savedMoim.getId(), ChatRoomType.MOIM); | ||
assertThat(chatRoomEntity.isPresent()).isTrue(); | ||
assertThat(chatRoomEntity.get().getTargetId()).isEqualTo(savedMoim.getId()); | ||
assertThat(chatRoomEntity.get().getType()).isEqualTo(ChatRoomType.MOIM); | ||
} | ||
|
||
@DisplayName("이미 존재하는 모임 채팅방일 땐 예외를 발생한다.") | ||
@Test | ||
void append_alreadyExistedMoimChatRoom() { | ||
// given | ||
Moim moim = MoimFixture.getCoffeeMoim(darakbang.getId()); | ||
Moim savedMoim = moimRepository.save(moim); | ||
chatRoomWriter.append(savedMoim.getId(), darakbang.getId(), ChatRoomType.MOIM); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> chatRoomWriter.append(savedMoim.getId(), darakbang.getId(), ChatRoomType.MOIM)) | ||
.isInstanceOf(ChatException.class); | ||
} | ||
|
||
@DisplayName("이미 존재하는 배팅 채팅방일 땐 예외를 발생한다.") | ||
@Test | ||
void append_alreadyExistedBetChatRoom() { | ||
// given | ||
BetEntity betEntity = BetEntityFixture.getBetEntity(darakbang.getId(), darakbangAnna.getId()); | ||
BetEntity savedBet = betRepository.save(betEntity); | ||
chatRoomWriter.append(savedBet.getId(), darakbang.getId(), ChatRoomType.BET); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> chatRoomWriter.append(savedBet.getId(), darakbang.getId(), ChatRoomType.BET)) | ||
.isInstanceOf(ChatException.class); | ||
} | ||
} |