mirror of https://github.com/usbharu/Hideout.git
test: postのテストを追加
This commit is contained in:
parent
5de217fecc
commit
2c298d2d26
|
@ -19,6 +19,7 @@ package dev.usbharu.hideout.core.domain.model.post
|
|||
import dev.usbharu.hideout.core.domain.event.post.PostDomainEventFactory
|
||||
import dev.usbharu.hideout.core.domain.event.post.PostEvent
|
||||
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
||||
import dev.usbharu.hideout.core.domain.model.emoji.EmojiId
|
||||
import dev.usbharu.hideout.core.domain.model.media.MediaId
|
||||
import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventStorable
|
||||
import java.net.URI
|
||||
|
@ -38,7 +39,7 @@ class Post(
|
|||
val apId: URI,
|
||||
deleted: Boolean,
|
||||
mediaIds: List<MediaId>,
|
||||
visibleActors: List<ActorId> = emptyList(),
|
||||
visibleActors: Set<ActorId> = emptySet(),
|
||||
hide: Boolean = false,
|
||||
moveTo: PostId? = null,
|
||||
) : DomainEventStorable() {
|
||||
|
@ -71,7 +72,7 @@ class Post(
|
|||
require(deleted.not())
|
||||
if (visibility == Visibility.DIRECT) {
|
||||
addDomainEvent(PostDomainEventFactory(this).createEvent(PostEvent.update))
|
||||
field = field.plus(value).distinct()
|
||||
field = field.plus(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,11 +115,21 @@ class Post(
|
|||
field = value
|
||||
}
|
||||
|
||||
val text
|
||||
get() = content.text
|
||||
val text: String
|
||||
get() {
|
||||
if (hide) {
|
||||
return PostContent.empty.text
|
||||
}
|
||||
return content.text
|
||||
}
|
||||
|
||||
val emojiIds
|
||||
get() = content.emojiIds
|
||||
val emojiIds: List<EmojiId>
|
||||
get() {
|
||||
if (hide) {
|
||||
return PostContent.empty.emojiIds
|
||||
}
|
||||
return content.emojiIds
|
||||
}
|
||||
|
||||
var mediaIds = mediaIds
|
||||
get() {
|
||||
|
@ -207,7 +218,7 @@ class Post(
|
|||
apId: URI,
|
||||
deleted: Boolean,
|
||||
mediaIds: List<MediaId>,
|
||||
visibleActors: List<ActorId> = emptyList(),
|
||||
visibleActors: Set<ActorId> = emptySet(),
|
||||
hide: Boolean = false,
|
||||
moveTo: PostId? = null,
|
||||
): Post {
|
||||
|
|
|
@ -57,7 +57,7 @@ class PostQueryMapper(private val postResultRowMapper: ResultRowMapper<Post>) :
|
|||
resultRow
|
||||
.getOrNull(PostsVisibleActors.actorId)
|
||||
?.let { actorId -> ActorId(actorId) }
|
||||
}
|
||||
}.toSet()
|
||||
clearDomainEvents()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class PostResultRowMapper : ResultRowMapper<Post> {
|
|||
apId = URI.create(resultRow[Posts.apId]),
|
||||
deleted = resultRow[Posts.deleted],
|
||||
mediaIds = emptyList(),
|
||||
visibleActors = emptyList(),
|
||||
visibleActors = emptySet(),
|
||||
hide = resultRow[Posts.hide],
|
||||
moveTo = resultRow[Posts.moveTo]?.let { PostId(it) }
|
||||
)
|
||||
|
|
|
@ -139,7 +139,56 @@ class PostTest {
|
|||
val post = TestPostFactory.create(deleted = true)
|
||||
|
||||
assertThrows<IllegalArgumentException> {
|
||||
post.visibleActors = listOf(ActorId(100))
|
||||
post.visibleActors = setOf(ActorId(100))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun visibilityがDIRECTの時visibleActorsを変更できる() {
|
||||
val post = TestPostFactory.create(visibility = Visibility.DIRECT)
|
||||
|
||||
post.visibleActors = setOf(ActorId(100))
|
||||
assertEquals(setOf(ActorId(100)), post.visibleActors)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun visibleActorsから削除されることはない() {
|
||||
val post = TestPostFactory.create(visibility = Visibility.DIRECT, visibleActors = listOf(100))
|
||||
|
||||
post.visibleActors = setOf(ActorId(200))
|
||||
assertEquals(setOf(ActorId(100), ActorId(200)), post.visibleActors)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun visibleActorsに追加された時updateイベントが発生する() {
|
||||
val post = TestPostFactory.create(visibility = Visibility.DIRECT)
|
||||
|
||||
post.visibleActors = setOf(ActorId(100))
|
||||
|
||||
assertContainsEvent(post, PostEvent.update.eventName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun hideがtrueのときcontetnがemptyを返す() {
|
||||
val post = TestPostFactory.create(hide = true)
|
||||
|
||||
assertEquals(PostContent.empty, post.content)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun deletedがtrueの時contentをセットできない() {
|
||||
val post = TestPostFactory.create(deleted = true)
|
||||
|
||||
assertThrows<IllegalArgumentException> {
|
||||
post.content = PostContent("test", "test", emptyList())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun contentの内容が変更されたらupdateイベントが発生する() {
|
||||
val post = TestPostFactory.create()
|
||||
|
||||
post.content = PostContent("test", "test", emptyList())
|
||||
assertContainsEvent(post, PostEvent.update.eventName)
|
||||
}
|
||||
}
|
|
@ -42,7 +42,7 @@ object TestPostFactory {
|
|||
apId = apId,
|
||||
deleted = deleted,
|
||||
mediaIds.map { MediaId(it) },
|
||||
visibleActors.map { ActorId(it) },
|
||||
visibleActors.map { ActorId(it) }.toSet(),
|
||||
hide = hide,
|
||||
moveTo?.let { PostId(it) }
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue