|
| 1 | +package com.stackup.stackup.document.application; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 5 | +import static org.mockito.Mockito.mock; |
| 6 | +import static org.mockito.Mockito.when; |
| 7 | + |
| 8 | +import com.stackup.stackup.common.exception.ApiErrorCode; |
| 9 | +import com.stackup.stackup.common.exception.DomainException; |
| 10 | +import com.stackup.stackup.common.storage.ObjectStorageClient; |
| 11 | +import com.stackup.stackup.document.domain.AnalyzedDocument; |
| 12 | +import com.stackup.stackup.document.domain.AnalyzedDocumentRepository; |
| 13 | +import java.io.ByteArrayInputStream; |
| 14 | +import java.util.Optional; |
| 15 | +import org.junit.jupiter.api.Test; |
| 16 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 17 | +import org.mockito.InjectMocks; |
| 18 | +import org.mockito.Mock; |
| 19 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 20 | + |
| 21 | +@ExtendWith(MockitoExtension.class) |
| 22 | +class AnalyzedDocumentQueryServiceTest { |
| 23 | + |
| 24 | + @Mock AnalyzedDocumentRepository documentRepository; |
| 25 | + @Mock ObjectStorageClient storage; |
| 26 | + @InjectMocks AnalyzedDocumentQueryService service; |
| 27 | + |
| 28 | + // 분석 원문 프록시(A5) — presigned URL 은 내부 호스트라 브라우저 직접 접근 불가, |
| 29 | + // Core 가 소유권 검증 후 바이트를 중계한다. |
| 30 | + @Test |
| 31 | + void getContentForUser_streamsMarkdownFromStorage() { |
| 32 | + AnalyzedDocument doc = mock(AnalyzedDocument.class); |
| 33 | + when(doc.getDocumentPath()).thenReturn("analyzed/resume/42/summary.md"); |
| 34 | + when(documentRepository.findActiveByIdAndOwner(42L, 1L)).thenReturn(Optional.of(doc)); |
| 35 | + when(storage.get("analyzed/resume/42/summary.md")) |
| 36 | + .thenReturn(new ByteArrayInputStream("## 개요".getBytes())); |
| 37 | + |
| 38 | + assertThat(service.getContentForUser(1L, 42L)).isNotNull(); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + void getContentForUser_throwsNotFoundForOthersDocument() { |
| 43 | + when(documentRepository.findActiveByIdAndOwner(42L, 1L)).thenReturn(Optional.empty()); |
| 44 | + |
| 45 | + assertThatThrownBy(() -> service.getContentForUser(1L, 42L)) |
| 46 | + .isInstanceOfSatisfying(DomainException.class, |
| 47 | + e -> assertThat(e.getErrorCode()).isEqualTo(ApiErrorCode.DOC_NOT_FOUND)); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + void getContentForUser_throwsWhenNoDocumentPathYet() { |
| 52 | + AnalyzedDocument doc = mock(AnalyzedDocument.class); |
| 53 | + when(doc.getDocumentPath()).thenReturn(null); |
| 54 | + when(documentRepository.findActiveByIdAndOwner(42L, 1L)).thenReturn(Optional.of(doc)); |
| 55 | + |
| 56 | + assertThatThrownBy(() -> service.getContentForUser(1L, 42L)) |
| 57 | + .isInstanceOfSatisfying(DomainException.class, |
| 58 | + e -> assertThat(e.getErrorCode()).isEqualTo(ApiErrorCode.DOC_NOT_ANALYZED)); |
| 59 | + } |
| 60 | +} |
0 commit comments