Skip to content

Commit

Permalink
Fix: 오류 발생하는 테스트 코드 수정
Browse files Browse the repository at this point in the history
- 카카오 로그인 테스트, 헤더에 Bearer 추가
- LlmTask 테스트, 코드 변경에 맞게 수정
  • Loading branch information
hynseoj committed Nov 13, 2024
1 parent 57c67e9 commit 4d75d7b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import org.mockito.MockitoAnnotations;

Expand Down Expand Up @@ -47,7 +49,7 @@ public void testFetchMember() {

KakaoMemberResponse kakaoMemberResponse = new KakaoMemberResponse(id, hasSignedUp, connectedAt, kakaoAccount);

when(kakaoClient.fetchMember(accessToken)).thenReturn(kakaoMemberResponse);
when(kakaoClient.fetchMember(eq("Bearer " + accessToken))).thenReturn(kakaoMemberResponse);

Member member = kakaoOauthClient.fetchMember(accessToken);

Expand Down
16 changes: 16 additions & 0 deletions src/test/java/notai/llm/application/LlmTaskQueryServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import notai.llm.application.result.LlmTaskPageStatusResult;
import notai.llm.query.LlmTaskQueryRepository;
import notai.member.domain.Member;
import notai.member.domain.MemberRepository;
import notai.problem.domain.ProblemRepository;
import notai.problem.query.result.ProblemPageContentResult;
import notai.summary.domain.SummaryRepository;
Expand All @@ -28,6 +29,7 @@
import static notai.llm.domain.TaskStatus.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willDoNothing;
Expand All @@ -51,6 +53,9 @@ class LlmTaskQueryServiceTest {
@Mock
private ProblemRepository problemRepository;

@Mock
private MemberRepository memberRepository;

@Mock
private Member member;

Expand All @@ -76,6 +81,7 @@ class LlmTaskQueryServiceTest {
List<Long> summaryIds = List.of(1L, 2L, 3L);

given(documentRepository.getById(eq(1L))).willReturn(document);
given(memberRepository.getById(anyLong())).willReturn(member);
willDoNothing().given(document).validateOwner(member);

given(summaryRepository.getSummaryIdsByDocumentId(documentId)).willReturn(summaryIds);
Expand Down Expand Up @@ -103,6 +109,7 @@ class LlmTaskQueryServiceTest {
List<Long> summaryIds = List.of(1L, 2L, 3L);

given(documentRepository.getById(eq(1L))).willReturn(document);
given(memberRepository.getById(anyLong())).willReturn(member);
willDoNothing().given(document).validateOwner(member);

given(summaryRepository.getSummaryIdsByDocumentId(documentId)).willReturn(summaryIds);
Expand Down Expand Up @@ -132,6 +139,7 @@ class LlmTaskQueryServiceTest {
LlmTaskPageStatusCommand command = new LlmTaskPageStatusCommand(documentId, pageNumber);

given(documentRepository.getById(eq(1L))).willReturn(document);
given(memberRepository.getById(anyLong())).willReturn(member);
willDoNothing().given(document).validateOwner(member);

given(summaryRepository.getSummaryIdByDocumentIdAndPageNumber(documentId, pageNumber)).willReturn(summaryId);
Expand All @@ -152,6 +160,7 @@ class LlmTaskQueryServiceTest {
LlmTaskPageStatusCommand command = new LlmTaskPageStatusCommand(documentId, pageNumber);

given(documentRepository.getById(eq(1L))).willReturn(document);
given(memberRepository.getById(anyLong())).willReturn(member);
willDoNothing().given(document).validateOwner(member);

given(summaryRepository.getSummaryIdByDocumentIdAndPageNumber(documentId, pageNumber)).willReturn(null);
Expand Down Expand Up @@ -186,6 +195,7 @@ class LlmTaskQueryServiceTest {
);

given(documentRepository.getById(eq(1L))).willReturn(document);
given(memberRepository.getById(anyLong())).willReturn(member);
willDoNothing().given(document).validateOwner(member);

given(summaryRepository.getPageNumbersAndContentByDocumentId(documentId)).willReturn(summaryResults);
Expand Down Expand Up @@ -216,6 +226,7 @@ class LlmTaskQueryServiceTest {
);

given(documentRepository.getById(eq(1L))).willReturn(document);
given(memberRepository.getById(anyLong())).willReturn(member);
willDoNothing().given(document).validateOwner(member);

given(summaryRepository.getPageNumbersAndContentByDocumentId(documentId)).willReturn(summaryResults);
Expand Down Expand Up @@ -243,6 +254,7 @@ class LlmTaskQueryServiceTest {
LlmTaskPageResultCommand command = new LlmTaskPageResultCommand(documentId, pageNumber);

given(documentRepository.getById(eq(1L))).willReturn(document);
given(memberRepository.getById(anyLong())).willReturn(member);
willDoNothing().given(document).validateOwner(member);

given(summaryRepository.getSummaryContentByDocumentIdAndPageNumber(documentId, pageNumber)).willReturn(
Expand All @@ -268,6 +280,7 @@ class LlmTaskQueryServiceTest {
LlmTaskPageResultCommand command = new LlmTaskPageResultCommand(documentId, pageNumber);

given(documentRepository.getById(eq(1L))).willReturn(document);
given(memberRepository.getById(anyLong())).willReturn(member);
willDoNothing().given(document).validateOwner(member);

given(summaryRepository.getSummaryContentByDocumentIdAndPageNumber(documentId, pageNumber)).willReturn(null);
Expand All @@ -292,6 +305,7 @@ class LlmTaskQueryServiceTest {
LlmTaskPageResultCommand command = new LlmTaskPageResultCommand(documentId, pageNumber);

given(documentRepository.getById(eq(1L))).willReturn(document);
given(memberRepository.getById(anyLong())).willReturn(member);
willDoNothing().given(document).validateOwner(member);

given(summaryRepository.getSummaryContentByDocumentIdAndPageNumber(documentId, pageNumber)).willReturn(
Expand All @@ -310,6 +324,7 @@ class LlmTaskQueryServiceTest {
given(summaryRepository.getSummaryIdsByDocumentId(documentId)).willReturn(Collections.emptyList());

given(documentRepository.getById(eq(1L))).willReturn(document);
given(memberRepository.getById(anyLong())).willReturn(member);
willDoNothing().given(document).validateOwner(member);

// when
Expand All @@ -331,6 +346,7 @@ class LlmTaskQueryServiceTest {
given(summaryRepository.getPageNumbersAndContentByDocumentId(documentId)).willReturn(Collections.emptyList());

given(documentRepository.getById(eq(1L))).willReturn(document);
given(memberRepository.getById(anyLong())).willReturn(member);
willDoNothing().given(document).validateOwner(member);

// when
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/notai/llm/application/LlmTaskServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
import notai.member.domain.Member;
import notai.member.domain.OauthId;
import notai.member.domain.OauthProvider;
import notai.ocr.domain.OCR;
import notai.ocr.domain.OCRRepository;
import notai.problem.domain.Problem;
import notai.problem.domain.ProblemRepository;
import notai.recording.domain.Recording;
import notai.stt.domain.Stt;
import notai.stt.domain.SttRepository;
import notai.summary.domain.Summary;
import notai.summary.domain.SummaryRepository;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -57,6 +62,12 @@ class LlmTaskServiceTest {
@Mock
private AnnotationRepository annotationRepository;

@Mock
private SttRepository sttRepository;

@Mock
private OCRRepository ocrRepository;

@Mock
private AiClient aiClient;

Expand Down Expand Up @@ -94,11 +105,17 @@ class LlmTaskServiceTest {
new Annotation(document, 2, 50, 60, 120, 70, "Annotation 3")
);

Recording recording = new Recording(document);
List<Stt> stts = List.of(new Stt(recording));
List<OCR> ocrs = List.of(new OCR(document, 1, "TestDocumentContent"));

UUID taskId = UUID.randomUUID();
TaskResponse taskResponse = new TaskResponse(taskId, "llm");

given(documentRepository.getById(anyLong())).willReturn(document);
given(annotationRepository.findByDocumentId(anyLong())).willReturn(annotations);
given(sttRepository.findAllByDocumentIdAndPageNumber(any(), anyInt())).willReturn(stts);
given(ocrRepository.findAllByDocumentIdAndPageNumber(any(), anyInt())).willReturn(ocrs);
given(aiClient.submitLlmTask(any(LlmTaskRequest.class))).willReturn(taskResponse);
given(llmTaskRepository.save(any(LlmTask.class))).willAnswer(invocation -> invocation.getArgument(0));

Expand Down

0 comments on commit 4d75d7b

Please sign in to comment.