99import org .dfbf .soundlink .domain .emotionRecord .service .EmotionRecordService ;
1010import org .dfbf .soundlink .domain .user .entity .User ;
1111import org .dfbf .soundlink .domain .user .repository .UserRepository ;
12+ import org .dfbf .soundlink .global .comm .enums .Emotions ;
1213import org .dfbf .soundlink .global .exception .ErrorCode ;
1314import org .dfbf .soundlink .global .exception .ResponseResult ;
15+ import org .junit .jupiter .api .DisplayName ;
1416import org .junit .jupiter .api .Test ;
1517import org .junit .jupiter .api .extension .ExtendWith ;
1618import org .mockito .InjectMocks ;
@@ -36,7 +38,8 @@ public class EmotionRecordServiceTest {
3638 @ Mock
3739 private UserRepository userRepository ;
3840
39- //감정기록 작성 : 성공
41+
42+ @ DisplayName ("감정기록 작성(제목,가수,앨범,스포티파이아이디,감정,멘트):성공" )
4043 @ Test
4144 void saveEmotionRecordWithMusic_SUCCESS () {
4245 // given
@@ -63,6 +66,7 @@ void saveEmotionRecordWithMusic_SUCCESS() {
6366 }
6467
6568 //감정기록 삭제 : 성공
69+ @ DisplayName ("감정기록 삭제:성공" )
6670 @ Test
6771 void deleteEmotionRecord_SUCCESS () {
6872 //given
@@ -75,7 +79,8 @@ void deleteEmotionRecord_SUCCESS() {
7579 verify (emotionRecordRepository ).deleteByRecordId (recordId );
7680 }
7781
78- //감정기록 삭제 : 실패(DB 오류)
82+
83+ @ DisplayName ("감정기록 DB오류 : 실패" )
7984 @ Test
8085 void deleteEmotionRecord_DataAccessException () {
8186 // given
@@ -90,5 +95,35 @@ void deleteEmotionRecord_DataAccessException() {
9095 assertEquals ("Database error" , result .getMessage ());
9196 }
9297
98+ @ Test
99+ @ DisplayName ("감정 기록 수정 성공 테스트" )
100+ void updateEmotionRecord_Success () {
101+ // given
102+ Long recordId = 1L ;
103+ EmotionRecordUpdateRequestDTO updateDTO = new EmotionRecordUpdateRequestDTO (
104+ "spotify1233" , "New Title" , "New Artist" , "New Image" , "HAPPY" , "Test comment"
105+ );
106+
107+ // 기존 감정 기록 및 음악 정보
108+ SpotifyMusic existingMusic = new SpotifyMusic ("spotify123" , "Old Title" , "Old Artist" , "Old Image" );
109+ EmotionRecord existingRecord = new EmotionRecord (
110+ mock (User .class ), Emotions .SAD , "Old Comment" , existingMusic
111+ );
112+
113+ // 기존 감정 기록 조회
114+ when (emotionRecordRepository .findByRecordId (recordId )).thenReturn (Optional .of (existingRecord ));
115+ when (spotifyMusicRepository .findBySpotifyId (updateDTO .spotifyId ())).thenReturn (Optional .of (existingMusic ));
116+
117+ // when
118+ ResponseResult result = emotionRecordService .updateEmotionRecord (recordId , updateDTO );
119+
120+ // then
121+ assertEquals (200 , result .getCode ());
122+ verify (emotionRecordRepository ).findByRecordId (recordId );
123+ verify (spotifyMusicRepository ).findBySpotifyId (updateDTO .spotifyId ());
124+ verify (emotionRecordRepository , never ()).save (any ()); // update는 save 호출 안 함
125+ }
126+
127+
93128
94129}
0 commit comments