@@ -120,6 +120,7 @@ void setUp() {
120120 @ Test
121121 @ DisplayName ("채팅 요청: Redis에 저장 성공" )
122122 void testSaveRequestToRedis_SUCCESS () {
123+
123124 // given
124125 when (emotionRecordRepository .findById (emotionRecordId )).thenReturn (Optional .of (emotionRecord )); // 감정 기록 조회
125126 when (userRepository .findByUserIdWithCache (requestUserId )).thenReturn (Optional .of (requestUser )); // 요청자 정보 조회
@@ -130,6 +131,9 @@ void testSaveRequestToRedis_SUCCESS() {
130131// when(alertService.send(eq(responseUserId), eq("alarm"), any(Alert.class)))
131132// .thenReturn(new ResponseResult(ErrorCode.SUCCESS)); // 알림 전송 mock
132133
134+ // 상대방이 온라인이라고 가정..
135+ when (alertService .isOnline (responseUserId )).thenReturn (true );
136+
133137 // Redis 관련 mock 설정
134138 ValueOperations <String , Object > valueOps = mock (ValueOperations .class ); // ValueOperations 객체 생성
135139 when (redisTemplate .opsForValue ()).thenReturn (valueOps ); // redisTemplate에서 valueOps 반환하도록 설정
@@ -171,6 +175,20 @@ void testDeleteRequestFromRedis_SUCCESS() {
171175 verify (alertService ).send (responseUserId , "cancel" , "Chat request has been canceled." );
172176 }
173177
178+ @ Test
179+ @ DisplayName ("상대방이 오프라인일 경우" )
180+ void testSaveRequestToRedis_Offline () {
181+ // given
182+ when (emotionRecordRepository .findById (emotionRecordId )).thenReturn (Optional .of (emotionRecord ));
183+ when (alertService .isOnline (responseUserId )).thenReturn (false ); // 핵심만 남김
184+
185+ // when
186+ ResponseResult result = chatRoomService .saveRequestToRedis (requestUserId , emotionRecordId );
187+
188+ // then
189+ assertEquals (202 , result .getCode ());
190+ }
191+
174192 @ Test
175193 @ DisplayName ("채팅 요청 거절" )
176194 void testRequestRejected_SUCCESS () {
0 commit comments