diff --git a/schedule/src/main/java/itcast/ai/dto/request/GPTSummaryRequest.java b/schedule/src/main/java/itcast/ai/dto/request/GPTSummaryRequest.java index 50e00340..356921b2 100644 --- a/schedule/src/main/java/itcast/ai/dto/request/GPTSummaryRequest.java +++ b/schedule/src/main/java/itcast/ai/dto/request/GPTSummaryRequest.java @@ -1,8 +1,17 @@ package itcast.ai.dto.request; +import lombok.Builder; + + public record GPTSummaryRequest( String model, Message message, float temperature ) { + @Builder + public GPTSummaryRequest(String model, Message message, float temperature) { + this.model = model; + this.message = message; + this.temperature = temperature; + } } diff --git a/schedule/src/main/java/itcast/news/application/NewsService.java b/schedule/src/main/java/itcast/news/application/NewsService.java index c85098ac..a005a023 100644 --- a/schedule/src/main/java/itcast/news/application/NewsService.java +++ b/schedule/src/main/java/itcast/news/application/NewsService.java @@ -76,7 +76,7 @@ public News processNews(String link) { } } - private void updateNewsSummary(News news, String content) { + public void updateNewsSummary(News news, String content) { try { Message message = new Message("user", content); GPTSummaryRequest request = new GPTSummaryRequest("gpt-4o-mini", message, 0.7f); diff --git a/schedule/src/main/java/itcast/news/application/SendNewsService.java b/schedule/src/main/java/itcast/news/application/SendNewsService.java index c0076e73..9996bbd4 100644 --- a/schedule/src/main/java/itcast/news/application/SendNewsService.java +++ b/schedule/src/main/java/itcast/news/application/SendNewsService.java @@ -39,7 +39,6 @@ public void selectNews(LocalDate yesterday) { } LocalDate sendAt = LocalDate.now().plusDays(ALARM_DAY); - newsList.forEach(news -> { news.newsUpdate(sendAt); }); @@ -60,7 +59,6 @@ public void sendNews() { news.getLink(), news.getThumbnail())) .toList(); - List emails = retrieveUserEmails(Interest.NEWS); if (emails == null || emails.isEmpty()) { diff --git a/schedule/src/test/java/itcast/news/application/NewsServiceTest.java b/schedule/src/test/java/itcast/news/application/NewsServiceTest.java index 92ba26b6..3ca2edbd 100644 --- a/schedule/src/test/java/itcast/news/application/NewsServiceTest.java +++ b/schedule/src/test/java/itcast/news/application/NewsServiceTest.java @@ -1,6 +1,7 @@ package itcast.news.application; import itcast.ai.application.GPTService; +import itcast.ai.dto.request.GPTSummaryRequest; import itcast.domain.news.News; import itcast.news.repository.NewsRepository; import org.jsoup.Connection; @@ -11,16 +12,15 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.junit.jupiter.MockitoExtension; import java.io.IOException; -import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Arrays; -import java.util.Collections; import java.util.List; import static org.junit.jupiter.api.Assertions.*; @@ -168,4 +168,31 @@ void findLinksTest() throws IOException { } } + @Test + @DisplayName("updateNewsSummary 메소드 테스트") + void updateNewsSummaryTest() { + // give + News news = News.builder() + .id(1L) + .title("Sample News") + .content("Original Content") + .build(); + String content = "Updated Summary Content"; + + doNothing().when(gptService).updateNewsBySummaryContent(any(GPTSummaryRequest.class), eq(news.getId())); + + // when + assertDoesNotThrow(() -> newsService.updateNewsSummary(news, content)); + + ArgumentCaptor captor = ArgumentCaptor.forClass(GPTSummaryRequest.class); + verify(gptService, times(1)).updateNewsBySummaryContent(captor.capture(), eq(news.getId())); + + // then + GPTSummaryRequest capturedRequest = captor.getValue(); + assertEquals("gpt-4o-mini", capturedRequest.model()); + assertEquals("user", capturedRequest.message().getRole()); + assertEquals(content, capturedRequest.message().getContent()); + assertEquals(0.7f, capturedRequest.temperature()); + } + } diff --git a/schedule/src/test/java/itcast/news/application/SelectNewsServiceTest.java b/schedule/src/test/java/itcast/news/application/SelectNewsServiceTest.java index 8d45ba8d..440fa17f 100644 --- a/schedule/src/test/java/itcast/news/application/SelectNewsServiceTest.java +++ b/schedule/src/test/java/itcast/news/application/SelectNewsServiceTest.java @@ -27,8 +27,6 @@ @ExtendWith(MockitoExtension.class) public class SelectNewsServiceTest { private static final int YESTERDAY = 1; - private static final int ALARM_HOUR = 2; - private static final int ALARM_DAY = 2; @Mock private UserRepository userRepository;