mirror of https://github.com/usbharu/Hideout.git
test: fix test
This commit is contained in:
parent
7fff8e39d4
commit
3f830097ed
|
@ -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,118 +31,131 @@ import kotlin.test.assertEquals
|
||||||
|
|
||||||
class APNoteServiceImplTest {
|
class APNoteServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
fun `createPost 新しい投稿`() = runTest {
|
fun `createPost 新しい投稿`() {
|
||||||
val followers = listOf(
|
val mediaQueryService = mock<MediaQueryService> {
|
||||||
User.of(
|
onBlocking { findByPostId(anyLong()) } doReturn emptyList()
|
||||||
2L,
|
}
|
||||||
"follower",
|
runTest {
|
||||||
"follower.example.com",
|
val followers = listOf(
|
||||||
"followerUser",
|
User.of(
|
||||||
"test follower user",
|
2L,
|
||||||
"https://follower.example.com/inbox",
|
"follower",
|
||||||
"https://follower.example.com/outbox",
|
"follower.example.com",
|
||||||
"https://follower.example.com",
|
"followerUser",
|
||||||
"https://follower.example.com",
|
"test follower user",
|
||||||
publicKey = "",
|
"https://follower.example.com/inbox",
|
||||||
createdAt = Instant.now()
|
"https://follower.example.com/outbox",
|
||||||
),
|
"https://follower.example.com",
|
||||||
User.of(
|
"https://follower.example.com",
|
||||||
3L,
|
publicKey = "",
|
||||||
"follower2",
|
createdAt = Instant.now()
|
||||||
"follower2.example.com",
|
),
|
||||||
"follower2User",
|
User.of(
|
||||||
"test follower2 user",
|
3L,
|
||||||
"https://follower2.example.com/inbox",
|
"follower2",
|
||||||
"https://follower2.example.com/outbox",
|
"follower2.example.com",
|
||||||
"https://follower2.example.com",
|
"follower2User",
|
||||||
"https://follower2.example.com",
|
"test follower2 user",
|
||||||
publicKey = "",
|
"https://follower2.example.com/inbox",
|
||||||
createdAt = Instant.now()
|
"https://follower2.example.com/outbox",
|
||||||
|
"https://follower2.example.com",
|
||||||
|
"https://follower2.example.com",
|
||||||
|
publicKey = "",
|
||||||
|
createdAt = Instant.now()
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
val userQueryService = mock<UserQueryService> {
|
||||||
val userQueryService = mock<UserQueryService> {
|
onBlocking { findById(eq(1L)) } doReturn User.of(
|
||||||
onBlocking { findById(eq(1L)) } doReturn User.of(
|
1L,
|
||||||
|
"test",
|
||||||
|
"example.com",
|
||||||
|
"testUser",
|
||||||
|
"test user",
|
||||||
|
"a",
|
||||||
|
"https://example.com/inbox",
|
||||||
|
"https://example.com/outbox",
|
||||||
|
"https://example.com",
|
||||||
|
publicKey = "",
|
||||||
|
privateKey = "a",
|
||||||
|
createdAt = Instant.now()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val followerQueryService = mock<FollowerQueryService> {
|
||||||
|
onBlocking { findFollowersById(eq(1L)) } doReturn followers
|
||||||
|
}
|
||||||
|
val jobQueueParentService = mock<JobQueueParentService>()
|
||||||
|
val activityPubNoteService =
|
||||||
|
APNoteServiceImpl(
|
||||||
|
httpClient = mock(),
|
||||||
|
jobQueueParentService = jobQueueParentService,
|
||||||
|
postRepository = mock(),
|
||||||
|
apUserService = mock(),
|
||||||
|
userQueryService = userQueryService,
|
||||||
|
followerQueryService = followerQueryService,
|
||||||
|
postQueryService = mock(),
|
||||||
|
objectMapper = objectMapper,
|
||||||
|
applicationConfig = testApplicationConfig,
|
||||||
|
postService = mock(),
|
||||||
|
mediaQueryService = mediaQueryService
|
||||||
|
)
|
||||||
|
val postEntity = Post.of(
|
||||||
1L,
|
1L,
|
||||||
"test",
|
1L,
|
||||||
"example.com",
|
null,
|
||||||
"testUser",
|
"test text",
|
||||||
"test user",
|
1L,
|
||||||
"a",
|
Visibility.PUBLIC,
|
||||||
"https://example.com/inbox",
|
"https://example.com"
|
||||||
"https://example.com/outbox",
|
|
||||||
"https://example.com",
|
|
||||||
publicKey = "",
|
|
||||||
privateKey = "a",
|
|
||||||
createdAt = Instant.now()
|
|
||||||
)
|
)
|
||||||
|
activityPubNoteService.createNote(postEntity)
|
||||||
|
verify(jobQueueParentService, times(2)).schedule(eq(DeliverPostJob), any())
|
||||||
}
|
}
|
||||||
val followerQueryService = mock<FollowerQueryService> {
|
}
|
||||||
onBlocking { findFollowersById(eq(1L)) } doReturn followers
|
|
||||||
}
|
@Test
|
||||||
val jobQueueParentService = mock<JobQueueParentService>()
|
fun `createPostJob 新しい投稿のJob`() {
|
||||||
val activityPubNoteService =
|
runTest {
|
||||||
APNoteServiceImpl(
|
val mediaQueryService = mock<MediaQueryService> {
|
||||||
httpClient = mock(),
|
onBlocking { findByPostId(anyLong()) } doReturn emptyList()
|
||||||
jobQueueParentService = jobQueueParentService,
|
}
|
||||||
|
Config.configData = ConfigData(objectMapper = JsonObjectMapper.objectMapper)
|
||||||
|
val httpClient = HttpClient(
|
||||||
|
MockEngine { httpRequestData ->
|
||||||
|
assertEquals("https://follower.example.com/inbox", httpRequestData.url.toString())
|
||||||
|
respondOk()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
val activityPubNoteService = APNoteServiceImpl(
|
||||||
|
httpClient = httpClient,
|
||||||
|
jobQueueParentService = mock(),
|
||||||
postRepository = mock(),
|
postRepository = mock(),
|
||||||
apUserService = mock(),
|
apUserService = mock(),
|
||||||
userQueryService = userQueryService,
|
userQueryService = mock(),
|
||||||
followerQueryService = followerQueryService,
|
followerQueryService = mock(),
|
||||||
postQueryService = mock(),
|
postQueryService = mock(),
|
||||||
objectMapper = objectMapper,
|
objectMapper = objectMapper,
|
||||||
applicationConfig = testApplicationConfig,
|
applicationConfig = testApplicationConfig,
|
||||||
postService = mock(),
|
postService = mock(),
|
||||||
|
mediaQueryService = mediaQueryService
|
||||||
)
|
)
|
||||||
val postEntity = Post.of(
|
activityPubNoteService.createNoteJob(
|
||||||
1L,
|
JobProps(
|
||||||
1L,
|
data = mapOf<String, Any>(
|
||||||
null,
|
DeliverPostJob.actor.name to "https://follower.example.com",
|
||||||
"test text",
|
DeliverPostJob.post.name to """{
|
||||||
1L,
|
"id": 1,
|
||||||
Visibility.PUBLIC,
|
"userId": 1,
|
||||||
"https://example.com"
|
"text": "test text",
|
||||||
)
|
"createdAt": 132525324,
|
||||||
activityPubNoteService.createNote(postEntity)
|
"visibility": 0,
|
||||||
verify(jobQueueParentService, times(2)).schedule(eq(DeliverPostJob), any())
|
"url": "https://example.com"
|
||||||
}
|
}""",
|
||||||
|
DeliverPostJob.inbox.name to "https://follower.example.com/inbox",
|
||||||
@Test
|
DeliverPostJob.media.name to "[]"
|
||||||
fun `createPostJob 新しい投稿のJob`() = runTest {
|
),
|
||||||
Config.configData = ConfigData(objectMapper = JsonObjectMapper.objectMapper)
|
json = Json
|
||||||
val httpClient = HttpClient(
|
)
|
||||||
MockEngine { httpRequestData ->
|
|
||||||
assertEquals("https://follower.example.com/inbox", httpRequestData.url.toString())
|
|
||||||
respondOk()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
val activityPubNoteService = APNoteServiceImpl(
|
|
||||||
httpClient = httpClient,
|
|
||||||
jobQueueParentService = mock(),
|
|
||||||
postRepository = mock(),
|
|
||||||
apUserService = mock(),
|
|
||||||
userQueryService = mock(),
|
|
||||||
followerQueryService = mock(),
|
|
||||||
postQueryService = mock(),
|
|
||||||
objectMapper = objectMapper,
|
|
||||||
applicationConfig = testApplicationConfig,
|
|
||||||
postService = mock(),
|
|
||||||
)
|
|
||||||
activityPubNoteService.createNoteJob(
|
|
||||||
JobProps(
|
|
||||||
data = mapOf<String, Any>(
|
|
||||||
DeliverPostJob.actor.name to "https://follower.example.com",
|
|
||||||
DeliverPostJob.post.name to """{
|
|
||||||
"id": 1,
|
|
||||||
"userId": 1,
|
|
||||||
"text": "test text",
|
|
||||||
"createdAt": 132525324,
|
|
||||||
"visibility": 0,
|
|
||||||
"url": "https://example.com"
|
|
||||||
}""",
|
|
||||||
DeliverPostJob.inbox.name to "https://follower.example.com/inbox"
|
|
||||||
),
|
|
||||||
json = Json
|
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue