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

Commit

Permalink
[WEAV-000] 미팅 팀원 요약정보 생성 핫픽스 (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
waterfogSW authored Apr 25, 2024
1 parent f0a3fbd commit 665e13e
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,51 @@ package com.studentcenter.weave.application.meetingTeam.service.application

import com.studentcenter.weave.application.common.security.context.getCurrentUserAuthentication
import com.studentcenter.weave.application.meetingTeam.port.inbound.JoinMeetingTeam
import com.studentcenter.weave.application.meetingTeam.port.outbound.MeetingTeamMemberSummaryRepository
import com.studentcenter.weave.application.meetingTeam.port.outbound.MeetingTeamRepository
import com.studentcenter.weave.application.meetingTeam.util.MeetingTeamInvitationService
import com.studentcenter.weave.application.user.port.inbound.GetUser
import com.studentcenter.weave.domain.meetingTeam.entity.MeetingMember
import com.studentcenter.weave.domain.meetingTeam.entity.MeetingTeam
import com.studentcenter.weave.domain.meetingTeam.entity.MeetingTeamMemberSummary
import com.studentcenter.weave.domain.meetingTeam.entity.MeetingTeamMemberSummary.Companion.createSummary
import com.studentcenter.weave.domain.meetingTeam.exception.MeetingTeamException
import com.studentcenter.weave.domain.user.entity.User
import org.springframework.stereotype.Service
import java.util.*

@Service
class JoinMeetingTeamService(
private val meetingTeamRepository: MeetingTeamRepository,
private val meetingTeamInvitationService: MeetingTeamInvitationService,
private val meetingTeamMemberSummaryRepository: MeetingTeamMemberSummaryRepository,
private val getUser: GetUser,
) : JoinMeetingTeam {

override fun invoke(invitationCode: UUID) {
val currentUser = getCurrentUserAuthentication().userId
val currentUser: User = getCurrentUserAuthentication().userId
.let { getUser.getById(it) }

val meetingTeam = meetingTeamInvitationService
.findByInvitationCode(invitationCode)
?.let { meetingTeamRepository.getById(it.teamId) }
?: throw MeetingTeamException.InvitationCodeNotFound()

meetingTeam
val memberJoinedMeetingTeam: MeetingTeam = meetingTeam
.joinMember(currentUser)
.also { meetingTeamRepository.save(it) }

if (memberJoinedMeetingTeam.isPublished()) {
val summary: MeetingTeamMemberSummary =
memberJoinedMeetingTeam.createSummary { getUsersByMeetingMembers(it) }
meetingTeamMemberSummaryRepository.save(summary)
}
}

private fun getUsersByMeetingMembers(members: List<MeetingMember>): List<User> {
return members
.map { it.userId }
.let { getUser.getAllByIds(it) }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import com.studentcenter.weave.application.meetingTeam.util.impl.MeetingTeamInvi
import com.studentcenter.weave.application.meetingTeam.vo.MeetingTeamInvitationFixtureFactory
import com.studentcenter.weave.application.user.port.inbound.GetUserStub
import com.studentcenter.weave.application.user.vo.UserAuthenticationFixtureFactory
import com.studentcenter.weave.domain.meetingTeam.entity.MeetingTeam
import com.studentcenter.weave.domain.meetingTeam.entity.MeetingTeamFixtureFactory
import com.studentcenter.weave.domain.meetingTeam.entity.MeetingTeamMemberSummary
import com.studentcenter.weave.domain.user.entity.User
import com.studentcenter.weave.domain.user.entity.UserFixtureFactory
import com.studentcenter.weave.support.security.context.SecurityContextHolder
import com.studentcetner.weave.support.lock.DistributedLockTestInitializer
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.DescribeSpec
import io.kotest.matchers.shouldNotBe
import io.mockk.clearAllMocks
import org.junit.jupiter.api.DisplayName

@DisplayName("JoinMeetingTeam")
Expand All @@ -36,19 +37,15 @@ class JoinMeetingTeamServiceTest : DescribeSpec({
val sut = JoinMeetingTeamService(
meetingTeamRepository = meetingTeamRepository,
meetingTeamInvitationService = meetingTeamInvitationService,
meetingTeamMemberSummaryRepository = meetingTeamMemberSummaryRepository,
getUser = getUser,
)

beforeTest {
DistributedLockTestInitializer.mockExecutionByStatic()
}

afterTest {
meetingTeamRepository.clear()
meetingTeamMemberSummaryRepository.clear()
meetingTeamInvitationRepositorySpy.clear()
SecurityContextHolder.clearContext()
clearAllMocks()
}

describe("미팅 팀 입장 요청") {
Expand Down Expand Up @@ -94,6 +91,35 @@ class JoinMeetingTeamServiceTest : DescribeSpec({
savedMeetingTeam.members.find { it.userId == currentUser.id } shouldNotBe null
}
}

context("만약 팀원이 입장을 통해 팀이 공개 상태가 되는 경우") {
it("팀원 요약 정보가 저장된다.") {
// arrange
val currentUser: User = UserFixtureFactory.create()
val meetingTeam: MeetingTeam = MeetingTeamFixtureFactory
.create(
memberCount = 2,
leader = UserFixtureFactory.create(),
)
.also { meetingTeamRepository.save(it) }

UserAuthenticationFixtureFactory
.create(currentUser)
.let { SecurityContextHolder.setContext(UserSecurityContext(it)) }

val meetingTeamInvitation = MeetingTeamInvitationFixtureFactory
.create(teamId = meetingTeam.id)
.also { meetingTeamInvitationRepositorySpy.save(it) }

// act
sut.invoke(meetingTeamInvitation.invitationCode)

// assert
val savedMeetingTeam = meetingTeamRepository.getById(meetingTeam.id)
val savedSummary: MeetingTeamMemberSummary = meetingTeamMemberSummaryRepository.getByMeetingTeamId(savedMeetingTeam.id)
savedSummary shouldNotBe null
}
}
}

})
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ data class MeetingTeamMemberSummary(

companion object {

fun create(
meetingTeamId: UUID,
members: List<User>,
fun MeetingTeam.createSummary(
getUsersByMeetingMembers: (List<MeetingMember>) -> List<User>
): MeetingTeamMemberSummary {
require(members.isNotEmpty()) {
"팀에 속한 멤버가 존재해야 합니다."
}
val users: List<User> = getUsersByMeetingMembers(members)

return MeetingTeamMemberSummary(
meetingTeamId = meetingTeamId,
teamMbti = getTeamMbti(members),
youngestMemberBirthYear = getYoungestMemberBirthYear(members),
oldestMemberBirthYear = getOldestMemberBirthYear(members)
meetingTeamId = this.id,
teamMbti = getTeamMbti(users),
youngestMemberBirthYear = getYoungestMemberBirthYear(users),
oldestMemberBirthYear = getOldestMemberBirthYear(users)
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.studentcenter.weave.domain.meetingTeam.entity


import com.studentcenter.weave.domain.meetingTeam.entity.MeetingTeamMemberSummary.Companion.createSummary
import com.studentcenter.weave.domain.user.entity.User
import com.studentcenter.weave.domain.user.entity.UserFixtureFactory
import com.studentcenter.weave.domain.user.vo.BirthYear
import io.kotest.assertions.throwables.shouldNotThrowAny
import io.kotest.core.annotation.DisplayName
import io.kotest.core.spec.style.DescribeSpec
import io.kotest.matchers.shouldBe

@DisplayName("MeetingTeamMemberSummary")
class MeetingTeamMemberSummaryTest : DescribeSpec({

describe("MeetingTeamMemberSummary 생성") {
context("[성공] 팀에 속한 멤버가 존재할 때") {
it("생성에 성공한다.") {
// arrange
val users: List<User> = listOf(
UserFixtureFactory.create(),
UserFixtureFactory.create(),
UserFixtureFactory.create(),
)
val meetingTeam = MeetingTeamFixtureFactory.create(
memberCount = 3, members = users
)

val getUsersByMeetingMembers = { members: List<MeetingMember> -> users }

// act & assert
shouldNotThrowAny {
meetingTeam.createSummary { getUsersByMeetingMembers(it) }
}
}
}

context("[성공] 가장 어린 멤버의 태어난 해와 가장 나이 많은 멤버의 태어난 해가 설정된다.") {
it("생성에 성공한다.") {
// arrange
val youngestMemberBirthYear = BirthYear(2000)
val oldestMemberBirthYear = BirthYear(1990)

val users: List<User> = listOf(
UserFixtureFactory.create(birthYear = oldestMemberBirthYear),
UserFixtureFactory.create(birthYear = BirthYear(1995)),
UserFixtureFactory.create(birthYear = youngestMemberBirthYear),
)
val meetingTeam: MeetingTeam = MeetingTeamFixtureFactory.create(
memberCount = 3, members = users
)

val getUsersByMeetingMembers: (List<MeetingMember>) -> List<User> =
{ members: List<MeetingMember> -> users }

// act
val summary: MeetingTeamMemberSummary =
meetingTeam.createSummary { getUsersByMeetingMembers(it) }

// assert
summary.youngestMemberBirthYear shouldBe youngestMemberBirthYear
summary.oldestMemberBirthYear shouldBe oldestMemberBirthYear
}
}
}
})

0 comments on commit 665e13e

Please sign in to comment.