Skip to content

Commit be5a1bc

Browse files
committed
test: 테스트 추가
1 parent 06cdc51 commit be5a1bc

File tree

4 files changed

+293
-373
lines changed

4 files changed

+293
-373
lines changed

tuk-api/src/test/kotlin/nexters/tuk/application/gathering/GatheringQueryServiceIntegrationTest.kt

Lines changed: 71 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import nexters.tuk.domain.gathering.GatheringMember
66
import nexters.tuk.domain.gathering.GatheringMemberRepository
77
import nexters.tuk.domain.gathering.GatheringRepository
88
import nexters.tuk.domain.proposal.Proposal
9+
import nexters.tuk.domain.proposal.ProposalMember
10+
import nexters.tuk.domain.proposal.ProposalMemberRepository
911
import nexters.tuk.domain.proposal.ProposalRepository
1012
import nexters.tuk.domain.member.MemberRepository
1113
import 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
}

tuk-api/src/test/kotlin/nexters/tuk/application/proposal/ProposalServiceIntegrationTest.kt

Lines changed: 0 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import nexters.tuk.application.proposal.vo.ProposalPurposeInfo
55
import nexters.tuk.domain.gathering.GatheringMemberRepository
66
import nexters.tuk.domain.gathering.GatheringRepository
77
import nexters.tuk.domain.member.MemberRepository
8-
import nexters.tuk.domain.proposal.Proposal
98
import nexters.tuk.domain.proposal.ProposalRepository
109
import nexters.tuk.fixtures.GatheringFixtureHelper
1110
import nexters.tuk.fixtures.MemberFixtureHelper
@@ -63,165 +62,4 @@ class ProposalServiceIntegrationTest @Autowired constructor(
6362
assertThat(savedProposal.gatheringId).isNull()
6463
assertThat(savedProposal.purpose).isEqualTo("카페\n오후 3시\n커피 모임")
6564
}
66-
67-
@Test
68-
fun `모임의 제안 통계를 정확히 계산한다`() {
69-
// given
70-
val host = memberFixture.createMember(socialId = "host", email = "[email protected]")
71-
val member1 = memberFixture.createMember(socialId = "member1", email = "[email protected]")
72-
val member2 = memberFixture.createMember(socialId = "member2", email = "[email protected]")
73-
val gathering = gatheringFixture.createGathering(hostMember = host)
74-
75-
// host가 보낸 제안 2개
76-
val hostProposal1 = Proposal.publish(host.id, "첫번째 제안")
77-
hostProposal1.registerGathering(gathering.id)
78-
proposalRepository.save(hostProposal1)
79-
80-
val hostProposal2 = Proposal.publish(host.id, "두번째 제안")
81-
hostProposal2.registerGathering(gathering.id)
82-
proposalRepository.save(hostProposal2)
83-
84-
// member1이 보낸 제안 1개
85-
val member1Proposal = Proposal.publish(member1.id, "멤버1 제안")
86-
member1Proposal.registerGathering(gathering.id)
87-
proposalRepository.save(member1Proposal)
88-
89-
// member2가 보낸 제안 1개
90-
val member2Proposal = Proposal.publish(member2.id, "멤버2 제안")
91-
member2Proposal.registerGathering(gathering.id)
92-
proposalRepository.save(member2Proposal)
93-
94-
// when - host 관점에서 통계 조회
95-
val hostStat = proposalService.getGatheringProposalStat(gathering.id, host.id)
96-
97-
// then
98-
assertThat(hostStat.sentCount).isEqualTo(2) // host가 보낸 제안 수
99-
assertThat(hostStat.receivedCount).isEqualTo(2) // host가 받은 제안 수 (member1 + member2)
100-
}
101-
102-
@Test
103-
fun `제안이 없는 모임의 통계는 모두 0이다`() {
104-
// given
105-
val member = memberFixture.createMember()
106-
val gathering = gatheringFixture.createGathering(hostMember = member)
107-
108-
// when
109-
val stat = proposalService.getGatheringProposalStat(gathering.id, member.id)
110-
111-
// then
112-
assertThat(stat.sentCount).isEqualTo(0)
113-
assertThat(stat.receivedCount).isEqualTo(0)
114-
}
115-
116-
@Test
117-
fun `다른 모임의 제안은 통계에 포함되지 않는다`() {
118-
// given
119-
val host = memberFixture.createMember(socialId = "host", email = "[email protected]")
120-
val member = memberFixture.createMember(socialId = "member", email = "[email protected]")
121-
122-
val gathering1 = gatheringFixture.createGathering(hostMember = host)
123-
val gathering2 = gatheringFixture.createGathering(hostMember = host)
124-
125-
// gathering1에 제안들
126-
val g1Proposal1 = Proposal.publish(host.id, "gathering1 제안1")
127-
g1Proposal1.registerGathering(gathering1.id)
128-
proposalRepository.save(g1Proposal1)
129-
130-
val g1Proposal2 = Proposal.publish(member.id, "gathering1 제안2")
131-
g1Proposal2.registerGathering(gathering1.id)
132-
proposalRepository.save(g1Proposal2)
133-
134-
// gathering2에 제안들
135-
val g2Proposal1 = Proposal.publish(host.id, "gathering2 제안1")
136-
g2Proposal1.registerGathering(gathering2.id)
137-
proposalRepository.save(g2Proposal1)
138-
139-
val g2Proposal2 = Proposal.publish(host.id, "gathering2 제안2")
140-
g2Proposal2.registerGathering(gathering2.id)
141-
proposalRepository.save(g2Proposal2)
142-
143-
val g2Proposal3 = Proposal.publish(member.id, "gathering2 제안3")
144-
g2Proposal3.registerGathering(gathering2.id)
145-
proposalRepository.save(g2Proposal3)
146-
147-
// when - gathering1에 대한 host의 통계
148-
val stat = proposalService.getGatheringProposalStat(gathering1.id, host.id)
149-
150-
// then - gathering1의 제안만 카운트되어야 함
151-
assertThat(stat.sentCount).isEqualTo(1) // host가 gathering1에 보낸 제안
152-
assertThat(stat.receivedCount).isEqualTo(1) // member가 gathering1에 보낸 제안
153-
}
154-
155-
@Test
156-
fun `혼자만 있는 모임에서는 보낸 제안만 카운트된다`() {
157-
// given
158-
val host = memberFixture.createMember(socialId = "host", email = "[email protected]")
159-
val gathering = gatheringFixture.createGathering(hostMember = host)
160-
161-
// host 혼자만 제안을 보냄
162-
val soloProposal1 = Proposal.publish(host.id, "혼자 제안1")
163-
soloProposal1.registerGathering(gathering.id)
164-
proposalRepository.save(soloProposal1)
165-
166-
val soloProposal2 = Proposal.publish(host.id, "혼자 제안2")
167-
soloProposal2.registerGathering(gathering.id)
168-
proposalRepository.save(soloProposal2)
169-
170-
// when
171-
val stat = proposalService.getGatheringProposalStat(gathering.id, host.id)
172-
173-
// then
174-
assertThat(stat.sentCount).isEqualTo(2) // host가 보낸 제안
175-
assertThat(stat.receivedCount).isEqualTo(0) // 다른 사람이 보낸 제안 없음
176-
}
177-
178-
@Test
179-
fun `복잡한 제안 상황의 통계를 정확히 계산한다`() {
180-
// given
181-
val host = memberFixture.createMember(socialId = "host", email = "[email protected]")
182-
val member1 = memberFixture.createMember(socialId = "member1", email = "[email protected]")
183-
val member2 = memberFixture.createMember(socialId = "member2", email = "[email protected]")
184-
val member3 = memberFixture.createMember(socialId = "member3", email = "[email protected]")
185-
val gathering = gatheringFixture.createGathering(hostMember = host)
186-
187-
// 다양한 멤버들이 제안을 보냄
188-
// host: 3개
189-
val hostP1 = Proposal.publish(host.id, "host 제안1")
190-
hostP1.registerGathering(gathering.id)
191-
proposalRepository.save(hostP1)
192-
193-
val hostP2 = Proposal.publish(host.id, "host 제안2")
194-
hostP2.registerGathering(gathering.id)
195-
proposalRepository.save(hostP2)
196-
197-
val hostP3 = Proposal.publish(host.id, "host 제안3")
198-
hostP3.registerGathering(gathering.id)
199-
proposalRepository.save(hostP3)
200-
201-
// member1: 2개
202-
val m1P1 = Proposal.publish(member1.id, "member1 제안1")
203-
m1P1.registerGathering(gathering.id)
204-
proposalRepository.save(m1P1)
205-
206-
val m1P2 = Proposal.publish(member1.id, "member1 제안2")
207-
m1P2.registerGathering(gathering.id)
208-
proposalRepository.save(m1P2)
209-
210-
// member2: 1개
211-
val m2P1 = Proposal.publish(member2.id, "member2 제안1")
212-
m2P1.registerGathering(gathering.id)
213-
proposalRepository.save(m2P1)
214-
215-
// member3: 1개
216-
val m3P1 = Proposal.publish(member3.id, "member3 제안1")
217-
m3P1.registerGathering(gathering.id)
218-
proposalRepository.save(m3P1)
219-
220-
// when - member1 관점에서 통계
221-
val member1Stat = proposalService.getGatheringProposalStat(gathering.id, member1.id)
222-
223-
// then
224-
assertThat(member1Stat.sentCount).isEqualTo(2) // member1이 보낸 제안
225-
assertThat(member1Stat.receivedCount).isEqualTo(5) // 다른 멤버들이 보낸 제안 (host:3 + member2:1 + member3:1)
226-
}
22765
}

0 commit comments

Comments
 (0)