diff --git a/bootstrap/http/src/test/kotlin/com/studentcenter/weave/bootstrap/meeting/controller/MeetingEventHandlerTest.kt b/bootstrap/http/src/test/kotlin/com/studentcenter/weave/bootstrap/meeting/controller/MeetingEventHandlerTest.kt deleted file mode 100644 index 1d39812a..00000000 --- a/bootstrap/http/src/test/kotlin/com/studentcenter/weave/bootstrap/meeting/controller/MeetingEventHandlerTest.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.studentcenter.weave.bootstrap.meeting.controller - -import com.ninjasquad.springmockk.MockkBean -import com.studentcenter.weave.application.chat.port.inbound.CreateChatRoom -import com.studentcenter.weave.bootstrap.integration.IntegrationTestDescribeSpec -import com.studentcenter.weave.domain.meeting.entity.MeetingFixtureFactory -import com.studentcenter.weave.domain.meeting.enums.MeetingStatus -import com.studentcenter.weave.domain.meeting.event.MeetingCompletedEvent.Companion.createCompletedEvent -import io.kotest.core.annotation.DisplayName -import io.mockk.every -import io.mockk.just -import io.mockk.runs -import io.mockk.verify -import org.springframework.context.ApplicationEventPublisher - -@DisplayName("MeetingEventHandler 테스트") -class MeetingEventHandlerTest( - private val applicationEventPublisher: ApplicationEventPublisher, - @MockkBean - private val createChatRoom: CreateChatRoom, -) : IntegrationTestDescribeSpec({ - - describe("미팅 완료 이벤트를 전달 받으면") { - it("새로운 채팅방을 생성한다") { - // arrange - val meetingFixture = MeetingFixtureFactory.create(status = MeetingStatus.COMPLETED) - val meetingCompletedEvent = meetingFixture.createCompletedEvent() - - every { createChatRoom.invoke(meetingCompletedEvent) } just runs - - // act - applicationEventPublisher.publishEvent(meetingCompletedEvent) - - // assert - verify { createChatRoom.invoke(meetingCompletedEvent) } - } - } - -}) diff --git a/domain/src/main/kotlin/com/studentcenter/weave/domain/chat/entity/ChatMember.kt b/domain/src/main/kotlin/com/studentcenter/weave/domain/chat/entity/ChatMember.kt new file mode 100644 index 00000000..8b035518 --- /dev/null +++ b/domain/src/main/kotlin/com/studentcenter/weave/domain/chat/entity/ChatMember.kt @@ -0,0 +1,21 @@ +package com.studentcenter.weave.domain.chat.entity + +import com.studentcenter.weave.domain.common.DomainEntity +import com.studentcenter.weave.support.common.uuid.UuidCreator +import java.util.* + +data class ChatMember( + override val id: UUID = UuidCreator.create(), + val userId: UUID, + val lastReadMessageId: UUID? = null, +) : DomainEntity { + + companion object { + + fun create(userId: UUID): ChatMember { + return ChatMember(userId = userId) + } + + } + +} diff --git a/domain/src/main/kotlin/com/studentcenter/weave/domain/chat/entity/ChatRoom.kt b/domain/src/main/kotlin/com/studentcenter/weave/domain/chat/entity/ChatRoom.kt index 58077879..5538d47b 100644 --- a/domain/src/main/kotlin/com/studentcenter/weave/domain/chat/entity/ChatRoom.kt +++ b/domain/src/main/kotlin/com/studentcenter/weave/domain/chat/entity/ChatRoom.kt @@ -12,8 +12,18 @@ data class ChatRoom( val receivingTeamId: UUID, val requestingTeamId: UUID, val createdAt: LocalDateTime = LocalDateTime.now(), + val members: Set = emptySet(), ) : AggregateRoot { + fun addMember(userId: UUID): ChatRoom { + require(members.none { it.userId == userId }) { + "이미 채팅방에 참여하고 있는 사용자입니다." + } + + val newMember: ChatMember = ChatMember.create(userId) + return copy(members = members + newMember) + } + companion object { fun create(meeting: Meeting): ChatRoom { diff --git a/domain/src/test/kotlin/com/studentcenter/weave/domain/chat/entity/ChatRoomTest.kt b/domain/src/test/kotlin/com/studentcenter/weave/domain/chat/entity/ChatRoomTest.kt index 5de10f65..c7da8e64 100644 --- a/domain/src/test/kotlin/com/studentcenter/weave/domain/chat/entity/ChatRoomTest.kt +++ b/domain/src/test/kotlin/com/studentcenter/weave/domain/chat/entity/ChatRoomTest.kt @@ -2,16 +2,18 @@ package com.studentcenter.weave.domain.chat.entity import com.studentcenter.weave.domain.meeting.entity.MeetingFixtureFactory import com.studentcenter.weave.domain.meeting.enums.MeetingStatus +import com.studentcenter.weave.support.common.uuid.UuidCreator import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.annotation.DisplayName import io.kotest.core.spec.style.DescribeSpec import io.kotest.matchers.shouldBe +import java.util.* @DisplayName("ChatRoomTest") class ChatRoomTest : DescribeSpec({ - describe("채팅방 생성 테스트") { + describe("채팅방 생성") { context("미팅이 매칭된 상태일 경우") { it("미팅 팀을 통해 채팅방을 생성한다") { // arrange @@ -49,4 +51,37 @@ class ChatRoomTest : DescribeSpec({ } } + describe("채팅 멤버 추가") { + context("멤버가 존재하지 않는 경우") { + it("멤버를 추가한다") { + // arrange + val chatRoom: ChatRoom = ChatRoomFixtureFactory.create() + val userId: UUID = UuidCreator.create() + + // act + val newMember: ChatRoom = chatRoom.addMember(userId) + + // assert + newMember.members.size shouldBe 1 + } + } + + context("멤버가 이미 존재하는 경우") { + it("예외를 발생시킨다.") { + // arrange + val userId: UUID = UuidCreator.create() + + val chatMember: ChatMember = ChatMemberFixtureFactory.create(userId = userId) + val chatRoom: ChatRoom = ChatRoomFixtureFactory.create( + members = setOf(chatMember) + ) + + // act, assert + shouldThrow { + chatRoom.addMember(userId) + } + } + } + } + }) diff --git a/domain/src/testFixtures/kotlin/com/studentcenter/weave/domain/chat/entity/ChatMemberFixtureFactory.kt b/domain/src/testFixtures/kotlin/com/studentcenter/weave/domain/chat/entity/ChatMemberFixtureFactory.kt new file mode 100644 index 00000000..4a8cbe64 --- /dev/null +++ b/domain/src/testFixtures/kotlin/com/studentcenter/weave/domain/chat/entity/ChatMemberFixtureFactory.kt @@ -0,0 +1,20 @@ +package com.studentcenter.weave.domain.chat.entity + +import com.studentcenter.weave.support.common.uuid.UuidCreator +import java.util.* + +object ChatMemberFixtureFactory { + + fun create( + id: UUID = UuidCreator.create(), + userId: UUID = UuidCreator.create(), + lastReadMessageId: UUID? = null, + ): ChatMember { + return ChatMember( + id = id, + userId = userId, + lastReadMessageId = lastReadMessageId, + ) + } + +} diff --git a/domain/src/testFixtures/kotlin/com/studentcenter/weave/domain/chat/entity/ChatRoomFixtureFactory.kt b/domain/src/testFixtures/kotlin/com/studentcenter/weave/domain/chat/entity/ChatRoomFixtureFactory.kt index deb32a44..dc63247e 100644 --- a/domain/src/testFixtures/kotlin/com/studentcenter/weave/domain/chat/entity/ChatRoomFixtureFactory.kt +++ b/domain/src/testFixtures/kotlin/com/studentcenter/weave/domain/chat/entity/ChatRoomFixtureFactory.kt @@ -12,6 +12,7 @@ object ChatRoomFixtureFactory { requestingTeamId: UUID = UuidCreator.create(), receivingTeamId: UUID = UuidCreator.create(), createdAt: LocalDateTime = LocalDateTime.now(), + members: Set = emptySet(), ): ChatRoom { return ChatRoom( id = id, @@ -19,7 +20,8 @@ object ChatRoomFixtureFactory { requestingTeamId = requestingTeamId, receivingTeamId = receivingTeamId, createdAt = createdAt, + members = members ) - } + }