From 1038e9e2419bd292ddfbe589ab0b2a008ba34ccc Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 18 Jun 2024 00:00:52 +0900 Subject: [PATCH] =?UTF-8?q?test:=20posts=E3=81=AE=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/core/domain/model/post/Post.kt | 3 - .../core/domain/model/post/PostTest.kt | 66 +++++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt index 9bf9211c..98b4ee60 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt @@ -298,9 +298,6 @@ class Post( fun isAllow(actor: Actor, action: Action, resource: Post): Boolean { return when (action) { UPDATE -> { - if (actor.deleted) { - return true - } resource.actorId == actor.id || actor.roles.contains(Role.ADMINISTRATOR) || actor.roles.contains( Role.MODERATOR ) diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostTest.kt index c881d6e4..e9c8e8e1 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostTest.kt @@ -9,6 +9,8 @@ import org.junit.jupiter.api.assertDoesNotThrow import org.junit.jupiter.api.assertThrows import utils.AssertDomainEvent.assertContainsEvent import utils.AssertDomainEvent.assertEmpty +import java.net.URI +import java.time.Instant import kotlin.test.assertEquals import kotlin.test.assertNull @@ -260,5 +262,69 @@ class PostTest { assertEmpty(post) } + @Test + fun sensitiveが変更されるとupdateイベントが発生する() { + val post = TestPostFactory.create() + val actor = TestActorFactory.create(id = post.actorId.id, publicKey = ActorPublicKey("")) + post.setSensitive(true, actor) + assertContainsEvent(post, PostEvent.UPDATE.eventName) + } + @Test + fun 削除されている場合sensitiveを変更できない() { + val post = TestPostFactory.create(deleted = true) + val actor = TestActorFactory.create(id = post.actorId.id, publicKey = ActorPublicKey("")) + assertThrows { + post.setSensitive(true, actor) + } + } + + @Test + fun sensitiveが変更されなかった場合イベントが発生しない() { + val post = TestPostFactory.create(overview = "aaaa") + val actor = TestActorFactory.create(id = post.actorId.id, publicKey = ActorPublicKey("")) + post.setSensitive(false, actor) + assertEmpty(post) + } + + @Test + fun hideがtrueの時emptyが帰る() { + val post = TestPostFactory.create(hide = true) + + assertEquals(PostContent.empty.text, post.text) + } + + @Test + fun hideがfalseの時textが返る() { + val post = TestPostFactory.create(hide = false, content = "aaaa") + + assertEquals("aaaa", post.text) + } + + @Test + fun `create actorが削除済みの時作成できない`() { + val actor = TestActorFactory.create(deleted = true) + assertThrows { + Post.create( + id = PostId(1), + actorId = actor.id, + overview = null, + content = PostContent.empty, + createdAt = Instant.now(), + visibility = Visibility.PUBLIC, + url = URI.create("https://example.com"), + repostId = null, + replyId = null, + sensitive = false, + apId = URI.create("https://example.com"), + deleted = false, + mediaIds = emptyList(), + visibleActors = emptySet(), + hide = false, + moveTo = null, + actor = actor + + ) + } + } } \ No newline at end of file