Skip to content

Commit

Permalink
fix: 코드 수정사항 테스트코드에 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
minisundev committed Nov 7, 2024
1 parent 524fce1 commit 815e71b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion chat/src/main/kotlin/kpring/chat/chat/model/Chat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Chat(
val id: String? = null,
val userId: String,
val type: ChatType,
val contextId: String, // roomId or serverId
// roomId or serverId
val contextId: String,
var content: String,
) : BaseTime() {
fun isEdited(): Boolean {
Expand Down
9 changes: 8 additions & 1 deletion chat/src/test/kotlin/kpring/chat/chat/ChatServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import kpring.chat.global.CommonTest
import kpring.chat.global.ContextTest
import kpring.chat.global.exception.ErrorCode
import kpring.chat.global.exception.GlobalException
import kpring.chat.global.util.AccessVerifier
import kpring.core.chat.chat.dto.request.CreateChatRequest
import kpring.core.chat.chat.dto.request.DeleteChatRequest
import kpring.core.chat.chat.dto.request.UpdateChatRequest
Expand All @@ -30,14 +31,16 @@ class ChatServiceTest(
val chatRepository = mockk<ChatRepository>()
val chatRoomRepository = mockk<ChatRoomRepository>()
val chatCustomRepository = mockk<ChatCustomRepository>()
val chatService = ChatService(chatRepository, chatRoomRepository, chatCustomRepository)
val accessVerifier = mockk<AccessVerifier>()
val chatService = ChatService(chatRepository, chatRoomRepository, chatCustomRepository, accessVerifier)

test("createChat 은 새 RoomChat을 저장해야 한다") {
// Given
val request = CreateChatRequest(content = ChatTest.CONTENT, contextId = ContextTest.TEST_ROOM_ID, type = ChatType.ROOM)
val userId = CommonTest.TEST_USER_ID
val chatId = ChatTest.TEST_CHAT_ID
val roomChat = Chat(chatId, userId, ChatType.ROOM, ContextTest.TEST_ROOM_ID, request.content)
every { accessVerifier.verifyChatRoomAccess(any(), any()) } just runs
every { chatRepository.save(any()) } returns roomChat
every { chatRoomRepository.existsByIdAndMembersContaining(any(), any()) } returns true

Expand All @@ -48,10 +51,12 @@ class ChatServiceTest(
verify { chatRepository.save(any()) }
}

// TODO : AccessVerifier의 Test Code로 옮기기
test("getRoomChats 은 권한이 없는 사용자에게 에러 발생") {
// Given
val chatRoomId = ContextTest.TEST_ROOM_ID
val userId = CommonTest.TEST_ANOTHER_USER_ID
every { accessVerifier.verifyChatRoomAccess(any(), any()) } throws GlobalException(ErrorCode.FORBIDDEN_CHATROOM)
every { chatRoomRepository.existsByIdAndMembersContaining(chatRoomId, userId) } returns false

// When & Then
Expand All @@ -65,6 +70,7 @@ class ChatServiceTest(
errorCode shouldBe ErrorCode.FORBIDDEN_CHATROOM
}

// TODO : AccessVerifier의 Test Code로 옮기기
test("getServerChats 은 권한이 없는 사용자에게 에러 발생") {
// Given
val serverId1 = "test_server_id"
Expand All @@ -88,6 +94,7 @@ class ChatServiceTest(
)

// When & Then
every { accessVerifier.verifyServerAccess(any(), any()) } throws GlobalException(ErrorCode.FORBIDDEN_SERVER)
val exception =
shouldThrow<GlobalException> {
chatService.getServerChats(serverId1, userId, 0, 1, serverList)
Expand Down
2 changes: 1 addition & 1 deletion chat/src/test/kotlin/kpring/chat/example/SampleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SampleTest(
) : DescribeSpec({

beforeTest {
chatRepository.deleteAll()
// chatRepository.deleteAll()
}

it("query dsl 적용 테스트") {
Expand Down

0 comments on commit 815e71b

Please sign in to comment.