@@ -55,7 +55,7 @@ class ProposalCreateServiceIntegrationTest @Autowired constructor(
5555
5656 val command = ProposalCommand .Propose (
5757 memberId = host.id,
58- gatheringId = null , // 새로운 API에서는 gatheringId가 null
58+ gatheringId = null , // gatheringId가 null이면 모임에 자동으로 추가되지 않음
5959 purpose = ProposalPurposeInfo (
6060 whereTag = " 카페" ,
6161 whenTag = " 오후 3시" ,
@@ -73,13 +73,13 @@ class ProposalCreateServiceIntegrationTest @Autowired constructor(
7373 val savedProposal = proposalRepository.findById(result.proposalId).orElse(null )
7474 assertThat(savedProposal).isNotNull
7575 assertThat(savedProposal.proposerId).isEqualTo(host.id)
76- assertThat(savedProposal.gatheringId).isNull() // 새로운 API에서는 gatheringId가 null
76+ assertThat(savedProposal.gatheringId).isNull() // gatheringId가 null로 설정됨
7777 assertThat(savedProposal.purpose).isEqualTo(" 카페\n 오후 3시\n 커피 모임" )
7878
79- // 새로운 API에서는 ProposalCreateService가 모임 멤버에게 자동으로 발송하지 않음
80- // ProposalMember는 GatheringProposalService.addProposal에서 생성됨
79+ // gatheringId가 null이면 GatheringProposalService.addProposal이 호출되지 않음
80+ // ProposalMember는 별도로 GatheringProposalService.addProposal을 호출해야 생성됨
8181 val proposalMembers = proposalMemberRepository.findAll()
82- assertThat(proposalMembers).hasSize(0 ) // 모임에 추가되기 전까지는 멤버가 없음
82+ assertThat(proposalMembers).hasSize(0 ) // gatheringId가 null이므로 멤버가 없음
8383 }
8484
8585
@@ -95,7 +95,7 @@ class ProposalCreateServiceIntegrationTest @Autowired constructor(
9595
9696 val command = ProposalCommand .Propose (
9797 memberId = host.id,
98- gatheringId = null , // 새로운 API에서는 gatheringId가 null
98+ gatheringId = null , // gatheringId가 null이면 모임에 자동으로 추가되지 않음
9999 purpose = ProposalPurposeInfo (
100100 whereTag = " 강남역 스타벅스 2층" ,
101101 whenTag = " 2024년 12월 25일 오후 2시 30분" ,
@@ -123,13 +123,13 @@ class ProposalCreateServiceIntegrationTest @Autowired constructor(
123123
124124 val command1 = ProposalCommand .Propose (
125125 memberId = host.id,
126- gatheringId = null , // 새로운 API에서는 gatheringId가 null
126+ gatheringId = null , // gatheringId가 null이면 모임에 자동으로 추가되지 않음
127127 purpose = ProposalPurposeInfo (whereTag = " 카페" , whenTag = " 오후 3시" , whatTag = " 첫 번째 모임" )
128128 )
129129
130130 val command2 = ProposalCommand .Propose (
131131 memberId = host.id,
132- gatheringId = null , // 새로운 API에서는 gatheringId가 null
132+ gatheringId = null , // gatheringId가 null이면 모임에 자동으로 추가되지 않음
133133 purpose = ProposalPurposeInfo (whereTag = " 레스토랑" , whenTag = " 저녁 7시" , whatTag = " 두 번째 모임" )
134134 )
135135
@@ -144,7 +144,7 @@ class ProposalCreateServiceIntegrationTest @Autowired constructor(
144144 val proposals = proposalRepository.findAll()
145145 assertThat(proposals).hasSize(2 )
146146
147- // 새로운 API에서는 ProposalCreateService가 자동으로 멤버에게 발송하지 않음
147+ // gatheringId가 null이면 GatheringProposalService.addProposal이 호출되지 않음
148148 val proposalMembers = proposalMemberRepository.findAll()
149149 assertThat(proposalMembers).hasSize(0 )
150150
@@ -156,4 +156,89 @@ class ProposalCreateServiceIntegrationTest @Autowired constructor(
156156 assertThat(proposal1?.gatheringId).isNull()
157157 assertThat(proposal2?.gatheringId).isNull()
158158 }
159+
160+ @Test
161+ fun `gatheringId가 존재할 때 제안을 생성하고 모임에 자동으로 추가한다` () {
162+ // given
163+ val host
= memberFixture.createMember(socialId
= " host" , email
= " [email protected] " )
164+ val member1
= memberFixture.createMember(socialId
= " member1" , email
= " [email protected] " )
165+ val member2
= memberFixture.createMember(socialId
= " member2" , email
= " [email protected] " )
166+
167+ val gathering = gatheringFixture.createGathering(host, " 테스트 모임" )
168+
169+ // 모임 멤버 등록
170+ gatheringMemberRepository.save(GatheringMember .registerMember(gathering, host.id))
171+ gatheringMemberRepository.save(GatheringMember .registerMember(gathering, member1.id))
172+ gatheringMemberRepository.save(GatheringMember .registerMember(gathering, member2.id))
173+
174+ val command = ProposalCommand .Propose (
175+ memberId = host.id,
176+ gatheringId = gathering.id, // gatheringId가 존재하는 경우
177+ purpose = ProposalPurposeInfo (
178+ whereTag = " 카페" ,
179+ whenTag = " 오후 3시" ,
180+ whatTag = " 모임 제안"
181+ )
182+ )
183+
184+ // when
185+ val result = proposalCreateService.propose(command)
186+
187+ // then
188+ assertThat(result.proposalId).isNotNull()
189+
190+ // 제안이 생성되었는지 확인
191+ val savedProposal = proposalRepository.findById(result.proposalId).orElse(null )
192+ assertThat(savedProposal).isNotNull
193+ assertThat(savedProposal.proposerId).isEqualTo(host.id)
194+ assertThat(savedProposal.gatheringId).isEqualTo(gathering.id) // gatheringId가 설정되어야 함
195+ assertThat(savedProposal.purpose).isEqualTo(" 카페\n 오후 3시\n 모임 제안" )
196+
197+ // gatheringId가 존재할 때는 GatheringProposalService.addProposal이 호출되어
198+ // 모든 모임 멤버에게 제안이 발송되어야 함
199+ val proposalMembers = proposalMemberRepository.findAll()
200+ assertThat(proposalMembers).hasSize(3 ) // host, member1, member2
201+
202+ val proposalMemberIds = proposalMembers.map { it.memberId }
203+ assertThat(proposalMemberIds).containsExactlyInAnyOrder(host.id, member1.id, member2.id)
204+ }
205+
206+ @Test
207+ fun `gatheringId가 null일 때 제안만 생성하고 모임에 추가하지 않는다` () {
208+ // given
209+ val host
= memberFixture.createMember(socialId
= " host" , email
= " [email protected] " )
210+ val member1
= memberFixture.createMember(socialId
= " member1" , email
= " [email protected] " )
211+
212+ val gathering = gatheringFixture.createGathering(host, " 테스트 모임" )
213+ gatheringMemberRepository.save(GatheringMember .registerMember(gathering, host.id))
214+ gatheringMemberRepository.save(GatheringMember .registerMember(gathering, member1.id))
215+
216+ val command = ProposalCommand .Propose (
217+ memberId = host.id,
218+ gatheringId = null , // gatheringId가 null인 경우
219+ purpose = ProposalPurposeInfo (
220+ whereTag = " 카페" ,
221+ whenTag = " 오후 3시" ,
222+ whatTag = " 개별 제안"
223+ )
224+ )
225+
226+ // when
227+ val result = proposalCreateService.propose(command)
228+
229+ // then
230+ assertThat(result.proposalId).isNotNull()
231+
232+ // 제안이 생성되었는지 확인
233+ val savedProposal = proposalRepository.findById(result.proposalId).orElse(null )
234+ assertThat(savedProposal).isNotNull
235+ assertThat(savedProposal.proposerId).isEqualTo(host.id)
236+ assertThat(savedProposal.gatheringId).isNull() // gatheringId가 null이어야 함
237+ assertThat(savedProposal.purpose).isEqualTo(" 카페\n 오후 3시\n 개별 제안" )
238+
239+ // gatheringId가 null일 때는 GatheringProposalService.addProposal이 호출되지 않아
240+ // 제안 멤버가 생성되지 않아야 함
241+ val proposalMembers = proposalMemberRepository.findAll()
242+ assertThat(proposalMembers).hasSize(0 )
243+ }
159244}
0 commit comments