test: fix test

This commit is contained in:
usbharu 2023-10-10 18:01:57 +09:00
parent 7fff8e39d4
commit 3f830097ed
1 changed files with 116 additions and 101 deletions

View File

@ -10,6 +10,7 @@ import dev.usbharu.hideout.domain.model.hideout.entity.User
import dev.usbharu.hideout.domain.model.hideout.entity.Visibility import dev.usbharu.hideout.domain.model.hideout.entity.Visibility
import dev.usbharu.hideout.domain.model.job.DeliverPostJob import dev.usbharu.hideout.domain.model.job.DeliverPostJob
import dev.usbharu.hideout.query.FollowerQueryService import dev.usbharu.hideout.query.FollowerQueryService
import dev.usbharu.hideout.query.MediaQueryService
import dev.usbharu.hideout.query.UserQueryService import dev.usbharu.hideout.query.UserQueryService
import dev.usbharu.hideout.service.job.JobQueueParentService import dev.usbharu.hideout.service.job.JobQueueParentService
import io.ktor.client.* import io.ktor.client.*
@ -19,6 +20,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.runTest
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.Mockito.anyLong
import org.mockito.Mockito.eq import org.mockito.Mockito.eq
import org.mockito.kotlin.* import org.mockito.kotlin.*
import utils.JsonObjectMapper import utils.JsonObjectMapper
@ -29,7 +31,11 @@ import kotlin.test.assertEquals
class APNoteServiceImplTest { class APNoteServiceImplTest {
@Test @Test
fun `createPost 新しい投稿`() = runTest { fun `createPost 新しい投稿`() {
val mediaQueryService = mock<MediaQueryService> {
onBlocking { findByPostId(anyLong()) } doReturn emptyList()
}
runTest {
val followers = listOf( val followers = listOf(
User.of( User.of(
2L, 2L,
@ -90,6 +96,7 @@ class APNoteServiceImplTest {
objectMapper = objectMapper, objectMapper = objectMapper,
applicationConfig = testApplicationConfig, applicationConfig = testApplicationConfig,
postService = mock(), postService = mock(),
mediaQueryService = mediaQueryService
) )
val postEntity = Post.of( val postEntity = Post.of(
1L, 1L,
@ -103,9 +110,14 @@ class APNoteServiceImplTest {
activityPubNoteService.createNote(postEntity) activityPubNoteService.createNote(postEntity)
verify(jobQueueParentService, times(2)).schedule(eq(DeliverPostJob), any()) verify(jobQueueParentService, times(2)).schedule(eq(DeliverPostJob), any())
} }
}
@Test @Test
fun `createPostJob 新しい投稿のJob`() = runTest { fun `createPostJob 新しい投稿のJob`() {
runTest {
val mediaQueryService = mock<MediaQueryService> {
onBlocking { findByPostId(anyLong()) } doReturn emptyList()
}
Config.configData = ConfigData(objectMapper = JsonObjectMapper.objectMapper) Config.configData = ConfigData(objectMapper = JsonObjectMapper.objectMapper)
val httpClient = HttpClient( val httpClient = HttpClient(
MockEngine { httpRequestData -> MockEngine { httpRequestData ->
@ -124,6 +136,7 @@ class APNoteServiceImplTest {
objectMapper = objectMapper, objectMapper = objectMapper,
applicationConfig = testApplicationConfig, applicationConfig = testApplicationConfig,
postService = mock(), postService = mock(),
mediaQueryService = mediaQueryService
) )
activityPubNoteService.createNoteJob( activityPubNoteService.createNoteJob(
JobProps( JobProps(
@ -137,10 +150,12 @@ class APNoteServiceImplTest {
"visibility": 0, "visibility": 0,
"url": "https://example.com" "url": "https://example.com"
}""", }""",
DeliverPostJob.inbox.name to "https://follower.example.com/inbox" DeliverPostJob.inbox.name to "https://follower.example.com/inbox",
DeliverPostJob.media.name to "[]"
), ),
json = Json json = Json
) )
) )
} }
} }
}