Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

[WEAV-350] 채팅방 멤버 도메인 설계 #258

Merged
merged 9 commits into from
Apr 27, 2024

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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,
rilac1 marked this conversation as resolved.
Show resolved Hide resolved
val lastReadMessageId: UUID? = null,
) : DomainEntity {

companion object {

fun create(userId: UUID): ChatMember {
return ChatMember(userId = userId)
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@ data class ChatRoom(
val receivingTeamId: UUID,
val requestingTeamId: UUID,
val createdAt: LocalDateTime = LocalDateTime.now(),
val members: Set<ChatMember> = 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<IllegalArgumentException> {
chatRoom.addMember(userId)
}
}
}
}

})
Original file line number Diff line number Diff line change
@@ -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,
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ object ChatRoomFixtureFactory {
requestingTeamId: UUID = UuidCreator.create(),
receivingTeamId: UUID = UuidCreator.create(),
createdAt: LocalDateTime = LocalDateTime.now(),
members: Set<ChatMember> = emptySet(),
): ChatRoom {
return ChatRoom(
id = id,
meetingId = meetingId,
requestingTeamId = requestingTeamId,
receivingTeamId = receivingTeamId,
createdAt = createdAt,
members = members
)

}

}
Loading