diff --git a/chat/src/main/kotlin/kpring/chat/chat/model/Chat.kt b/chat/src/main/kotlin/kpring/chat/chat/model/Chat.kt index 10125c8c..802ed60e 100644 --- a/chat/src/main/kotlin/kpring/chat/chat/model/Chat.kt +++ b/chat/src/main/kotlin/kpring/chat/chat/model/Chat.kt @@ -1,6 +1,7 @@ package kpring.chat.chat.model import kpring.chat.NoArg +import kpring.chat.chatroom.model.EventType import kpring.chat.global.model.BaseTime import kpring.core.chat.model.ChatType import org.springframework.data.annotation.Id @@ -12,7 +13,8 @@ class Chat( @Id val id: String? = null, val userId: String, - val type: ChatType, + val chatType: ChatType, + val eventType: EventType, // roomId or serverId val contextId: String, var content: String, diff --git a/chat/src/main/kotlin/kpring/chat/chat/service/ChatService.kt b/chat/src/main/kotlin/kpring/chat/chat/service/ChatService.kt index 905b1d00..2a09cc9f 100644 --- a/chat/src/main/kotlin/kpring/chat/chat/service/ChatService.kt +++ b/chat/src/main/kotlin/kpring/chat/chat/service/ChatService.kt @@ -4,6 +4,7 @@ import kpring.chat.chat.api.v1.WebSocketChatController import kpring.chat.chat.model.Chat import kpring.chat.chat.repository.ChatCustomRepository import kpring.chat.chat.repository.ChatRepository +import kpring.chat.chatroom.model.EventType import kpring.chat.chatroom.repository.ChatRoomRepository import kpring.chat.global.exception.ErrorCode import kpring.chat.global.exception.GlobalException @@ -38,7 +39,8 @@ class ChatService( chatRepository.save( Chat( userId = userId, - type = request.type, + chatType = request.type, + eventType = EventType.CHAT, contextId = request.contextId, content = request.content, ), @@ -56,7 +58,8 @@ class ChatService( chatRepository.save( Chat( userId = userId, - type = request.type, + chatType = request.type, + eventType = EventType.CHAT, contextId = request.contextId, content = request.content, ), diff --git a/chat/src/main/kotlin/kpring/chat/chatroom/api/v1/ChatRoomController.kt b/chat/src/main/kotlin/kpring/chat/chatroom/api/v1/ChatRoomController.kt index fc061c8f..56a5c881 100644 --- a/chat/src/main/kotlin/kpring/chat/chatroom/api/v1/ChatRoomController.kt +++ b/chat/src/main/kotlin/kpring/chat/chatroom/api/v1/ChatRoomController.kt @@ -14,6 +14,7 @@ class ChatRoomController( private val chatRoomService: ChatRoomService, private val authClient: AuthClient, ) { + @Deprecated("WebSocketChatRoomController의 createChatRoom을 이용") @PostMapping("/chatroom") fun createChatRoom( @Validated @RequestBody request: CreateChatRoomRequest, @@ -25,6 +26,7 @@ class ChatRoomController( return ResponseEntity.ok().body(result) } + @Deprecated("WebSocketChatRoomController의 exitChatRoom을 이용") @PatchMapping("/chatroom/exit/{chatRoomId}") fun exitChatRoom( @PathVariable("chatRoomId") chatRoomId: String, @@ -46,6 +48,7 @@ class ChatRoomController( return ResponseEntity.ok().body(ApiResponse(data = result)) } + @Deprecated("WebSocketChatRoomController의 joinChatRoom을 이용") @PatchMapping("/chatroom/{code}/join") fun joinChatRoom( @PathVariable("code") code: String, diff --git a/chat/src/main/kotlin/kpring/chat/chatroom/api/v1/WebSocketChatRoomController.kt b/chat/src/main/kotlin/kpring/chat/chatroom/api/v1/WebSocketChatRoomController.kt new file mode 100644 index 00000000..89253fdc --- /dev/null +++ b/chat/src/main/kotlin/kpring/chat/chatroom/api/v1/WebSocketChatRoomController.kt @@ -0,0 +1,53 @@ +package kpring.chat.chatroom.api.v1 + +import kpring.chat.chatroom.service.ChatRoomService +import kpring.core.chat.chatroom.dto.request.CreateChatRoomRequest +import kpring.core.global.dto.response.ApiResponse +import lombok.RequiredArgsConstructor +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.springframework.messaging.handler.annotation.MessageMapping +import org.springframework.messaging.handler.annotation.Payload +import org.springframework.messaging.simp.SimpMessagingTemplate +import org.springframework.stereotype.Controller +import org.springframework.validation.annotation.Validated +import java.security.Principal + +@Controller +@RequiredArgsConstructor +class WebSocketChatRoomController( + private val chatRoomService: ChatRoomService, + private val simpMessagingTemplate: SimpMessagingTemplate, +) { + private val logger: Logger = LoggerFactory.getLogger(WebSocketChatRoomController::class.java) + + @MessageMapping("/chatroom/create") + fun createChatRoom( + @Payload @Validated request: CreateChatRoomRequest, + principal: Principal, + ) { + val userId = principal.name + val result = chatRoomService.createChatRoom(request, userId) + simpMessagingTemplate.convertAndSend("/topic/chatroom/${result.chatRoomId}", ApiResponse(status = 200, data = result.chatResponse)) + } + + @MessageMapping("/chatroom/exit") + fun exitChatRoom( + @Payload chatRoomId: String, + principal: Principal, + ) { + val userId = principal.name + val result = chatRoomService.exitChatRoom(chatRoomId, userId) + simpMessagingTemplate.convertAndSend("/topic/chatroom/${result.chatRoomId}", ApiResponse(status = 200, data = result.chatResponse)) + } + + @MessageMapping("/chatroom/join") + fun joinChatRoom( + @Payload code: String, + principal: Principal, + ) { + val userId = principal.name + val result = chatRoomService.joinChatRoom(code, userId) + simpMessagingTemplate.convertAndSend("/topic/chatroom/${result.chatRoomId}", ApiResponse(status = 200, data = result.chatResponse)) + } +} diff --git a/chat/src/main/kotlin/kpring/chat/chatroom/dto/ChatWrapper.kt b/chat/src/main/kotlin/kpring/chat/chatroom/dto/ChatWrapper.kt new file mode 100644 index 00000000..4f8a7bc7 --- /dev/null +++ b/chat/src/main/kotlin/kpring/chat/chatroom/dto/ChatWrapper.kt @@ -0,0 +1,8 @@ +package kpring.chat.chatroom.dto + +import kpring.core.chat.chat.dto.response.ChatResponse + +data class ChatWrapper( + val chatRoomId: String, + val chatResponse: ChatResponse, +) diff --git a/chat/src/main/kotlin/kpring/chat/chatroom/model/EventType.kt b/chat/src/main/kotlin/kpring/chat/chatroom/model/EventType.kt new file mode 100644 index 00000000..fdfb61ee --- /dev/null +++ b/chat/src/main/kotlin/kpring/chat/chatroom/model/EventType.kt @@ -0,0 +1,9 @@ +package kpring.chat.chatroom.model + +enum class EventType(val type: String) { + ENTER("ENTER"), + INVITATION("INVITATION"), + CREATED("CREATED"), + CHAT("CHAT"), + EXIT("EXIT"), +} diff --git a/chat/src/main/kotlin/kpring/chat/chatroom/service/ChatRoomService.kt b/chat/src/main/kotlin/kpring/chat/chatroom/service/ChatRoomService.kt index b301ec2f..cc43fbf0 100644 --- a/chat/src/main/kotlin/kpring/chat/chatroom/service/ChatRoomService.kt +++ b/chat/src/main/kotlin/kpring/chat/chatroom/service/ChatRoomService.kt @@ -1,43 +1,55 @@ package kpring.chat.chatroom.service +import kpring.chat.chat.model.Chat +import kpring.chat.chat.repository.ChatRepository +import kpring.chat.chatroom.dto.ChatWrapper import kpring.chat.chatroom.dto.InvitationInfo import kpring.chat.chatroom.model.ChatRoom +import kpring.chat.chatroom.model.EventType import kpring.chat.chatroom.repository.ChatRoomRepository import kpring.chat.global.exception.ErrorCode import kpring.chat.global.exception.GlobalException +import kpring.chat.global.util.AccessVerifier +import kpring.core.chat.chat.dto.response.ChatResponse import kpring.core.chat.chat.dto.response.InvitationResponse import kpring.core.chat.chatroom.dto.request.CreateChatRoomRequest +import kpring.core.chat.model.ChatType +import kpring.core.chat.model.MessageType import org.springframework.stereotype.Service @Service class ChatRoomService( private val chatRoomRepository: ChatRoomRepository, + private val chatRepository: ChatRepository, private val invitationService: InvitationService, + private val accessVerifier: AccessVerifier, ) { fun createChatRoom( request: CreateChatRoomRequest, userId: String, - ) { + ): ChatWrapper { val chatRoom = ChatRoom(members = mutableSetOf(userId)) chatRoom.addUsers(request.users) - chatRoomRepository.save(chatRoom) + val saved = chatRoomRepository.save(chatRoom) + return createChatRoomMessage(saved.id!!, "방이 생성되었습니다.", EventType.CREATED) } fun exitChatRoom( chatRoomId: String, userId: String, - ) { - verifyChatRoomAccess(chatRoomId, userId) + ): ChatWrapper { + accessVerifier.verifyChatRoomAccess(chatRoomId, userId) val chatRoom: ChatRoom = getChatRoom(chatRoomId) chatRoom.removeUser(userId) chatRoomRepository.save(chatRoom) + return createChatRoomMessage(chatRoom.id!!, "${userId}님이 방에서 나갔습니다.", EventType.EXIT) // TODO : 닉네임으로 변경 } fun getChatRoomInvitation( chatRoomId: String, userId: String, ): InvitationResponse { - verifyChatRoomAccess(chatRoomId, userId) + accessVerifier.verifyChatRoomAccess(chatRoomId, userId) var code = invitationService.getInvitation(userId, chatRoomId) if (code == null) { code = invitationService.setInvitation(userId, chatRoomId) @@ -49,13 +61,13 @@ class ChatRoomService( fun joinChatRoom( code: String, userId: String, - ): Boolean { + ): ChatWrapper { val invitationInfo = invitationService.getInvitationInfoFromCode(code) verifyInvitationExistence(invitationInfo) val chatRoom = getChatRoom(invitationInfo.chatRoomId) chatRoom.addUser(userId) chatRoomRepository.save(chatRoom) - return true + return createChatRoomMessage(chatRoom.id!!, "${userId}님이 방에 들어왔습니다.", EventType.ENTER) // TODO : 닉네임으로 변경 } private fun verifyInvitationExistence(invitationInfo: InvitationInfo) { @@ -64,13 +76,25 @@ class ChatRoomService( } } - private fun verifyChatRoomAccess( + fun createChatRoomMessage( chatRoomId: String, - userId: String, - ) { - if (!chatRoomRepository.existsByIdAndMembersContaining(chatRoomId, userId)) { - throw GlobalException(ErrorCode.FORBIDDEN_CHATROOM) - } + content: String, + eventType: EventType, + ): ChatWrapper { + val chat = + chatRepository.save( + Chat( + userId = "", + chatType = ChatType.ROOM, + eventType = eventType, + contextId = chatRoomId, + content = content, + ), + ) + return ChatWrapper( + chatRoomId, + ChatResponse(chat.id!!, chat.userId, MessageType.CHAT, chat.isEdited(), chat.updatedAt.toString(), chat.content), + ) } private fun getChatRoom(chatRoomId: String): ChatRoom { diff --git a/chat/src/main/resources/static/chat.html b/chat/src/main/resources/static/chatSample.html similarity index 63% rename from chat/src/main/resources/static/chat.html rename to chat/src/main/resources/static/chatSample.html index 62018c82..0d985598 100644 --- a/chat/src/main/resources/static/chat.html +++ b/chat/src/main/resources/static/chatSample.html @@ -1,7 +1,7 @@ - WebSocket Chat + WebSocket Chat Application @@ -12,6 +12,7 @@

WebSocket Chat Application

+
@@ -20,11 +21,27 @@

WebSocket Chat Application

+

Create Chat Room

+ + + +

Exit Chat Room

+ + + +

Invite to Chat Room

+ + + +

Join Chat Room

+ + +

Create Chat

@@ -54,14 +71,16 @@

Delete Chat

let stompClient = null; const getToken = () => document.getElementById('authToken').value; + const getUserId = () => document.getElementById('userId').value; const getChatRoomId = () => document.getElementById('chatroomId').value; function connectWebSocket() { const token = getToken(); const chatroomId = getChatRoomId(); + const userId = getUserId(); - if (!token || !chatroomId) { - alert('Authorization token and Chatroom ID are required!'); + if (!token || !chatroomId || !userId) { + alert('Authorization token, User ID, and Chatroom ID are required!'); return; } @@ -78,20 +97,22 @@

Delete Chat

stompClient.subscribe(`/topic/chatroom/${chatroomId}`, function (message) { console.log("Received message:", message.body); }, { - Authorization: `Bearer ${token}`, - ContextId: chatroomId, - Context: 'ROOM' + Authorization: `Bearer ${token}` }); enableButtonsAfterConnect(token, chatroomId); }, function(error) { console.error('Connection error:', error); - alert('Connection failed. Please check your token and chat room ID.'); + alert('Connection failed. Please check your token, user ID, and chat room ID.'); }); } function enableButtonsAfterConnect(token, chatroomId) { document.getElementById("sendBtn").disabled = false; + document.getElementById("createChatRoomBtn").disabled = false; + document.getElementById("exitChatRoomBtn").disabled = false; + document.getElementById("inviteChatRoomBtn").disabled = false; + document.getElementById("joinChatRoomBtn").disabled = false; document.getElementById("createChatBtn").disabled = false; document.getElementById("getChatsBtn").disabled = false; document.getElementById("updateChatBtn").disabled = false; @@ -108,7 +129,50 @@

Delete Chat

} }); - // Creating a new chat message + document.getElementById("createChatRoomBtn").addEventListener("click", function () { + const content = document.getElementById("createChatRoomContent").value; + if (content.trim() !== "") { + stompClient.send(`/app/chatroom/create`, {'Authorization': token}, + JSON.stringify({content: content, chatRoomId: chatroomId}) + ); + document.getElementById("createChatRoomContent").value = ""; + console.log('Chat room created successfully!'); + } + }); + + document.getElementById("exitChatRoomBtn").addEventListener("click", function () { + const chatRoomId = document.getElementById("exitChatRoomId").value; + if (chatRoomId) { + stompClient.send(`/app/chatroom/exit`, {'Authorization': token}, + JSON.stringify({chatRoomId: chatRoomId}) + ); + document.getElementById("exitChatRoomId").value = ""; + console.log('Exited chat room successfully!'); + } + }); + + document.getElementById("inviteChatRoomBtn").addEventListener("click", function () { + const chatRoomId = document.getElementById("inviteChatRoomId").value; + if (chatRoomId) { + stompClient.send(`/app/chatroom/invite`, {'Authorization': token}, + JSON.stringify({chatRoomId: chatRoomId}) + ); + document.getElementById("inviteChatRoomId").value = ""; + console.log('Invitation sent successfully!'); + } + }); + + document.getElementById("joinChatRoomBtn").addEventListener("click", function () { + const code = document.getElementById("joinChatRoomCode").value; + if (code) { + stompClient.send(`/app/chatroom/join`, {'Authorization': token}, + JSON.stringify({code: code}) + ); + document.getElementById("joinChatRoomCode").value = ""; + console.log('Joined chat room successfully!'); + } + }); + document.getElementById("createChatBtn").addEventListener("click", function () { const content = document.getElementById("chatContent").value; const type = document.getElementById("chatType").value; @@ -121,7 +185,6 @@

Delete Chat

} }); - // Fetching chat messages document.getElementById("getChatsBtn").addEventListener("click", function () { const id = document.getElementById("getId").value; const type = document.getElementById("getChatType").value; @@ -134,7 +197,6 @@

Delete Chat

} }); - // Updating a chat document.getElementById("updateChatBtn").addEventListener("click", function () { const chatId = document.getElementById("updateChatId").value; const content = document.getElementById("updateContent").value; @@ -148,7 +210,6 @@

Delete Chat

} }); - // Deleting a chat document.getElementById("deleteChatBtn").addEventListener("click", function () { const chatId = document.getElementById("deleteChatId").value; const type = document.getElementById("deleteChatType").value; @@ -164,6 +225,10 @@

Delete Chat

document.addEventListener('DOMContentLoaded', function () { document.getElementById("sendBtn").disabled = true; + document.getElementById("createChatRoomBtn").disabled = true; + document.getElementById("exitChatRoomBtn").disabled = true; + document.getElementById("inviteChatRoomBtn").disabled = true; + document.getElementById("joinChatRoomBtn").disabled = true; document.getElementById("createChatBtn").disabled = true; document.getElementById("getChatsBtn").disabled = true; document.getElementById("updateChatBtn").disabled = true; diff --git a/chat/src/test/kotlin/kpring/chat/chat/ChatServiceTest.kt b/chat/src/test/kotlin/kpring/chat/chat/ChatServiceTest.kt index 9fc88d38..5617538d 100644 --- a/chat/src/test/kotlin/kpring/chat/chat/ChatServiceTest.kt +++ b/chat/src/test/kotlin/kpring/chat/chat/ChatServiceTest.kt @@ -8,6 +8,7 @@ import kpring.chat.chat.model.Chat import kpring.chat.chat.repository.ChatCustomRepository import kpring.chat.chat.repository.ChatRepository import kpring.chat.chat.service.ChatService +import kpring.chat.chatroom.model.EventType import kpring.chat.chatroom.repository.ChatRoomRepository import kpring.chat.global.ChatTest import kpring.chat.global.CommonTest @@ -39,7 +40,7 @@ class ChatServiceTest( 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) + val roomChat = Chat(chatId, userId, ChatType.ROOM, EventType.CHAT, 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 @@ -118,6 +119,7 @@ class ChatServiceTest( chatId, userId, ChatType.ROOM, + EventType.CHAT, roomId, "content", ) @@ -148,6 +150,7 @@ class ChatServiceTest( chatId, userId, ChatType.SERVER, + EventType.CHAT, serverId, "content", ) @@ -183,6 +186,7 @@ class ChatServiceTest( chatId, userId, ChatType.ROOM, + EventType.CHAT, roomId, "content", ) @@ -218,6 +222,7 @@ class ChatServiceTest( chatId, userId, ChatType.SERVER, + EventType.CHAT, serverId, "content", ) @@ -252,7 +257,8 @@ class ChatServiceTest( Chat( id = chatId, userId = userId, - type = ChatType.SERVER, + eventType = EventType.CHAT, + chatType = ChatType.SERVER, contextId = serverId, content = "content", ) @@ -285,7 +291,8 @@ class ChatServiceTest( Chat( id = chatId, userId = userId, - ChatType.ROOM, + chatType = ChatType.ROOM, + eventType = EventType.CHAT, contextId = roomId, content = "content", ) diff --git a/chat/src/test/kotlin/kpring/chat/chatroom/ChatRoomServiceTest.kt b/chat/src/test/kotlin/kpring/chat/chatroom/ChatRoomServiceTest.kt index 9105cf5e..7de9b227 100644 --- a/chat/src/test/kotlin/kpring/chat/chatroom/ChatRoomServiceTest.kt +++ b/chat/src/test/kotlin/kpring/chat/chatroom/ChatRoomServiceTest.kt @@ -2,28 +2,36 @@ package kpring.chat.chatroom import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.collections.shouldNotContain -import io.mockk.every -import io.mockk.mockk -import io.mockk.verify +import io.mockk.* +import kpring.chat.chat.model.Chat +import kpring.chat.chat.repository.ChatRepository import kpring.chat.chatroom.model.ChatRoom +import kpring.chat.chatroom.model.EventType import kpring.chat.chatroom.repository.ChatRoomRepository import kpring.chat.chatroom.service.ChatRoomService import kpring.chat.chatroom.service.InvitationService import kpring.chat.global.CommonTest import kpring.chat.global.ContextTest +import kpring.chat.global.util.AccessVerifier import kpring.core.chat.chatroom.dto.request.CreateChatRoomRequest +import kpring.core.chat.model.ChatType import java.util.* class ChatRoomServiceTest : FunSpec({ val chatRoomRepository = mockk() + val chatRepository = mockk() val invitationService = mockk() - val chatRoomService = ChatRoomService(chatRoomRepository, invitationService) + val accessVerifier = mockk() + + val chatRoomService = ChatRoomService(chatRoomRepository, chatRepository, invitationService, accessVerifier) test("createChatRoom 는 새 ChatRoom을 저장해야 한다") { // Given val request = CreateChatRoomRequest(ContextTest.TEST_MEMBERS) - val chatRoom = ChatRoom() + val chatRoom = ChatRoom("test_chatroom_id", mutableSetOf(CommonTest.TEST_USER_ID)) + val chat = Chat("chat_id", CommonTest.TEST_USER_ID, ChatType.ROOM, EventType.CHAT, ContextTest.TEST_ROOM_ID, "content") + every { chatRepository.save(any()) } returns chat every { chatRoomRepository.save(any()) } returns chatRoom // When @@ -45,6 +53,9 @@ class ChatRoomServiceTest : FunSpec({ every { chatRoomRepository.findById(chatRoom.id!!) } returns Optional.of(chatRoom) every { chatRoomRepository.save(any()) } returns chatRoom every { chatRoomRepository.existsByIdAndMembersContaining(any(), CommonTest.TEST_USER_ID) } returns true + every { accessVerifier.verifyChatRoomAccess(any(), any()) } just runs + val chat = Chat("chat_id", CommonTest.TEST_USER_ID, ChatType.ROOM, EventType.CHAT, ContextTest.TEST_ROOM_ID, "content") + every { chatRepository.save(any()) } returns chat // When chatRoomService.exitChatRoom(chatRoom.id!!, CommonTest.TEST_USER_ID) diff --git a/chat/src/test/kotlin/kpring/chat/chatroom/api/v1/ChatRoomControllerTest.kt b/chat/src/test/kotlin/kpring/chat/chatroom/api/v1/ChatRoomControllerTest.kt index 2b82a60d..62e8add0 100644 --- a/chat/src/test/kotlin/kpring/chat/chatroom/api/v1/ChatRoomControllerTest.kt +++ b/chat/src/test/kotlin/kpring/chat/chatroom/api/v1/ChatRoomControllerTest.kt @@ -5,7 +5,10 @@ import com.ninjasquad.springmockk.MockkBean import io.kotest.core.spec.style.DescribeSpec import io.mockk.every import io.mockk.junit5.MockKExtension +import kpring.chat.chat.model.Chat import kpring.chat.chatroom.api.v1.ChatRoomController +import kpring.chat.chatroom.dto.ChatWrapper +import kpring.chat.chatroom.model.EventType import kpring.chat.chatroom.service.ChatRoomService import kpring.chat.global.CommonTest import kpring.chat.global.ContextTest @@ -13,7 +16,10 @@ import kpring.chat.global.config.TestMongoConfig import kpring.core.auth.client.AuthClient import kpring.core.auth.dto.response.TokenInfo import kpring.core.auth.enums.TokenType +import kpring.core.chat.chat.dto.response.ChatResponse import kpring.core.chat.chat.dto.response.InvitationResponse +import kpring.core.chat.model.ChatType +import kpring.core.chat.model.MessageType import kpring.core.global.dto.response.ApiResponse import kpring.test.restdoc.dsl.restDoc import kpring.test.restdoc.json.JsonDataType @@ -113,7 +119,17 @@ class ChatRoomControllerTest( val chatRoomId = ContextTest.TEST_ROOM_ID val userId = CommonTest.TEST_USER_ID val code = "666fcd76027b2432e4b49a0f" - val data = true + val content = "${userId}님이 방에 들어왔습니다." + val chat = + Chat( + userId = "", + chatType = ChatType.ROOM, + eventType = EventType.ENTER, + contextId = chatRoomId, + content = content, + ) + val data = + ChatWrapper(chatRoomId, ChatResponse("1", userId, MessageType.CHAT, chat.isEdited(), chat.updatedAt.toString(), chat.content)) every { authClient.getTokenInfo(any()) } returns ApiResponse( diff --git a/chat/src/test/kotlin/kpring/chat/example/SampleTest.kt b/chat/src/test/kotlin/kpring/chat/example/SampleTest.kt index 1cc35c38..1358ec29 100644 --- a/chat/src/test/kotlin/kpring/chat/example/SampleTest.kt +++ b/chat/src/test/kotlin/kpring/chat/example/SampleTest.kt @@ -6,6 +6,7 @@ import io.kotest.matchers.shouldBe import kpring.chat.chat.model.Chat import kpring.chat.chat.model.QChat import kpring.chat.chat.repository.ChatRepository +import kpring.chat.chatroom.model.EventType import kpring.core.chat.model.ChatType import kpring.test.testcontainer.SpringTestContext import org.springframework.boot.test.context.SpringBootTest @@ -29,7 +30,13 @@ class SampleTest( val chat = QChat.chat repeat(5) { idx -> chatRepository.save( - Chat(userId = "testUserId", type = ChatType.ROOM, contextId = "testRoomId", content = "testContent$idx"), + Chat( + userId = "testUserId", + chatType = ChatType.ROOM, + eventType = EventType.CHAT, + contextId = "testRoomId", + content = "testContent$idx", + ), ) } @@ -54,7 +61,13 @@ class SampleTest( chatRepository.deleteAll() repeat(5) { idx -> chatRepository.save( - Chat(userId = "testUserId", type = ChatType.ROOM, contextId = "testRoomId", content = "testContent$idx"), + Chat( + userId = "testUserId", + chatType = ChatType.ROOM, + eventType = EventType.CHAT, + contextId = "testRoomId", + content = "testContent$idx", + ), ) } diff --git a/core/src/main/kotlin/kpring/core/chat/model/MessageType.kt b/core/src/main/kotlin/kpring/core/chat/model/MessageType.kt index 8add5cf0..4d548ca4 100644 --- a/core/src/main/kotlin/kpring/core/chat/model/MessageType.kt +++ b/core/src/main/kotlin/kpring/core/chat/model/MessageType.kt @@ -1,10 +1,7 @@ package kpring.core.chat.model enum class MessageType(val type: String) { - ENTER("ENTER"), - INVITATION("INVITATION"), CHAT("CHAT"), UPDATE("UPDATE"), DELETE("DELETE"), - OUT("OUT"), }