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