-
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.
feat: ChatRoomEntity에 targetId와 type으로 고유키 설정
- Loading branch information
Showing
2 changed files
with
65 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
55 changes: 55 additions & 0 deletions
55
backend/src/test/java/mouda/backend/chat/entity/ChatRoomEntityTest.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,55 @@ | ||
package mouda.backend.chat.entity; | ||
|
||
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 org.springframework.dao.DataIntegrityViolationException; | ||
|
||
import mouda.backend.chat.infrastructure.ChatRoomRepository; | ||
import mouda.backend.common.fixture.ChatRoomEntityFixture; | ||
|
||
@SpringBootTest | ||
class ChatRoomEntityTest { | ||
|
||
@Autowired | ||
ChatRoomRepository chatRoomRepository; | ||
|
||
@DisplayName("targetId와 type이 같은 ChatRoomEntity는 저장할 수 없다.") | ||
@Test | ||
void failToCreateDuplicatedUnique() { | ||
ChatRoomEntity chatRoom = ChatRoomEntityFixture.getChatRoomEntityOfBet(1L, 1L); | ||
chatRoomRepository.save(chatRoom); | ||
|
||
ChatRoomEntity duplicated = ChatRoomEntityFixture.getChatRoomEntityOfBet(1L, 2L); | ||
|
||
assertThatThrownBy(() -> chatRoomRepository.save(duplicated)) | ||
.isInstanceOf(DataIntegrityViolationException.class); | ||
} | ||
|
||
@DisplayName("targetId이 같아도 type이 다르다면 ChatRoomEntity는 저장할 수 있다.") | ||
@Test | ||
void createWithDifferentType() { | ||
ChatRoomEntity chatRoom1 = ChatRoomEntityFixture.getChatRoomEntityOfBet(1L, 1L); | ||
chatRoomRepository.save(chatRoom1); | ||
|
||
ChatRoomEntity chatRoom2 = ChatRoomEntityFixture.getChatRoomEntityOfMoim(1L, 2L); | ||
chatRoomRepository.save(chatRoom2); | ||
|
||
assertThat(chatRoomRepository.findAll()).hasSize(2); | ||
} | ||
|
||
@DisplayName("type이 같아도 targetId이 다르다면 ChatRoomEntity는 저장할 수 있다.") | ||
@Test | ||
void createWithDifferentTargetId() { | ||
ChatRoomEntity chatRoom1 = ChatRoomEntityFixture.getChatRoomEntityOfBet(1L, 1L); | ||
chatRoomRepository.save(chatRoom1); | ||
|
||
ChatRoomEntity chatRoom2 = ChatRoomEntityFixture.getChatRoomEntityOfBet(2L, 2L); | ||
chatRoomRepository.save(chatRoom2); | ||
|
||
assertThat(chatRoomRepository.findAll()).hasSize(2); | ||
} | ||
} |