66import static org .assertj .core .api .Assertions .assertThat ;
77import static org .assertj .core .api .Assertions .assertThatThrownBy ;
88import static org .junit .jupiter .api .Assertions .assertAll ;
9-
9+ import static org .awaitility .Awaitility .await ;
10+ import com .example .solidconnection .chat .domain .ChatParticipant ;
11+ import com .example .solidconnection .chat .domain .ChatRoom ;
12+ import com .example .solidconnection .chat .repository .ChatRoomRepositoryForTest ;
1013import com .example .solidconnection .common .VerifyStatus ;
1114import com .example .solidconnection .common .exception .CustomException ;
1215import com .example .solidconnection .mentor .domain .Mentor ;
2225import com .example .solidconnection .siteuser .domain .SiteUser ;
2326import com .example .solidconnection .siteuser .fixture .SiteUserFixture ;
2427import com .example .solidconnection .support .TestContainerSpringBootTest ;
28+ import java .time .Duration ;
29+ import java .util .List ;
30+ import java .util .Optional ;
2531import org .junit .jupiter .api .BeforeEach ;
2632import org .junit .jupiter .api .DisplayName ;
2733import org .junit .jupiter .api .Nested ;
@@ -41,6 +47,9 @@ class MentoringCommandServiceTest {
4147 @ Autowired
4248 private MentoringRepository mentoringRepository ;
4349
50+ @ Autowired
51+ private ChatRoomRepositoryForTest chatRoomRepositoryForTest ;
52+
4453 @ Autowired
4554 private SiteUserFixture siteUserFixture ;
4655
@@ -115,6 +124,36 @@ class 멘토링_승인_거절_테스트 {
115124 );
116125 }
117126
127+ @ Test
128+ void 멘토링_승인시_채팅방이_자동으로_생성된다 () {
129+ // given
130+ Mentoring mentoring = mentoringFixture .대기중_멘토링 (mentor1 .getId (), menteeUser .getId ());
131+ MentoringConfirmRequest request = new MentoringConfirmRequest (VerifyStatus .APPROVED );
132+
133+ Optional <ChatRoom > beforeChatRoom = chatRoomRepositoryForTest .findOneOnOneChatRoomByParticipants (mentorUser1 .getId (), menteeUser .getId ());
134+ assertThat (beforeChatRoom ).isEmpty ();
135+
136+ // when
137+ mentoringCommandService .confirmMentoring (mentorUser1 .getId (), mentoring .getId (), request );
138+
139+ // then
140+ ChatRoom afterChatRoom = await ()
141+ .atMost (Duration .ofSeconds (5 ))
142+ .pollInterval (Duration .ofMillis (100 ))
143+ .until (() -> chatRoomRepositoryForTest
144+ .findOneOnOneChatRoomByParticipants (mentorUser1 .getId (), menteeUser .getId ()),
145+ Optional ::isPresent )
146+ .orElseThrow ();
147+
148+ List <Long > participantIds = afterChatRoom .getChatParticipants ().stream ()
149+ .map (ChatParticipant ::getSiteUserId )
150+ .toList ();
151+ assertAll (
152+ () -> assertThat (afterChatRoom .isGroup ()).isFalse (),
153+ () -> assertThat (participantIds ).containsExactly (mentorUser1 .getId (), menteeUser .getId ())
154+ );
155+ }
156+
118157 @ Test
119158 void 멘토링을_성공적으로_거절한다 () {
120159 // given
@@ -137,6 +176,31 @@ class 멘토링_승인_거절_테스트 {
137176 );
138177 }
139178
179+ @ Test
180+ void 멘토링_거절시_채팅방이_자동으로_생성되지_않는다 () {
181+ // given
182+ Mentoring mentoring = mentoringFixture .대기중_멘토링 (mentor1 .getId (), menteeUser .getId ());
183+ MentoringConfirmRequest request = new MentoringConfirmRequest (VerifyStatus .REJECTED );
184+
185+ Optional <ChatRoom > beforeChatRoom = chatRoomRepositoryForTest .findOneOnOneChatRoomByParticipants (mentorUser1 .getId (), menteeUser .getId ());
186+ assertThat (beforeChatRoom ).isEmpty ();
187+
188+ // when
189+ mentoringCommandService .confirmMentoring (mentorUser1 .getId (), mentoring .getId (), request );
190+
191+ // then
192+ await ()
193+ .pollInterval (Duration .ofMillis (100 ))
194+ .during (Duration .ofSeconds (1 ))
195+ .until (() -> chatRoomRepositoryForTest
196+ .findOneOnOneChatRoomByParticipants (mentorUser1 .getId (), menteeUser .getId ())
197+ .isEmpty ());
198+
199+ Optional <ChatRoom > afterChatRoom = chatRoomRepositoryForTest .findOneOnOneChatRoomByParticipants (mentorUser1 .getId (), menteeUser .getId ());
200+ assertThat (afterChatRoom ).isEmpty ();
201+
202+ }
203+
140204 @ Test
141205 void 다른_멘토의_멘토링을_승인할_수_없다 () {
142206 // given
0 commit comments