mirror of
https://github.com/usbharu/Hideout.git
synced 2026-09-27 07:21:12 +00:00
feat: Postのインスタンス化時にチェックするように
This commit is contained in:
+9
-14
@@ -45,6 +45,7 @@ import io.ktor.http.*
|
||||
import io.ktor.http.content.*
|
||||
import io.ktor.util.*
|
||||
import io.ktor.util.date.*
|
||||
import jakarta.validation.Validation
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.Job
|
||||
@@ -60,7 +61,10 @@ import java.time.Instant
|
||||
|
||||
class APNoteServiceImplTest {
|
||||
|
||||
val postBuilder = Post.PostBuilder(CharacterLimit(), DefaultPostContentFormatter(HtmlSanitizeConfig().policy()))
|
||||
val postBuilder = Post.PostBuilder(
|
||||
CharacterLimit(), DefaultPostContentFormatter(HtmlSanitizeConfig().policy()),
|
||||
Validation.buildDefaultValidatorFactory().validator
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `fetchNote(String,String) ノートが既に存在する場合はDBから取得したものを返す`() = runTest {
|
||||
@@ -89,10 +93,7 @@ class APNoteServiceImplTest {
|
||||
apUserService = mock(),
|
||||
postService = mock(),
|
||||
apResourceResolveService = mock(),
|
||||
postBuilder = Post.PostBuilder(
|
||||
CharacterLimit(),
|
||||
DefaultPostContentFormatter(HtmlSanitizeConfig().policy())
|
||||
),
|
||||
postBuilder = postBuilder,
|
||||
noteQueryService = noteQueryService,
|
||||
mock(),
|
||||
mock(),
|
||||
@@ -163,10 +164,7 @@ class APNoteServiceImplTest {
|
||||
apUserService = apUserService,
|
||||
postService = mock(),
|
||||
apResourceResolveService = apResourceResolveService,
|
||||
postBuilder = Post.PostBuilder(
|
||||
CharacterLimit(),
|
||||
DefaultPostContentFormatter(HtmlSanitizeConfig().policy())
|
||||
),
|
||||
postBuilder = postBuilder,
|
||||
noteQueryService = noteQueryService,
|
||||
mock(),
|
||||
mock { },
|
||||
@@ -216,14 +214,11 @@ class APNoteServiceImplTest {
|
||||
apUserService = mock(),
|
||||
postService = mock(),
|
||||
apResourceResolveService = apResourceResolveService,
|
||||
postBuilder = Post.PostBuilder(
|
||||
CharacterLimit(),
|
||||
DefaultPostContentFormatter(HtmlSanitizeConfig().policy())
|
||||
),
|
||||
postBuilder = postBuilder,
|
||||
noteQueryService = noteQueryService,
|
||||
mock(),
|
||||
mock(),
|
||||
mock { }
|
||||
mock { }
|
||||
)
|
||||
|
||||
assertThrows<FailedToGetActivityPubResourceException> { apNoteServiceImpl.fetchNote(url) }
|
||||
|
||||
@@ -26,6 +26,7 @@ import dev.usbharu.hideout.core.domain.model.post.Post
|
||||
import dev.usbharu.hideout.core.domain.model.post.PostRepository
|
||||
import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository
|
||||
import dev.usbharu.hideout.core.service.timeline.TimelineService
|
||||
import jakarta.validation.Validation
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
@@ -56,7 +57,7 @@ class PostServiceImplTest {
|
||||
private var postBuilder: Post.PostBuilder = Post.PostBuilder(
|
||||
CharacterLimit(), DefaultPostContentFormatter(
|
||||
HtmlSanitizeConfig().policy()
|
||||
)
|
||||
), Validation.buildDefaultValidatorFactory().validator
|
||||
)
|
||||
|
||||
@Mock
|
||||
|
||||
@@ -20,11 +20,8 @@ package dev.usbharu.hideout.core.service.user
|
||||
|
||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||
import dev.usbharu.hideout.application.config.CharacterLimit
|
||||
import dev.usbharu.hideout.application.config.HtmlSanitizeConfig
|
||||
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
||||
import dev.usbharu.hideout.core.domain.model.post.Post
|
||||
import dev.usbharu.hideout.core.service.post.DefaultPostContentFormatter
|
||||
import jakarta.validation.Validation
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.runTest
|
||||
@@ -43,7 +40,6 @@ class ActorServiceTest {
|
||||
ApplicationConfig(URL("https://example.com")),
|
||||
Validation.buildDefaultValidatorFactory().validator
|
||||
)
|
||||
val postBuilder = Post.PostBuilder(CharacterLimit(), DefaultPostContentFormatter(HtmlSanitizeConfig().policy()))
|
||||
@Test
|
||||
fun `createLocalUser ローカルユーザーを作成できる`() = runTest {
|
||||
|
||||
|
||||
@@ -22,13 +22,18 @@ import dev.usbharu.hideout.application.service.id.TwitterSnowflakeIdGenerateServ
|
||||
import dev.usbharu.hideout.core.domain.model.post.Post
|
||||
import dev.usbharu.hideout.core.domain.model.post.Visibility
|
||||
import dev.usbharu.hideout.core.service.post.DefaultPostContentFormatter
|
||||
import jakarta.validation.Validation
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.time.Instant
|
||||
|
||||
object PostBuilder {
|
||||
|
||||
private val postBuilder =
|
||||
Post.PostBuilder(CharacterLimit(), DefaultPostContentFormatter(HtmlSanitizeConfig().policy()))
|
||||
Post.PostBuilder(
|
||||
CharacterLimit(),
|
||||
DefaultPostContentFormatter(HtmlSanitizeConfig().policy()),
|
||||
Validation.buildDefaultValidatorFactory().validator
|
||||
)
|
||||
|
||||
private val idGenerator = TwitterSnowflakeIdGenerateService
|
||||
|
||||
@@ -39,7 +44,7 @@ object PostBuilder {
|
||||
text: String = "Hello World",
|
||||
createdAt: Long = Instant.now().toEpochMilli(),
|
||||
visibility: Visibility = Visibility.PUBLIC,
|
||||
url: String = "https://example.com/users/$userId/posts/$id"
|
||||
url: String = "https://example.com/users/$userId/posts/$id",
|
||||
): Post {
|
||||
return postBuilder.of(
|
||||
id = id,
|
||||
|
||||
Reference in New Issue
Block a user