mirror of https://github.com/usbharu/Hideout.git
test: ApNoteJobServiceImplのテストを移動
This commit is contained in:
parent
89e1675611
commit
95f3da5bb6
|
@ -1,4 +1,4 @@
|
|||
@file:OptIn(ExperimentalCoroutinesApi::class) @file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
@file:OptIn(ExperimentalCoroutinesApi::class)
|
||||
|
||||
package dev.usbharu.hideout.service.ap
|
||||
|
||||
|
@ -20,7 +20,6 @@ import dev.usbharu.hideout.query.PostQueryService
|
|||
import dev.usbharu.hideout.query.UserQueryService
|
||||
import dev.usbharu.hideout.repository.PostRepository
|
||||
import dev.usbharu.hideout.service.ap.APNoteServiceImpl.Companion.public
|
||||
import dev.usbharu.hideout.service.ap.job.ApNoteJobServiceImpl
|
||||
import dev.usbharu.hideout.service.ap.resource.APResourceResolveService
|
||||
import dev.usbharu.hideout.service.core.TwitterSnowflakeIdGenerateService
|
||||
import dev.usbharu.hideout.service.job.JobQueueParentService
|
||||
|
@ -35,12 +34,10 @@ import io.ktor.http.*
|
|||
import io.ktor.http.content.*
|
||||
import io.ktor.util.*
|
||||
import io.ktor.util.date.*
|
||||
import kjob.core.job.JobProps
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
|
@ -48,7 +45,6 @@ import org.mockito.Mockito.anyLong
|
|||
import org.mockito.kotlin.*
|
||||
import utils.JsonObjectMapper.objectMapper
|
||||
import utils.PostBuilder
|
||||
import utils.TestTransaction
|
||||
import utils.UserBuilder
|
||||
import java.net.URL
|
||||
import java.time.Instant
|
||||
|
@ -412,31 +408,5 @@ class APNoteServiceImplTest {
|
|||
assertEquals(note, fetchNote)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `createPostJob 新しい投稿のJob`() {
|
||||
runTest {
|
||||
val activityPubNoteService = ApNoteJobServiceImpl(
|
||||
|
||||
userQueryService = mock(),
|
||||
objectMapper = objectMapper,
|
||||
apRequestService = mock(),
|
||||
transaction = TestTransaction,
|
||||
applicationConfig = ApplicationConfig(URL("https://example.com"))
|
||||
)
|
||||
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", DeliverPostJob.media.name to "[]"
|
||||
), json = Json
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package dev.usbharu.hideout.service.ap.job
|
||||
|
||||
import dev.usbharu.hideout.config.ApplicationConfig
|
||||
import dev.usbharu.hideout.domain.model.ap.Create
|
||||
import dev.usbharu.hideout.domain.model.ap.Note
|
||||
import dev.usbharu.hideout.domain.model.job.DeliverPostJob
|
||||
import dev.usbharu.hideout.query.UserQueryService
|
||||
import dev.usbharu.hideout.service.ap.APNoteServiceImpl
|
||||
import dev.usbharu.hideout.service.ap.APRequestService
|
||||
import kjob.core.job.JobProps
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.kotlin.*
|
||||
import utils.JsonObjectMapper
|
||||
import utils.TestTransaction
|
||||
import utils.UserBuilder
|
||||
import java.net.URL
|
||||
import java.time.Instant
|
||||
|
||||
class ApNoteJobServiceImplTest {
|
||||
@Test
|
||||
fun `createPostJob 新しい投稿のJob`() = runTest {
|
||||
val apRequestService = mock<APRequestService>()
|
||||
val user = UserBuilder.localUserOf()
|
||||
val userQueryService = mock<UserQueryService> {
|
||||
onBlocking { findByUrl(eq(user.url)) } doReturn user
|
||||
}
|
||||
val activityPubNoteService = ApNoteJobServiceImpl(
|
||||
|
||||
userQueryService = userQueryService,
|
||||
objectMapper = JsonObjectMapper.objectMapper,
|
||||
apRequestService = apRequestService,
|
||||
transaction = TestTransaction,
|
||||
applicationConfig = ApplicationConfig(URL("https://example.com"))
|
||||
)
|
||||
val remoteUserOf = UserBuilder.remoteUserOf()
|
||||
activityPubNoteService.createNoteJob(
|
||||
JobProps(
|
||||
data = mapOf<String, Any>(
|
||||
DeliverPostJob.actor.name to user.url,
|
||||
DeliverPostJob.post.name to """{
|
||||
"id": 1,
|
||||
"userId": ${user.id},
|
||||
"text": "test text",
|
||||
"createdAt": 132525324,
|
||||
"visibility": 0,
|
||||
"url": "https://example.com"
|
||||
}""",
|
||||
DeliverPostJob.inbox.name to remoteUserOf.inbox,
|
||||
DeliverPostJob.media.name to "[]"
|
||||
), json = Json
|
||||
)
|
||||
)
|
||||
|
||||
val note = Note(
|
||||
name = "Note",
|
||||
id = "https://example.com",
|
||||
attributedTo = user.url,
|
||||
content = "test text",
|
||||
published = Instant.ofEpochMilli(132525324).toString(),
|
||||
to = listOfNotNull(APNoteServiceImpl.public, user.followers)
|
||||
)
|
||||
val create = Create(
|
||||
name = "Create Note",
|
||||
`object` = note,
|
||||
actor = note.attributedTo,
|
||||
id = "https://example.com/create/note/1"
|
||||
)
|
||||
verify(apRequestService, times(1)).apPost(
|
||||
eq(remoteUserOf.inbox),
|
||||
eq(create),
|
||||
eq(user)
|
||||
)
|
||||
}
|
||||
}
|
|
@ -44,8 +44,8 @@ object UserBuilder {
|
|||
privateKey = privateKey,
|
||||
createdAt = createdAt,
|
||||
keyId = keyId,
|
||||
followers = following,
|
||||
following = followers
|
||||
followers = followers,
|
||||
following = following
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -78,8 +78,8 @@ object UserBuilder {
|
|||
privateKey = null,
|
||||
createdAt = createdAt,
|
||||
keyId = keyId,
|
||||
followers = following,
|
||||
following = followers
|
||||
followers = followers,
|
||||
following = following
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue