diff --git a/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt index bc9ab9c6..628a8eff 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt @@ -3,6 +3,8 @@ package dev.usbharu.hideout.service.ap +import dev.usbharu.hideout.config.ApplicationConfig +import dev.usbharu.hideout.config.CharacterLimit import dev.usbharu.hideout.domain.model.hideout.entity.Post import dev.usbharu.hideout.domain.model.hideout.entity.User import dev.usbharu.hideout.domain.model.hideout.entity.Visibility @@ -21,21 +23,28 @@ import org.junit.jupiter.api.Test import org.mockito.Mockito.anyLong import org.mockito.Mockito.eq import org.mockito.kotlin.* -import org.springframework.boot.context.config.ConfigData import utils.JsonObjectMapper.objectMapper import utils.TestApplicationConfig.testApplicationConfig +import java.net.URL import java.time.Instant import kotlin.test.assertEquals class APNoteServiceImplTest { + + val userBuilder = User.UserBuilder(CharacterLimit(), ApplicationConfig(URL("https://example.com"))) + val postBuilder = Post.PostBuilder(CharacterLimit()) + @Test fun `createPost 新しい投稿`() { val mediaQueryService = mock { onBlocking { findByPostId(anyLong()) } doReturn emptyList() } + + + runTest { val followers = listOf( - User.of( + userBuilder.of( 2L, "follower", "follower.example.com", @@ -49,7 +58,7 @@ class APNoteServiceImplTest { createdAt = Instant.now(), keyId = "a" ), - User.of( + userBuilder.of( 3L, "follower2", "follower2.example.com", @@ -65,7 +74,7 @@ class APNoteServiceImplTest { ) ) val userQueryService = mock { - onBlocking { findById(eq(1L)) } doReturn User.of( + onBlocking { findById(eq(1L)) } doReturn userBuilder.of( 1L, "test", "example.com", @@ -99,9 +108,10 @@ class APNoteServiceImplTest { postService = mock(), apResourceResolveService = mock(), apRequestService = mock(), - transaction = mock() + transaction = mock(), + postBuilder = postBuilder ) - val postEntity = Post.of( + val postEntity = postBuilder.of( 1L, 1L, null, @@ -121,7 +131,7 @@ class APNoteServiceImplTest { val mediaQueryService = mock { onBlocking { findByPostId(anyLong()) } doReturn emptyList() } - Config.configData = ConfigData() + val httpClient = HttpClient( MockEngine { httpRequestData -> assertEquals("https://follower.example.com/inbox", httpRequestData.url.toString()) @@ -141,7 +151,8 @@ class APNoteServiceImplTest { postService = mock(), apResourceResolveService = mock(), apRequestService = mock(), - transaction = mock() + transaction = mock(), + postBuilder = postBuilder ) activityPubNoteService.createNoteJob( JobProps( diff --git a/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt index 89ac6dc2..38c266e1 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt @@ -3,10 +3,13 @@ package dev.usbharu.hideout.service.ap +import dev.usbharu.hideout.config.ApplicationConfig +import dev.usbharu.hideout.config.CharacterLimit import dev.usbharu.hideout.domain.model.ap.Follow import dev.usbharu.hideout.domain.model.ap.Image import dev.usbharu.hideout.domain.model.ap.Key import dev.usbharu.hideout.domain.model.ap.Person +import dev.usbharu.hideout.domain.model.hideout.entity.Post import dev.usbharu.hideout.domain.model.hideout.entity.User import dev.usbharu.hideout.domain.model.job.ReceiveFollowJob import dev.usbharu.hideout.query.UserQueryService @@ -21,12 +24,16 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.mockito.ArgumentMatchers.anyString import org.mockito.kotlin.* -import org.springframework.boot.context.config.ConfigData 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 { @@ -78,7 +85,6 @@ class APReceiveFollowServiceImplTest { @Test fun `receiveFollowJob フォロー受付処理のJob`() = runTest { - Config.configData = ConfigData() val person = Person( type = emptyList(), name = "follower", @@ -110,7 +116,7 @@ class APReceiveFollowServiceImplTest { } val userQueryService = mock { onBlocking { findByUrl(eq("https://example.com")) } doReturn - User.of( + userBuilder.of( id = 1L, name = "test", domain = "example.com", @@ -120,11 +126,13 @@ class APReceiveFollowServiceImplTest { 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 - User.of( + userBuilder.of( id = 2L, name = "follower", domain = "follower.example.com", diff --git a/src/test/kotlin/dev/usbharu/hideout/service/ap/resource/APResourceResolveServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/ap/resource/APResourceResolveServiceImplTest.kt index 344a07d8..87f5a553 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/ap/resource/APResourceResolveServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/ap/resource/APResourceResolveServiceImplTest.kt @@ -1,6 +1,9 @@ package dev.usbharu.hideout.service.ap.resource +import dev.usbharu.hideout.config.ApplicationConfig +import dev.usbharu.hideout.config.CharacterLimit import dev.usbharu.hideout.domain.model.ap.Object +import dev.usbharu.hideout.domain.model.hideout.entity.Post import dev.usbharu.hideout.domain.model.hideout.entity.User import dev.usbharu.hideout.repository.UserRepository import io.ktor.client.* @@ -16,6 +19,7 @@ import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.whenever +import java.net.URL import java.time.Instant import kotlin.test.assertEquals @@ -23,6 +27,9 @@ import kotlin.test.assertEquals @Disabled class APResourceResolveServiceImplTest { + val userBuilder = User.UserBuilder(CharacterLimit(), ApplicationConfig(URL("https://example.com"))) + val postBuilder = Post.PostBuilder(CharacterLimit()) + @Test fun `単純な一回のリクエスト`() = runTest { @@ -36,7 +43,7 @@ class APResourceResolveServiceImplTest { val userRepository = mock() whenever(userRepository.findById(any())).doReturn( - User.of( + userBuilder.of( 2L, "follower", "follower.example.com", @@ -72,7 +79,7 @@ class APResourceResolveServiceImplTest { val userRepository = mock() whenever(userRepository.findById(any())).doReturn( - User.of( + userBuilder.of( 2L, "follower", "follower.example.com", @@ -111,7 +118,7 @@ class APResourceResolveServiceImplTest { val userRepository = mock() whenever(userRepository.findById(any())).doReturn( - User.of( + userBuilder.of( 2L, "follower", "follower.example.com", @@ -161,7 +168,7 @@ class APResourceResolveServiceImplTest { val userRepository = mock() whenever(userRepository.findById(any())).doReturn( - User.of( + userBuilder.of( 2L, "follower", "follower.example.com", diff --git a/src/test/kotlin/dev/usbharu/hideout/service/user/UserServiceTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/user/UserServiceTest.kt index 357dcbfb..663d7f40 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/user/UserServiceTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/user/UserServiceTest.kt @@ -2,24 +2,30 @@ package dev.usbharu.hideout.service.user +import dev.usbharu.hideout.config.ApplicationConfig +import dev.usbharu.hideout.config.CharacterLimit import dev.usbharu.hideout.domain.model.hideout.dto.RemoteUserCreateDto import dev.usbharu.hideout.domain.model.hideout.dto.UserCreateDto +import dev.usbharu.hideout.domain.model.hideout.entity.Post +import dev.usbharu.hideout.domain.model.hideout.entity.User import dev.usbharu.hideout.repository.UserRepository import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Test import org.mockito.ArgumentMatchers.anyString import org.mockito.kotlin.* -import org.springframework.boot.context.config.ConfigData import utils.TestApplicationConfig.testApplicationConfig +import java.net.URL import java.security.KeyPairGenerator import kotlin.test.assertEquals import kotlin.test.assertNull class UserServiceTest { + val userBuilder = User.UserBuilder(CharacterLimit(), ApplicationConfig(URL("https://example.com"))) + val postBuilder = Post.PostBuilder(CharacterLimit()) @Test fun `createLocalUser ローカルユーザーを作成できる`() = runTest { - Config.configData = ConfigData(domain = "example.com", url = "https://example.com") + val userRepository = mock { onBlocking { nextId() } doReturn 110001L } @@ -29,7 +35,15 @@ class UserServiceTest { onBlocking { generateKeyPair() } doReturn generateKeyPair } val userService = - UserServiceImpl(userRepository, userAuthService, mock(), mock(), mock(), testApplicationConfig) + UserServiceImpl( + userRepository, + userAuthService, + mock(), + mock(), + mock(), + userBuilder, + testApplicationConfig, + ) userService.createLocalUser(UserCreateDto("test", "testUser", "XXXXXXXXXXXXX", "test")) verify(userRepository, times(1)).save(any()) argumentCaptor { @@ -50,20 +64,20 @@ class UserServiceTest { @Test fun `createRemoteUser リモートユーザーを作成できる`() = runTest { - Config.configData = ConfigData(domain = "remote.example.com", url = "https://remote.example.com") val userRepository = mock { onBlocking { nextId() } doReturn 113345L } - val userService = UserServiceImpl(userRepository, mock(), mock(), mock(), mock(), testApplicationConfig) + val userService = + UserServiceImpl(userRepository, mock(), mock(), mock(), mock(), userBuilder, testApplicationConfig) val user = RemoteUserCreateDto( name = "test", - domain = "example.com", + domain = "remote.example.com", screenName = "testUser", description = "test user", - inbox = "https://example.com/inbox", - outbox = "https://example.com/outbox", - url = "https://example.com", + inbox = "https://remote.example.com/inbox", + outbox = "https://remote.example.com/outbox", + url = "https://remote.example.com", publicKey = "-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----", keyId = "a", following = "", @@ -78,10 +92,10 @@ class UserServiceTest { assertEquals("test user", firstValue.description) assertNull(firstValue.password) assertEquals(113345L, firstValue.id) - assertEquals("https://example.com", firstValue.url) - assertEquals("example.com", firstValue.domain) - assertEquals("https://example.com/inbox", firstValue.inbox) - assertEquals("https://example.com/outbox", firstValue.outbox) + assertEquals("https://remote.example.com", firstValue.url) + assertEquals("remote.example.com", firstValue.domain) + assertEquals("https://remote.example.com/inbox", firstValue.inbox) + assertEquals("https://remote.example.com/outbox", firstValue.outbox) assertEquals("-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----", firstValue.publicKey) assertNull(firstValue.privateKey) }