@@ -6,6 +6,8 @@ import nexters.tuk.domain.gathering.GatheringMember
66import nexters.tuk.domain.gathering.GatheringMemberRepository
77import nexters.tuk.domain.gathering.GatheringRepository
88import nexters.tuk.domain.proposal.Proposal
9+ import nexters.tuk.domain.proposal.ProposalMember
10+ import nexters.tuk.domain.proposal.ProposalMemberRepository
911import nexters.tuk.domain.proposal.ProposalRepository
1012import nexters.tuk.domain.member.MemberRepository
1113import nexters.tuk.fixtures.GatheringFixtureHelper
@@ -24,13 +26,15 @@ class GatheringQueryServiceIntegrationTest @Autowired constructor(
2426 private val gatheringMemberRepository : GatheringMemberRepository ,
2527 private val memberRepository : MemberRepository ,
2628 private val proposalRepository : ProposalRepository ,
29+ private val proposalMemberRepository : ProposalMemberRepository ,
2730) {
2831
2932 private val memberFixture = MemberFixtureHelper (memberRepository)
3033 private val gatheringFixture = GatheringFixtureHelper (gatheringRepository, gatheringMemberRepository)
3134
3235 @AfterEach
3336 fun tearDown () {
37+ proposalMemberRepository.deleteAllInBatch()
3438 proposalRepository.deleteAllInBatch()
3539 gatheringMemberRepository.deleteAllInBatch()
3640 gatheringRepository.deleteAllInBatch()
@@ -113,17 +117,9 @@ class GatheringQueryServiceIntegrationTest @Autowired constructor(
113117 gatheringMemberRepository.save(GatheringMember .registerMember(gathering, member2.id))
114118
115119 // 제안 생성 (보낸 제안 2개, 받은 제안 1개)
116- val proposal1 = Proposal .publish(host.id, " 모임 제안" )
117- proposal1.registerGathering(gathering.id)
118- proposalRepository.save(proposal1)
119-
120- val proposal2 = Proposal .publish(host.id, " 모임 제안" )
121- proposal2.registerGathering(gathering.id)
122- proposalRepository.save(proposal2)
123-
124- val proposal3 = Proposal .publish(member1.id, " 모임 제안" )
125- proposal3.registerGathering(gathering.id)
126- proposalRepository.save(proposal3)
120+ val proposal1 = createProposalWithMembers(host.id, gathering.id, " 모임 제안1" , listOf (host.id, member1.id, member2.id))
121+ val proposal2 = createProposalWithMembers(host.id, gathering.id, " 모임 제안2" , listOf (host.id, member1.id, member2.id))
122+ val proposal3 = createProposalWithMembers(member1.id, gathering.id, " 모임 제안3" , listOf (host.id, member1.id, member2.id))
127123
128124 val query = GatheringQuery .GatheringDetail (host.id, gathering.id)
129125
@@ -256,17 +252,9 @@ class GatheringQueryServiceIntegrationTest @Autowired constructor(
256252 gatheringMemberRepository.save(GatheringMember .registerMember(gathering, member1.id))
257253
258254 // 다양한 상태의 제안 생성
259- val proposal1 = Proposal .publish(host.id, " 첫번째 제안" )
260- proposal1.registerGathering(gathering.id)
261- proposalRepository.save(proposal1)
262-
263- val proposal2 = Proposal .publish(host.id, " 두번째 제안" )
264- proposal2.registerGathering(gathering.id)
265- proposalRepository.save(proposal2)
266-
267- val proposal3 = Proposal .publish(member1.id, " 역제안" )
268- proposal3.registerGathering(gathering.id)
269- proposalRepository.save(proposal3)
255+ val proposal1 = createProposalWithMembers(host.id, gathering.id, " 첫번째 제안" , listOf (host.id, member1.id))
256+ val proposal2 = createProposalWithMembers(host.id, gathering.id, " 두번째 제안" , listOf (host.id, member1.id))
257+ val proposal3 = createProposalWithMembers(member1.id, gathering.id, " 역제안" , listOf (host.id, member1.id))
270258
271259 val query = GatheringQuery .GatheringDetail (host.id, gathering.id)
272260
@@ -345,4 +333,65 @@ class GatheringQueryServiceIntegrationTest @Autowired constructor(
345333 assertThat(member2Info.isHost).isFalse()
346334 }
347335
336+ @Test
337+ fun `나중에 모임에 추가된 멤버의 통계가 올바르게 반영된다` () {
338+ // given - 기존 멤버들과 초대장들이 있는 상황
339+ val host
= memberFixture.createMember(socialId
= " host" , email
= " [email protected] " )
340+ val existingMember
= memberFixture.createMember(socialId
= " existing" , email
= " [email protected] " )
341+ val newMember
= memberFixture.createMember(socialId
= " new" , email
= " [email protected] " )
342+
343+ val gathering = gatheringFixture.createGathering(host, " 테스트 모임" )
344+
345+ // 기존 멤버들만 모임에 추가
346+ gatheringMemberRepository.save(GatheringMember .registerMember(gathering, host.id))
347+ gatheringMemberRepository.save(GatheringMember .registerMember(gathering, existingMember.id))
348+
349+ // 기존 멤버들 간의 초대장 생성
350+ createProposalWithMembers(host.id, gathering.id, " 기존 제안1" , listOf (host.id, existingMember.id))
351+ createProposalWithMembers(existingMember.id, gathering.id, " 기존 제안2" , listOf (host.id, existingMember.id))
352+
353+ // 새로운 멤버를 모임에 추가
354+ gatheringMemberRepository.save(GatheringMember .registerMember(gathering, newMember.id))
355+
356+ // 새로운 멤버가 포함된 초대장 생성
357+ createProposalWithMembers(host.id, gathering.id, " 새 멤버 포함 제안" , listOf (host.id, existingMember.id, newMember.id))
358+ createProposalWithMembers(newMember.id, gathering.id, " 새 멤버의 제안" , listOf (host.id, existingMember.id, newMember.id))
359+
360+ // when - 새로운 멤버의 모임 상세 조회
361+ val newMemberQuery = GatheringQuery .GatheringDetail (newMember.id, gathering.id)
362+ val result = gatheringQueryService.getGatheringDetail(newMemberQuery)
363+
364+ // then - 새로운 멤버의 통계는 자신이 참여한 초대장만 반영되어야 함
365+ assertThat(result.sentProposalCount).isEqualTo(1 ) // 자신이 보낸 초대장 1개
366+ assertThat(result.receivedProposalCount).isEqualTo(1 ) // 자신이 받은 초대장 1개 (host가 새로 보낸 것)
367+ assertThat(result.members).hasSize(3 ) // host, existingMember, newMember
368+ assertThat(result.isHost).isFalse()
369+
370+ // 기존 멤버들의 통계도 확인
371+ val hostQuery = GatheringQuery .GatheringDetail (host.id, gathering.id)
372+ val hostResult = gatheringQueryService.getGatheringDetail(hostQuery)
373+
374+ assertThat(hostResult.sentProposalCount).isEqualTo(2 ) // 기존 1개 + 새로운 1개
375+ assertThat(hostResult.receivedProposalCount).isEqualTo(2 ) // existingMember가 보낸 1개 + newMember가 보낸 1개
376+ }
377+
378+ private fun createProposalWithMembers (
379+ proposerId : Long ,
380+ gatheringId : Long ,
381+ purpose : String ,
382+ memberIds : List <Long >
383+ ): Proposal {
384+ val proposal = Proposal .publish(proposerId, purpose)
385+ proposal.registerGathering(gatheringId)
386+ proposalRepository.save(proposal)
387+
388+ // 모든 멤버에게 ProposalMember 생성
389+ memberIds.forEach { memberId ->
390+ val proposalMember = ProposalMember .publish(proposal, memberId)
391+ proposalMemberRepository.save(proposalMember)
392+ }
393+
394+ return proposal
395+ }
396+
348397}
0 commit comments