mirror of https://github.com/usbharu/Hideout.git
test: 不要なテストを削除
This commit is contained in:
parent
640dff53cf
commit
a3adba6813
|
@ -4,7 +4,6 @@ import dev.usbharu.hideout.activitypub.domain.exception.JsonParseException
|
|||
import dev.usbharu.hideout.activitypub.service.common.APService
|
||||
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
||||
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||
import io.ktor.http.*
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
@ -12,10 +11,7 @@ import org.junit.jupiter.api.extension.ExtendWith
|
|||
import org.mockito.InjectMocks
|
||||
import org.mockito.Mock
|
||||
import org.mockito.junit.jupiter.MockitoExtension
|
||||
import org.mockito.kotlin.doReturn
|
||||
import org.mockito.kotlin.doThrow
|
||||
import org.mockito.kotlin.eq
|
||||
import org.mockito.kotlin.whenever
|
||||
import org.mockito.kotlin.*
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.test.web.servlet.MockMvc
|
||||
import org.springframework.test.web.servlet.get
|
||||
|
@ -44,11 +40,15 @@ class InboxControllerImplTest {
|
|||
|
||||
val json = """{"type":"Follow"}"""
|
||||
whenever(apService.parseActivity(eq(json))).doReturn(ActivityType.Follow)
|
||||
whenever(apService.processActivity(eq(json), eq(ActivityType.Follow))).doReturn(
|
||||
ActivityPubStringResponse(
|
||||
HttpStatusCode.Accepted, ""
|
||||
)
|
||||
whenever(
|
||||
apService.processActivity(
|
||||
eq(json),
|
||||
eq(ActivityType.Follow),
|
||||
any(),
|
||||
any()
|
||||
|
||||
)
|
||||
).doReturn(Unit)
|
||||
|
||||
mockMvc
|
||||
.post("/inbox") {
|
||||
|
@ -86,7 +86,9 @@ class InboxControllerImplTest {
|
|||
whenever(
|
||||
apService.processActivity(
|
||||
eq(json),
|
||||
eq(ActivityType.Follow)
|
||||
eq(ActivityType.Follow),
|
||||
any(),
|
||||
any()
|
||||
)
|
||||
).doThrow(FailedToGetResourcesException::class)
|
||||
|
||||
|
@ -113,10 +115,8 @@ class InboxControllerImplTest {
|
|||
|
||||
val json = """{"type":"Follow"}"""
|
||||
whenever(apService.parseActivity(eq(json))).doReturn(ActivityType.Follow)
|
||||
whenever(apService.processActivity(eq(json), eq(ActivityType.Follow))).doReturn(
|
||||
ActivityPubStringResponse(
|
||||
HttpStatusCode.Accepted, ""
|
||||
)
|
||||
whenever(apService.processActivity(eq(json), eq(ActivityType.Follow), any(), any())).doReturn(
|
||||
Unit
|
||||
)
|
||||
|
||||
mockMvc
|
||||
|
@ -155,7 +155,9 @@ class InboxControllerImplTest {
|
|||
whenever(
|
||||
apService.processActivity(
|
||||
eq(json),
|
||||
eq(ActivityType.Follow)
|
||||
eq(ActivityType.Follow),
|
||||
any(),
|
||||
any()
|
||||
)
|
||||
).doThrow(FailedToGetResourcesException::class)
|
||||
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
package dev.usbharu.hideout.activitypub.service.activity.accept
|
||||
|
||||
import dev.usbharu.hideout.activitypub.domain.exception.IllegalActivityPubObjectException
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Accept
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Like
|
||||
import dev.usbharu.hideout.core.query.FollowerQueryService
|
||||
import dev.usbharu.hideout.core.query.UserQueryService
|
||||
import dev.usbharu.hideout.core.service.user.UserService
|
||||
import io.ktor.http.*
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import org.mockito.kotlin.*
|
||||
import utils.TestTransaction
|
||||
import utils.UserBuilder
|
||||
|
||||
class APAcceptServiceImplTest {
|
||||
|
||||
@Test
|
||||
fun `receiveAccept 正常なAcceptを処理できる`() = runTest {
|
||||
val actor = "https://example.com"
|
||||
val follower = "https://follower.example.com"
|
||||
val targetUser = UserBuilder.localUserOf()
|
||||
val followerUser = UserBuilder.localUserOf()
|
||||
val userQueryService = mock<UserQueryService> {
|
||||
onBlocking { findByUrl(eq(actor)) } doReturn targetUser
|
||||
onBlocking { findByUrl(eq(follower)) } doReturn followerUser
|
||||
}
|
||||
val followerQueryService = mock<FollowerQueryService> {
|
||||
onBlocking { alreadyFollow(eq(targetUser.id), eq(followerUser.id)) } doReturn false
|
||||
}
|
||||
val userService = mock<UserService>()
|
||||
val apAcceptServiceImpl =
|
||||
APAcceptServiceImpl(userService, userQueryService, followerQueryService, TestTransaction)
|
||||
|
||||
val accept = Accept(
|
||||
name = "Accept",
|
||||
`object` = Follow(
|
||||
name = "",
|
||||
`object` = actor,
|
||||
actor = follower
|
||||
),
|
||||
actor = actor
|
||||
)
|
||||
|
||||
|
||||
val actual = apAcceptServiceImpl.receiveAccept(accept)
|
||||
assertEquals(ActivityPubStringResponse(HttpStatusCode.OK, "accepted"), actual)
|
||||
verify(userService, times(1)).follow(eq(targetUser.id), eq(followerUser.id))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `receiveAccept 既にフォローしている場合は無視する`() = runTest {
|
||||
|
||||
val actor = "https://example.com"
|
||||
val follower = "https://follower.example.com"
|
||||
val targetUser = UserBuilder.localUserOf()
|
||||
val followerUser = UserBuilder.localUserOf()
|
||||
val userQueryService = mock<UserQueryService> {
|
||||
onBlocking { findByUrl(eq(actor)) } doReturn targetUser
|
||||
onBlocking { findByUrl(eq(follower)) } doReturn followerUser
|
||||
}
|
||||
val followerQueryService = mock<FollowerQueryService> {
|
||||
onBlocking { alreadyFollow(eq(targetUser.id), eq(followerUser.id)) } doReturn true
|
||||
}
|
||||
val userService = mock<UserService>()
|
||||
val apAcceptServiceImpl =
|
||||
APAcceptServiceImpl(userService, userQueryService, followerQueryService, TestTransaction)
|
||||
|
||||
val accept = Accept(
|
||||
name = "Accept",
|
||||
`object` = Follow(
|
||||
name = "",
|
||||
`object` = actor,
|
||||
actor = follower
|
||||
),
|
||||
actor = actor
|
||||
)
|
||||
|
||||
|
||||
val actual = apAcceptServiceImpl.receiveAccept(accept)
|
||||
assertEquals(ActivityPubStringResponse(HttpStatusCode.OK, "accepted"), actual)
|
||||
verify(userService, times(0)).follow(eq(targetUser.id), eq(followerUser.id))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `revieveAccept AcceptのobjectのtypeがFollow以外の場合IllegalActivityPubObjectExceptionがthrowされる`() =
|
||||
runTest {
|
||||
val accept = Accept(
|
||||
name = "Accept",
|
||||
`object` = Like(
|
||||
name = "Like",
|
||||
actor = "actor",
|
||||
id = "https://example.com",
|
||||
`object` = "https://example.com",
|
||||
content = "aaaa"
|
||||
),
|
||||
actor = "https://example.com"
|
||||
)
|
||||
|
||||
val apAcceptServiceImpl = APAcceptServiceImpl(mock(), mock(), mock(), TestTransaction)
|
||||
|
||||
assertThrows<IllegalActivityPubObjectException> {
|
||||
apAcceptServiceImpl.receiveAccept(accept)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package dev.usbharu.hideout.activitypub.service.activity.create
|
||||
|
||||
import dev.usbharu.hideout.activitypub.domain.exception.IllegalActivityPubObjectException
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Create
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Like
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Note
|
||||
import dev.usbharu.hideout.activitypub.service.objects.note.APNoteService
|
||||
import io.ktor.http.*
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import org.mockito.kotlin.*
|
||||
import utils.TestTransaction
|
||||
|
||||
class APCreateServiceImplTest {
|
||||
|
||||
@Test
|
||||
fun `receiveCreate 正常なCreateを処理できる`() = runTest {
|
||||
val create = Create(
|
||||
name = "Create",
|
||||
`object` = Note(
|
||||
name = "Note",
|
||||
id = "https://example.com/note",
|
||||
attributedTo = "https://example.com/actor",
|
||||
content = "Hello World",
|
||||
published = "Date: Wed, 21 Oct 2015 07:28:00 GMT"
|
||||
),
|
||||
actor = "https://example.com/actor",
|
||||
id = "https://example.com/create",
|
||||
)
|
||||
|
||||
val apNoteService = mock<APNoteService>()
|
||||
val apCreateServiceImpl = APCreateServiceImpl(apNoteService, TestTransaction)
|
||||
|
||||
val actual = ActivityPubStringResponse(HttpStatusCode.OK, "Created")
|
||||
|
||||
val receiveCreate = apCreateServiceImpl.receiveCreate(create)
|
||||
verify(apNoteService, times(1)).fetchNote(any<Note>(), anyOrNull())
|
||||
assertEquals(actual, receiveCreate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `reveiveCreate CreateのobjectのtypeがNote以外の場合IllegalActivityPubObjectExceptionがthrowされる`() = runTest {
|
||||
val create = Create(
|
||||
name = "Create",
|
||||
`object` = Like(
|
||||
name = "Like",
|
||||
id = "https://example.com/note",
|
||||
actor = "https://example.com/actor",
|
||||
`object` = "https://example.com/create",
|
||||
content = "aaa"
|
||||
),
|
||||
actor = "https://example.com/actor",
|
||||
id = "https://example.com/create",
|
||||
)
|
||||
|
||||
val apCreateServiceImpl = APCreateServiceImpl(mock(), TestTransaction)
|
||||
assertThrows<IllegalActivityPubObjectException> {
|
||||
apCreateServiceImpl.receiveCreate(create)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,176 +0,0 @@
|
|||
@file:OptIn(ExperimentalCoroutinesApi::class)
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package dev.usbharu.hideout.activitypub.service.activity.follow
|
||||
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Image
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Key
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Person
|
||||
import dev.usbharu.hideout.activitypub.service.objects.user.APUserService
|
||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||
import dev.usbharu.hideout.application.config.CharacterLimit
|
||||
import dev.usbharu.hideout.core.domain.model.post.Post
|
||||
import dev.usbharu.hideout.core.domain.model.user.User
|
||||
import dev.usbharu.hideout.core.external.job.ReceiveFollowJob
|
||||
import dev.usbharu.hideout.core.query.UserQueryService
|
||||
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
||||
import dev.usbharu.hideout.core.service.user.UserService
|
||||
import kjob.core.dsl.ScheduleContext
|
||||
import kjob.core.job.JobProps
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
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.mockito.ArgumentMatchers.anyString
|
||||
import org.mockito.kotlin.*
|
||||
import utils.JsonObjectMapper.objectMapper
|
||||
import utils.TestTransaction
|
||||
import java.net.URL
|
||||
import java.time.Instant
|
||||
|
||||
class APReceiveFollowServiceImplTest {
|
||||
|
||||
val userBuilder = User.UserBuilder(CharacterLimit(), ApplicationConfig(URL("https://example.com")))
|
||||
val postBuilder = Post.PostBuilder(CharacterLimit())
|
||||
|
||||
@Test
|
||||
fun `receiveFollow フォロー受付処理`() = runTest {
|
||||
val jobQueueParentService = mock<JobQueueParentService> {
|
||||
onBlocking { schedule(eq(ReceiveFollowJob), any()) } doReturn Unit
|
||||
}
|
||||
val activityPubFollowService =
|
||||
APReceiveFollowServiceImpl(
|
||||
jobQueueParentService,
|
||||
objectMapper
|
||||
)
|
||||
activityPubFollowService.receiveFollow(
|
||||
Follow(
|
||||
emptyList(),
|
||||
"Follow",
|
||||
"https://example.com",
|
||||
"https://follower.example.com"
|
||||
)
|
||||
)
|
||||
verify(jobQueueParentService, times(1)).schedule(eq(ReceiveFollowJob), any())
|
||||
argumentCaptor<ScheduleContext<ReceiveFollowJob>.(ReceiveFollowJob) -> Unit> {
|
||||
verify(jobQueueParentService, times(1)).schedule(eq(ReceiveFollowJob), capture())
|
||||
val scheduleContext = ScheduleContext<ReceiveFollowJob>(Json)
|
||||
firstValue.invoke(scheduleContext, ReceiveFollowJob)
|
||||
val actor = scheduleContext.props.props[ReceiveFollowJob.actor.name]
|
||||
val targetActor = scheduleContext.props.props[ReceiveFollowJob.targetActor.name]
|
||||
val follow = scheduleContext.props.props[ReceiveFollowJob.follow.name] as String
|
||||
assertEquals("https://follower.example.com", actor)
|
||||
assertEquals("https://example.com", targetActor)
|
||||
//language=JSON
|
||||
assertEquals(
|
||||
Json.parseToJsonElement(
|
||||
"""{
|
||||
"type": "Follow",
|
||||
"name": "Follow",
|
||||
"actor": "https://follower.example.com",
|
||||
"object": "https://example.com"
|
||||
|
||||
}"""
|
||||
),
|
||||
Json.parseToJsonElement(follow)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `receiveFollowJob フォロー受付処理のJob`() = runTest {
|
||||
val person = Person(
|
||||
type = emptyList(),
|
||||
name = "follower",
|
||||
id = "https://follower.example.com",
|
||||
preferredUsername = "followerUser",
|
||||
summary = "This user is follower user.",
|
||||
inbox = "https://follower.example.com/inbox",
|
||||
outbox = "https://follower.example.com/outbox",
|
||||
url = "https://follower.example.com",
|
||||
icon = Image(
|
||||
type = emptyList(),
|
||||
name = "https://follower.example.com/image",
|
||||
mediaType = "image/png",
|
||||
url = "https://follower.example.com/image"
|
||||
),
|
||||
publicKey = Key(
|
||||
type = emptyList(),
|
||||
name = "Public Key",
|
||||
id = "https://follower.example.com#main-key",
|
||||
owner = "https://follower.example.com",
|
||||
publicKeyPem = "BEGIN PUBLIC KEY...END PUBLIC KEY",
|
||||
),
|
||||
followers = "",
|
||||
following = ""
|
||||
|
||||
)
|
||||
val apUserService = mock<APUserService> {
|
||||
onBlocking { fetchPerson(anyString(), any()) } doReturn person
|
||||
}
|
||||
val userQueryService = mock<UserQueryService> {
|
||||
onBlocking { findByUrl(eq("https://example.com")) } doReturn
|
||||
userBuilder.of(
|
||||
id = 1L,
|
||||
name = "test",
|
||||
domain = "example.com",
|
||||
screenName = "testUser",
|
||||
description = "This user is test user.",
|
||||
inbox = "https://example.com/inbox",
|
||||
outbox = "https://example.com/outbox",
|
||||
url = "https://example.com",
|
||||
publicKey = "",
|
||||
password = "a",
|
||||
privateKey = "a",
|
||||
createdAt = Instant.now(),
|
||||
keyId = "a"
|
||||
)
|
||||
onBlocking { findByUrl(eq("https://follower.example.com")) } doReturn
|
||||
userBuilder.of(
|
||||
id = 2L,
|
||||
name = "follower",
|
||||
domain = "follower.example.com",
|
||||
screenName = "followerUser",
|
||||
description = "This user is test follower user.",
|
||||
inbox = "https://follower.example.com/inbox",
|
||||
outbox = "https://follower.example.com/outbox",
|
||||
url = "https://follower.example.com",
|
||||
publicKey = "",
|
||||
createdAt = Instant.now(),
|
||||
keyId = "a"
|
||||
)
|
||||
}
|
||||
|
||||
val userService = mock<UserService> {
|
||||
onBlocking { followRequest(any(), any()) } doReturn false
|
||||
}
|
||||
val activityPubFollowService =
|
||||
APReceiveFollowJobServiceImpl(
|
||||
apUserService,
|
||||
userQueryService,
|
||||
mock(),
|
||||
userService,
|
||||
objectMapper,
|
||||
TestTransaction
|
||||
)
|
||||
activityPubFollowService.receiveFollowJob(
|
||||
JobProps(
|
||||
data = mapOf<String, Any>(
|
||||
ReceiveFollowJob.actor.name to "https://follower.example.com",
|
||||
ReceiveFollowJob.targetActor.name to "https://example.com",
|
||||
//language=JSON
|
||||
ReceiveFollowJob.follow.name to """{
|
||||
"type": "Follow",
|
||||
"name": "Follow",
|
||||
"object": "https://example.com",
|
||||
"actor": "https://follower.example.com",
|
||||
"@context": null
|
||||
}"""
|
||||
),
|
||||
json = Json
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
package dev.usbharu.hideout.activitypub.service.activity.like
|
||||
|
||||
import dev.usbharu.hideout.activitypub.domain.exception.FailedToGetActivityPubResourceException
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Like
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Note
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Person
|
||||
import dev.usbharu.hideout.activitypub.service.objects.note.APNoteService
|
||||
import dev.usbharu.hideout.activitypub.service.objects.user.APUserService
|
||||
import dev.usbharu.hideout.core.query.PostQueryService
|
||||
import dev.usbharu.hideout.core.service.reaction.ReactionService
|
||||
import io.ktor.http.*
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.kotlin.*
|
||||
import utils.PostBuilder
|
||||
import utils.TestTransaction
|
||||
import utils.UserBuilder
|
||||
|
||||
|
||||
class APLikeServiceImplTest {
|
||||
@Test
|
||||
fun `receiveLike 正常なLikeを処理できる`() = runTest {
|
||||
val actor = "https://example.com/actor"
|
||||
val note = "https://example.com/note"
|
||||
val like = Like(
|
||||
name = "Like", actor = actor, id = "htps://example.com", `object` = note, content = "aaa"
|
||||
)
|
||||
|
||||
val user = UserBuilder.localUserOf()
|
||||
val apUserService = mock<APUserService> {
|
||||
onBlocking { fetchPersonWithEntity(eq(actor), anyOrNull()) } doReturn (Person(
|
||||
name = "TestUser",
|
||||
id = "https://example.com",
|
||||
preferredUsername = "Test user",
|
||||
summary = "test user",
|
||||
inbox = "https://example.com/inbox",
|
||||
outbox = "https://example.com/outbox",
|
||||
url = "https://example.com/",
|
||||
icon = null,
|
||||
publicKey = null,
|
||||
followers = null,
|
||||
following = null
|
||||
) to user)
|
||||
}
|
||||
val apNoteService = mock<APNoteService> {
|
||||
on { fetchNoteAsync(eq(note), anyOrNull()) } doReturn async {
|
||||
Note(
|
||||
name = "Note",
|
||||
id = "https://example.com/note",
|
||||
attributedTo = "https://example.com/actor",
|
||||
content = "Hello World",
|
||||
published = "Date: Wed, 21 Oct 2015 07:28:00 GMT",
|
||||
)
|
||||
}
|
||||
}
|
||||
val post = PostBuilder.of()
|
||||
val postQueryService = mock<PostQueryService> {
|
||||
onBlocking { findByUrl(eq(note)) } doReturn post
|
||||
}
|
||||
val reactionService = mock<ReactionService>()
|
||||
val apLikeServiceImpl = APLikeServiceImpl(
|
||||
reactionService, apUserService, apNoteService, postQueryService, TestTransaction
|
||||
)
|
||||
|
||||
val actual = apLikeServiceImpl.receiveLike(like)
|
||||
|
||||
verify(reactionService, times(1)).receiveReaction(eq("aaa"), eq("example.com"), eq(user.id), eq(post.id))
|
||||
assertEquals(ActivityPubStringResponse(HttpStatusCode.OK, ""), actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `recieveLike Likeのobjectのurlが取得できないとき何もしない`() = runTest {
|
||||
val actor = "https://example.com/actor"
|
||||
val note = "https://example.com/note"
|
||||
val like = Like(
|
||||
name = "Like", actor = actor, id = "htps://example.com", `object` = note, content = "aaa"
|
||||
)
|
||||
|
||||
val user = UserBuilder.localUserOf()
|
||||
val apUserService = mock<APUserService> {
|
||||
onBlocking { fetchPersonWithEntity(eq(actor), anyOrNull()) } doReturn (Person(
|
||||
name = "TestUser",
|
||||
id = "https://example.com",
|
||||
preferredUsername = "Test user",
|
||||
summary = "test user",
|
||||
inbox = "https://example.com/inbox",
|
||||
outbox = "https://example.com/outbox",
|
||||
url = "https://example.com/",
|
||||
icon = null,
|
||||
publicKey = null,
|
||||
followers = null,
|
||||
following = null
|
||||
) to user)
|
||||
}
|
||||
val apNoteService = mock<APNoteService> {
|
||||
on { fetchNoteAsync(eq(note), anyOrNull()) } doThrow FailedToGetActivityPubResourceException()
|
||||
}
|
||||
|
||||
val reactionService = mock<ReactionService>()
|
||||
val apLikeServiceImpl = APLikeServiceImpl(
|
||||
reactionService, apUserService, apNoteService, mock(), TestTransaction
|
||||
)
|
||||
|
||||
val actual = apLikeServiceImpl.receiveLike(like)
|
||||
|
||||
verify(reactionService, times(0)).receiveReaction(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull())
|
||||
assertEquals(ActivityPubStringResponse(HttpStatusCode.OK, ""), actual)
|
||||
}
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package dev.usbharu.hideout.activitypub.service.activity.like
|
||||
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Like
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Undo
|
||||
import dev.usbharu.hideout.activitypub.service.common.APRequestService
|
||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||
import dev.usbharu.hideout.core.external.job.DeliverReactionJob
|
||||
import dev.usbharu.hideout.core.external.job.DeliverRemoveReactionJob
|
||||
import dev.usbharu.hideout.core.query.UserQueryService
|
||||
import kjob.core.job.JobProps
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.Mockito.mockStatic
|
||||
import org.mockito.kotlin.*
|
||||
import utils.JsonObjectMapper.objectMapper
|
||||
import utils.UserBuilder
|
||||
import java.net.URL
|
||||
import java.time.Instant
|
||||
|
||||
class ApReactionJobServiceImplTest {
|
||||
@Test
|
||||
fun `reactionJob Likeが配送される`() = runTest {
|
||||
|
||||
val localUser = UserBuilder.localUserOf()
|
||||
val remoteUser = UserBuilder.remoteUserOf()
|
||||
|
||||
val userQueryService = mock<UserQueryService> {
|
||||
onBlocking { findByUrl(localUser.url) } doReturn localUser
|
||||
}
|
||||
val apRequestService = mock<APRequestService>()
|
||||
val apReactionJobServiceImpl = ApReactionJobServiceImpl(
|
||||
userQueryService = userQueryService,
|
||||
apRequestService = apRequestService,
|
||||
applicationConfig = ApplicationConfig(URL("https://example.com")),
|
||||
objectMapper = objectMapper
|
||||
)
|
||||
|
||||
|
||||
val postUrl = "${remoteUser.url}/posts/1234"
|
||||
|
||||
apReactionJobServiceImpl.reactionJob(
|
||||
JobProps(
|
||||
data = mapOf(
|
||||
DeliverReactionJob.inbox.name to remoteUser.inbox,
|
||||
DeliverReactionJob.actor.name to localUser.url,
|
||||
DeliverReactionJob.postUrl.name to postUrl,
|
||||
DeliverReactionJob.id.name to "1234",
|
||||
DeliverReactionJob.reaction.name to "❤",
|
||||
|
||||
),
|
||||
json = Json
|
||||
)
|
||||
)
|
||||
|
||||
val body = Like(
|
||||
name = "Like",
|
||||
actor = localUser.url,
|
||||
`object` = postUrl,
|
||||
id = "https://example.com/like/note/1234",
|
||||
content = "❤"
|
||||
)
|
||||
|
||||
verify(apRequestService, times(1)).apPost(eq(remoteUser.inbox), eq(body), eq(localUser))
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `removeReactionJob LikeのUndoが配送される`() = runTest {
|
||||
|
||||
val localUser = UserBuilder.localUserOf()
|
||||
val remoteUser = UserBuilder.remoteUserOf()
|
||||
|
||||
val userQueryService = mock<UserQueryService> {
|
||||
onBlocking { findByUrl(localUser.url) } doReturn localUser
|
||||
}
|
||||
val apRequestService = mock<APRequestService>()
|
||||
val apReactionJobServiceImpl = ApReactionJobServiceImpl(
|
||||
userQueryService = userQueryService,
|
||||
apRequestService = apRequestService,
|
||||
applicationConfig = ApplicationConfig(URL("https://example.com")),
|
||||
objectMapper = objectMapper
|
||||
)
|
||||
|
||||
|
||||
val postUrl = "${remoteUser.url}/posts/1234"
|
||||
val like = Like(
|
||||
name = "Like",
|
||||
actor = remoteUser.url,
|
||||
`object` = postUrl,
|
||||
id = "https://example.com/like/note/1234",
|
||||
content = "❤"
|
||||
)
|
||||
|
||||
val now = Instant.now()
|
||||
|
||||
val body = mockStatic(Instant::class.java).use {
|
||||
|
||||
it.`when`<Instant>(Instant::now).thenReturn(now)
|
||||
|
||||
apReactionJobServiceImpl.removeReactionJob(
|
||||
JobProps(
|
||||
data = mapOf(
|
||||
DeliverRemoveReactionJob.inbox.name to remoteUser.inbox,
|
||||
DeliverRemoveReactionJob.actor.name to localUser.url,
|
||||
DeliverRemoveReactionJob.id.name to "1234",
|
||||
DeliverRemoveReactionJob.like.name to objectMapper.writeValueAsString(like),
|
||||
|
||||
),
|
||||
json = Json
|
||||
)
|
||||
)
|
||||
Undo(
|
||||
name = "Undo Reaction",
|
||||
actor = localUser.url,
|
||||
`object` = like,
|
||||
id = "https://example.com/undo/note/1234",
|
||||
published = now
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
verify(apRequestService, times(1)).apPost(eq(remoteUser.inbox), eq(body), eq(localUser))
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package dev.usbharu.hideout.activitypub.service.activity.undo
|
||||
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Undo
|
||||
import dev.usbharu.hideout.core.query.UserQueryService
|
||||
import io.ktor.http.*
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.kotlin.doReturn
|
||||
import org.mockito.kotlin.eq
|
||||
import org.mockito.kotlin.mock
|
||||
import utils.TestTransaction
|
||||
import utils.UserBuilder
|
||||
import java.time.Instant
|
||||
|
||||
class APUndoServiceImplTest {
|
||||
@Test
|
||||
fun `receiveUndo FollowのUndoを処理できる`() = runTest {
|
||||
|
||||
val userQueryService = mock<UserQueryService> {
|
||||
onBlocking { findByUrl(eq("https://follower.example.com/actor")) } doReturn UserBuilder.remoteUserOf()
|
||||
onBlocking { findByUrl(eq("https://example.com/actor")) } doReturn UserBuilder.localUserOf()
|
||||
}
|
||||
val apUndoServiceImpl = APUndoServiceImpl(
|
||||
userService = mock(),
|
||||
apUserService = mock(),
|
||||
userQueryService = userQueryService,
|
||||
transaction = TestTransaction
|
||||
)
|
||||
|
||||
val undo = Undo(
|
||||
name = "Undo",
|
||||
actor = "https://follower.example.com/actor",
|
||||
id = "https://follower.example.com/undo/follow",
|
||||
`object` = Follow(
|
||||
name = "Follow",
|
||||
`object` = "https://example.com/actor",
|
||||
actor = "https://follower.example.com/actor"
|
||||
),
|
||||
published = Instant.now()
|
||||
)
|
||||
val activityPubResponse = apUndoServiceImpl.receiveUndo(undo)
|
||||
assertEquals(ActivityPubStringResponse(HttpStatusCode.OK, "Accept"), activityPubResponse)
|
||||
}
|
||||
|
||||
}
|
|
@ -11,13 +11,7 @@ class APServiceImplTest {
|
|||
@Test
|
||||
fun `parseActivity 正常なActivityをパースできる`() {
|
||||
val apServiceImpl = APServiceImpl(
|
||||
apReceiveFollowService = mock(),
|
||||
apUndoService = mock(),
|
||||
apAcceptService = mock(),
|
||||
apCreateService = mock(),
|
||||
apLikeService = mock(),
|
||||
apReceiveDeleteService = mock(),
|
||||
objectMapper = objectMapper
|
||||
objectMapper = objectMapper, jobQueueParentService = mock()
|
||||
)
|
||||
|
||||
//language=JSON
|
||||
|
@ -29,13 +23,7 @@ class APServiceImplTest {
|
|||
@Test
|
||||
fun `parseActivity Typeが配列のActivityをパースできる`() {
|
||||
val apServiceImpl = APServiceImpl(
|
||||
apReceiveFollowService = mock(),
|
||||
apUndoService = mock(),
|
||||
apAcceptService = mock(),
|
||||
apCreateService = mock(),
|
||||
apLikeService = mock(),
|
||||
apReceiveDeleteService = mock(),
|
||||
objectMapper = objectMapper
|
||||
objectMapper = objectMapper, jobQueueParentService = mock()
|
||||
)
|
||||
|
||||
//language=JSON
|
||||
|
@ -47,13 +35,7 @@ class APServiceImplTest {
|
|||
@Test
|
||||
fun `parseActivity Typeが配列で関係ない物が入っていてもパースできる`() {
|
||||
val apServiceImpl = APServiceImpl(
|
||||
apReceiveFollowService = mock(),
|
||||
apUndoService = mock(),
|
||||
apAcceptService = mock(),
|
||||
apCreateService = mock(),
|
||||
apLikeService = mock(),
|
||||
apReceiveDeleteService = mock(),
|
||||
objectMapper = objectMapper
|
||||
objectMapper = objectMapper, jobQueueParentService = mock()
|
||||
)
|
||||
|
||||
//language=JSON
|
||||
|
@ -65,13 +47,8 @@ class APServiceImplTest {
|
|||
@Test
|
||||
fun `parseActivity jsonとして解釈できない場合JsonParseExceptionがthrowされる`() {
|
||||
val apServiceImpl = APServiceImpl(
|
||||
apReceiveFollowService = mock(),
|
||||
apUndoService = mock(),
|
||||
apAcceptService = mock(),
|
||||
apCreateService = mock(),
|
||||
apLikeService = mock(),
|
||||
apReceiveDeleteService = mock(),
|
||||
objectMapper = objectMapper
|
||||
|
||||
objectMapper = objectMapper, jobQueueParentService = mock()
|
||||
)
|
||||
|
||||
//language=JSON
|
||||
|
@ -83,13 +60,8 @@ class APServiceImplTest {
|
|||
@Test
|
||||
fun `parseActivity 空の場合JsonParseExceptionがthrowされる`() {
|
||||
val apServiceImpl = APServiceImpl(
|
||||
apReceiveFollowService = mock(),
|
||||
apUndoService = mock(),
|
||||
apAcceptService = mock(),
|
||||
apCreateService = mock(),
|
||||
apLikeService = mock(),
|
||||
apReceiveDeleteService = mock(),
|
||||
objectMapper = objectMapper
|
||||
|
||||
objectMapper = objectMapper, jobQueueParentService = mock()
|
||||
)
|
||||
|
||||
//language=JSON
|
||||
|
@ -101,13 +73,8 @@ class APServiceImplTest {
|
|||
@Test
|
||||
fun `parseActivity jsonにtypeプロパティがない場合JsonParseExceptionがthrowされる`() {
|
||||
val apServiceImpl = APServiceImpl(
|
||||
apReceiveFollowService = mock(),
|
||||
apUndoService = mock(),
|
||||
apAcceptService = mock(),
|
||||
apCreateService = mock(),
|
||||
apLikeService = mock(),
|
||||
apReceiveDeleteService = mock(),
|
||||
objectMapper = objectMapper
|
||||
|
||||
objectMapper = objectMapper, jobQueueParentService = mock()
|
||||
)
|
||||
|
||||
//language=JSON
|
||||
|
@ -119,13 +86,8 @@ class APServiceImplTest {
|
|||
@Test
|
||||
fun `parseActivity typeが配列でないときtypeが未定義の場合IllegalArgumentExceptionがthrowされる`() {
|
||||
val apServiceImpl = APServiceImpl(
|
||||
apReceiveFollowService = mock(),
|
||||
apUndoService = mock(),
|
||||
apAcceptService = mock(),
|
||||
apCreateService = mock(),
|
||||
apLikeService = mock(),
|
||||
apReceiveDeleteService = mock(),
|
||||
objectMapper = objectMapper
|
||||
|
||||
objectMapper = objectMapper, jobQueueParentService = mock()
|
||||
)
|
||||
|
||||
//language=JSON
|
||||
|
@ -137,13 +99,8 @@ class APServiceImplTest {
|
|||
@Test
|
||||
fun `parseActivity typeが配列のとき定義済みのtypeを見つけられなかった場合IllegalArgumentExceptionがthrowされる`() {
|
||||
val apServiceImpl = APServiceImpl(
|
||||
apReceiveFollowService = mock(),
|
||||
apUndoService = mock(),
|
||||
apAcceptService = mock(),
|
||||
apCreateService = mock(),
|
||||
apLikeService = mock(),
|
||||
apReceiveDeleteService = mock(),
|
||||
objectMapper = objectMapper
|
||||
|
||||
objectMapper = objectMapper, jobQueueParentService = mock()
|
||||
)
|
||||
|
||||
//language=JSON
|
||||
|
@ -155,13 +112,8 @@ class APServiceImplTest {
|
|||
@Test
|
||||
fun `parseActivity typeが空の場合IllegalArgumentExceptionがthrowされる`() {
|
||||
val apServiceImpl = APServiceImpl(
|
||||
apReceiveFollowService = mock(),
|
||||
apUndoService = mock(),
|
||||
apAcceptService = mock(),
|
||||
apCreateService = mock(),
|
||||
apLikeService = mock(),
|
||||
apReceiveDeleteService = mock(),
|
||||
objectMapper = objectMapper
|
||||
|
||||
objectMapper = objectMapper, jobQueueParentService = mock()
|
||||
)
|
||||
|
||||
//language=JSON
|
||||
|
@ -173,13 +125,8 @@ class APServiceImplTest {
|
|||
@Test
|
||||
fun `parseActivity typeに指定されている文字の判定がcase-insensitiveで行われる`() {
|
||||
val apServiceImpl = APServiceImpl(
|
||||
apReceiveFollowService = mock(),
|
||||
apUndoService = mock(),
|
||||
apAcceptService = mock(),
|
||||
apCreateService = mock(),
|
||||
apLikeService = mock(),
|
||||
apReceiveDeleteService = mock(),
|
||||
objectMapper = objectMapper
|
||||
|
||||
objectMapper = objectMapper, jobQueueParentService = mock()
|
||||
)
|
||||
|
||||
//language=JSON
|
||||
|
@ -191,13 +138,8 @@ class APServiceImplTest {
|
|||
@Test
|
||||
fun `parseActivity typeが配列のとき指定されている文字の判定がcase-insensitiveで行われる`() {
|
||||
val apServiceImpl = APServiceImpl(
|
||||
apReceiveFollowService = mock(),
|
||||
apUndoService = mock(),
|
||||
apAcceptService = mock(),
|
||||
apCreateService = mock(),
|
||||
apLikeService = mock(),
|
||||
apReceiveDeleteService = mock(),
|
||||
objectMapper = objectMapper
|
||||
|
||||
objectMapper = objectMapper, jobQueueParentService = mock()
|
||||
)
|
||||
|
||||
//language=JSON
|
||||
|
@ -209,13 +151,8 @@ class APServiceImplTest {
|
|||
@Test
|
||||
fun `parseActivity activityがarrayのときJsonParseExceptionがthrowされる`() {
|
||||
val apServiceImpl = APServiceImpl(
|
||||
apReceiveFollowService = mock(),
|
||||
apUndoService = mock(),
|
||||
apAcceptService = mock(),
|
||||
apCreateService = mock(),
|
||||
apLikeService = mock(),
|
||||
apReceiveDeleteService = mock(),
|
||||
objectMapper = objectMapper
|
||||
|
||||
objectMapper = objectMapper, jobQueueParentService = mock()
|
||||
)
|
||||
|
||||
//language=JSON
|
||||
|
@ -227,13 +164,8 @@ class APServiceImplTest {
|
|||
@Test
|
||||
fun `parseActivity activityがvalueのときJsonParseExceptionがthrowされる`() {
|
||||
val apServiceImpl = APServiceImpl(
|
||||
apReceiveFollowService = mock(),
|
||||
apUndoService = mock(),
|
||||
apAcceptService = mock(),
|
||||
apCreateService = mock(),
|
||||
apLikeService = mock(),
|
||||
apReceiveDeleteService = mock(),
|
||||
objectMapper = objectMapper
|
||||
|
||||
objectMapper = objectMapper, jobQueueParentService = mock()
|
||||
)
|
||||
|
||||
//language=JSON
|
||||
|
|
Loading…
Reference in New Issue