Skip to content

Commit 0dfd1a8

Browse files
committed
test: 문서 목록 read model 삭제 제외 조회 검증
- 목록 조회에서 deleted=true read model이 제외되는지 검증 - 제목 검색 조회에서도 삭제된 read model이 제외되는지 검증
1 parent afdbedb commit 0dfd1a8

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package io.ejangs.docsa.domain.doc.readmodel.dao.mongodb;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import io.ejangs.docsa.domain.doc.readmodel.document.DocListReadModel;
6+
import io.ejangs.docsa.domain.doc.readmodel.dto.payload.DocCreatedPayload;
7+
import io.ejangs.docsa.domain.doc.thumbnail.entity.Thumbnail.ThumbnailStatus;
8+
import java.time.LocalDateTime;
9+
import java.util.List;
10+
import org.junit.jupiter.api.AfterEach;
11+
import org.junit.jupiter.api.BeforeEach;
12+
import org.junit.jupiter.api.DisplayName;
13+
import org.junit.jupiter.api.Test;
14+
import org.springframework.beans.factory.annotation.Autowired;
15+
import org.springframework.boot.test.context.SpringBootTest;
16+
import org.springframework.data.domain.Page;
17+
import org.springframework.data.domain.PageRequest;
18+
import org.springframework.test.context.ActiveProfiles;
19+
20+
@SpringBootTest
21+
@ActiveProfiles("test")
22+
class DocListReadModelRepositoryIntegrationTest {
23+
24+
@Autowired
25+
private DocListReadModelRepository docListReadModelRepository;
26+
27+
private final Long userId = System.currentTimeMillis();
28+
private final Long activeDocId = userId + 1;
29+
private final Long deletedDocId = userId + 2;
30+
31+
@BeforeEach
32+
void setUp() {
33+
docListReadModelRepository.deleteAllById(List.of(activeDocId, deletedDocId));
34+
}
35+
36+
@AfterEach
37+
void cleanUp() {
38+
docListReadModelRepository.deleteAllById(List.of(activeDocId, deletedDocId));
39+
}
40+
41+
@Test
42+
@DisplayName("문서 목록 조회시 삭제된 read model은 제외한다")
43+
void findByUserIdAndDeletedFalse_excludesDeleted() {
44+
DocListReadModel active = readModel(activeDocId, "문서 1", 1L);
45+
DocListReadModel deleted = readModel(deletedDocId, "문서 2", 2L);
46+
deleted.markDeleted(3L);
47+
docListReadModelRepository.saveAll(List.of(active, deleted));
48+
49+
Page<DocListReadModel> result = docListReadModelRepository.findByUserIdAndDeletedFalse(
50+
userId,
51+
PageRequest.of(0, 10)
52+
);
53+
54+
assertThat(result.getContent())
55+
.extracting(DocListReadModel::getId)
56+
.containsExactly(activeDocId);
57+
}
58+
59+
@Test
60+
@DisplayName("문서 목록 검색시 삭제된 read model은 제외한다")
61+
void searchByTitle_excludesDeleted() {
62+
DocListReadModel active = readModel(activeDocId, "검색 문서", 1L);
63+
DocListReadModel deleted = readModel(deletedDocId, "검색 문서", 2L);
64+
deleted.markDeleted(3L);
65+
docListReadModelRepository.saveAll(List.of(active, deleted));
66+
67+
Page<DocListReadModel> result =
68+
docListReadModelRepository.findByUserIdAndDeletedFalseAndTitleContainingIgnoreCase(
69+
userId,
70+
"검색",
71+
PageRequest.of(0, 10)
72+
);
73+
74+
assertThat(result.getContent())
75+
.extracting(DocListReadModel::getId)
76+
.containsExactly(activeDocId);
77+
}
78+
79+
private DocListReadModel readModel(Long docId, String title, Long eventId) {
80+
LocalDateTime createdAt = LocalDateTime.of(2026, 1, 1, 10, 0);
81+
LocalDateTime updatedAt = LocalDateTime.of(2026, 1, 2, 10, 0);
82+
return DocListReadModel.create(
83+
new DocCreatedPayload(
84+
docId,
85+
userId,
86+
title,
87+
createdAt,
88+
updatedAt,
89+
10L,
90+
null,
91+
ThumbnailStatus.EMPTY
92+
),
93+
eventId
94+
);
95+
}
96+
}

0 commit comments

Comments
 (0)