11package no.nav.klage.document.repositories
22
3+ import no.nav.klage.document.domain.Comment
34import no.nav.klage.document.domain.Document
45import org.assertj.core.api.Assertions.assertThat
56import org.junit.jupiter.api.Test
@@ -16,7 +17,7 @@ import java.time.LocalDateTime
1617@DataJpaTest
1718@Testcontainers
1819@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase .Replace .NONE )
19- class DocumentRepositoryTest {
20+ class RepositoryTest {
2021
2122 companion object {
2223 @Container
@@ -30,8 +31,11 @@ class DocumentRepositoryTest {
3031 @Autowired
3132 lateinit var documentRepository: DocumentRepository
3233
34+ @Autowired
35+ lateinit var commentRepository: CommentRepository
36+
3337 @Test
34- fun `add documents works ` () {
38+ fun `add document and comments work ` () {
3539
3640 val now = LocalDateTime .now()
3741
@@ -48,6 +52,30 @@ class DocumentRepositoryTest {
4852
4953 val foundDocument = documentRepository.findById(document.id).get()
5054 assertThat(foundDocument).isEqualTo(document)
55+
56+ val comment1 = Comment (
57+ documentId = document.id,
58+ text = " my comment 1" ,
59+ created = now.plusDays(1 ),
60+ modified = now.plusDays(1 )
61+ )
62+
63+ val comment2 = Comment (
64+ documentId = document.id,
65+ text = " my comment 2" ,
66+ created = now.plusDays(2 ),
67+ modified = now.plusDays(2 )
68+ )
69+
70+ commentRepository.save(comment1)
71+ commentRepository.save(comment2)
72+
73+ testEntityManager.flush()
74+ testEntityManager.clear()
75+
76+ val comments = commentRepository.findByDocumentId(document.id)
77+
78+ assertThat(comments).hasSize(2 )
5179 }
5280
5381}
0 commit comments