Skip to content

Commit

Permalink
[#98] test: 나눠진 로직 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
junseok708 committed Dec 26, 2024
1 parent 964308a commit 7c7d3f2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public void selectNews(LocalDate yesterday) {
}

LocalDate sendAt = LocalDate.now().plusDays(ALARM_DAY);

newsList.forEach(news -> {
news.newsUpdate(sendAt);
});
Expand All @@ -60,7 +59,6 @@ public void sendNews() {
news.getLink(),
news.getThumbnail()))
.toList();

List<String> emails = retrieveUserEmails(Interest.NEWS);

if (emails == null || emails.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.*;
Expand Down Expand Up @@ -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<GPTSummaryRequest> 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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7c7d3f2

Please sign in to comment.