mirror of https://github.com/usbharu/Hideout.git
test: Postのテストを追加
This commit is contained in:
parent
34a049da5b
commit
19ee832a6f
|
@ -184,6 +184,7 @@ class Post(
|
|||
}
|
||||
|
||||
fun restore(content: PostContent, overview: PostOverview?, mediaIds: List<MediaId>) {
|
||||
require(deleted)
|
||||
deleted = false
|
||||
this.content = content
|
||||
this.overview = overview
|
||||
|
|
|
@ -6,6 +6,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorPublicKey
|
|||
import dev.usbharu.hideout.core.domain.model.actor.TestActorFactory
|
||||
import dev.usbharu.hideout.core.domain.model.emoji.EmojiId
|
||||
import dev.usbharu.hideout.core.domain.model.media.MediaId
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertDoesNotThrow
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
|
@ -14,6 +15,7 @@ import utils.AssertDomainEvent.assertEmpty
|
|||
import java.net.URI
|
||||
import java.time.Instant
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertNull
|
||||
|
||||
class PostTest {
|
||||
|
@ -550,4 +552,136 @@ class PostTest {
|
|||
|
||||
assertEquals(mediaIds, post.mediaIds)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `delete deleteイベントが発生する`() {
|
||||
|
||||
val actor = TestActorFactory.create()
|
||||
val post = TestPostFactory.create(deleted = false, actorId = actor.id.id)
|
||||
post.delete(actor)
|
||||
assertContainsEvent(post, PostEvent.DELETE.eventName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `delete すでにdeletedがtrueの時deleteイベントは発生しない`() {
|
||||
|
||||
val actor = TestActorFactory.create()
|
||||
val post = TestPostFactory.create(deleted = true, actorId = actor.id.id)
|
||||
post.delete(actor)
|
||||
assertEmpty(post)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `delete contentがemptyにoverviewがnullにmediaIdsがemptyになる`() {
|
||||
val actor = TestActorFactory.create()
|
||||
val post = TestPostFactory.create(deleted = false, actorId = actor.id.id)
|
||||
post.delete(actor)
|
||||
assertEquals(PostContent.empty, post.content)
|
||||
assertNull(post.overview)
|
||||
assertEquals(emptyList(), post.mediaIds)
|
||||
assertTrue(post.deleted)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `checkUpdate CHECKUPDATEイベントが発生する`() {
|
||||
val post = TestPostFactory.create()
|
||||
|
||||
post.checkUpdate()
|
||||
|
||||
assertContainsEvent(post, PostEvent.CHECK_UPDATE.eventName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `restore 指定された引数で再構成されCHECKUPDATEイベントが発生する`() {
|
||||
val post = TestPostFactory.create(deleted = true)
|
||||
|
||||
val postContent = PostContent("aiueo", "aiueo", listOf(EmojiId(1)))
|
||||
val overview = PostOverview("overview")
|
||||
val mediaIds = listOf(MediaId(1))
|
||||
post.restore(
|
||||
postContent,
|
||||
overview,
|
||||
mediaIds
|
||||
)
|
||||
|
||||
assertContainsEvent(post, PostEvent.CHECK_UPDATE.eventName)
|
||||
assertEquals(postContent, post.content)
|
||||
assertEquals(overview, post.overview)
|
||||
assertEquals(mediaIds, post.mediaIds)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun deletedがfalseの時失敗する() {
|
||||
val post = TestPostFactory.create(deleted = false)
|
||||
|
||||
val postContent = PostContent("aiueo", "aiueo", listOf(EmojiId(1)))
|
||||
val overview = PostOverview("overview")
|
||||
val mediaIds = listOf(MediaId(1))
|
||||
assertThrows<IllegalArgumentException> {
|
||||
post.restore(
|
||||
postContent,
|
||||
overview,
|
||||
mediaIds
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `addMediaIds deletedがtrueの時失敗する`() {
|
||||
val post = TestPostFactory.create(deleted = true)
|
||||
val actor = TestActorFactory.create(id = post.actorId.id)
|
||||
|
||||
assertThrows<IllegalArgumentException> {
|
||||
post.addMediaIds(listOf(MediaId(1)), actor)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `addMediaIds updateイベントが発生する`() {
|
||||
val post = TestPostFactory.create(deleted = false)
|
||||
val actor = TestActorFactory.create(id = post.actorId.id)
|
||||
|
||||
post.addMediaIds(listOf(MediaId(2)), actor)
|
||||
assertContainsEvent(post, PostEvent.UPDATE.eventName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `hide hideがtrueになる`() {
|
||||
val post = TestPostFactory.create(hide = false)
|
||||
|
||||
post.hide()
|
||||
|
||||
assertTrue(post.hide)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `show hideがfalseになる`() {
|
||||
val post = TestPostFactory.create(hide = true)
|
||||
|
||||
post.show()
|
||||
|
||||
assertFalse(post.hide)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `moveTo すでに設定されている場合は失敗する`() {
|
||||
val post = TestPostFactory.create(moveTo = 100)
|
||||
val actor = TestActorFactory.create(post.actorId.id)
|
||||
|
||||
assertThrows<IllegalArgumentException> {
|
||||
post.moveTo(PostId(2), actor)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `moveTo moveToが設定される`() {
|
||||
val post = TestPostFactory.create(moveTo = null)
|
||||
val actor = TestActorFactory.create(post.actorId.id)
|
||||
|
||||
assertDoesNotThrow {
|
||||
post.moveTo(PostId(2), actor)
|
||||
}
|
||||
|
||||
assertEquals(PostId(2), post.moveTo)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue