diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/Relationship.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/Relationship.kt index 4893d62a..03237ef4 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/Relationship.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/Relationship.kt @@ -49,9 +49,9 @@ data class Relationship( muting = relationship.muting, followRequesting = relationship.followRequesting, followRequestedBy = relationship2.followRequesting, - domainBlocking = actorInstanceRelationship.isBlocking(), - domainMuting = actorInstanceRelationship.isMuting(), - domainDoNotSendPrivate = actorInstanceRelationship.isDoNotSendPrivate() + domainBlocking = actorInstanceRelationship.blocking, + domainMuting = actorInstanceRelationship.muting, + domainDoNotSendPrivate = actorInstanceRelationship.doNotSendPrivate ) } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actorinstancerelationship/ActorInstanceRelationshipEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actorinstancerelationship/ActorInstanceRelationshipEvent.kt index 5ff3fc5f..bf332080 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actorinstancerelationship/ActorInstanceRelationshipEvent.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actorinstancerelationship/ActorInstanceRelationshipEvent.kt @@ -34,9 +34,9 @@ class ActorInstanceRelationshipEventBody(actorInstanceRelationship: ActorInstanc mapOf( "actorId" to actorInstanceRelationship.actorId, "instanceId" to actorInstanceRelationship.instanceId, - "muting" to actorInstanceRelationship.isMuting(), - "blocking" to actorInstanceRelationship.isBlocking(), - "doNotSendPrivate" to actorInstanceRelationship.isDoNotSendPrivate(), + "muting" to actorInstanceRelationship.muting, + "blocking" to actorInstanceRelationship.blocking, + "doNotSendPrivate" to actorInstanceRelationship.doNotSendPrivate, ) ) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt index 45d34c4d..239ce88f 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt @@ -79,7 +79,7 @@ class Actor( private set fun setRole(roles: Set, actor: Actor) { - require(actor.roles.contains(Role.ADMINISTRATOR).not()) + require(actor.roles.contains(Role.ADMINISTRATOR)) this.roles = roles } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorKeyId.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorKeyId.kt index ccf98962..3bc3e643 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorKeyId.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorKeyId.kt @@ -17,4 +17,8 @@ package dev.usbharu.hideout.core.domain.model.actor @JvmInline -value class ActorKeyId(val keyId: String) +value class ActorKeyId(val keyId: String) { + init { + require(keyId.isNotBlank()) + } +} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorName.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorName.kt index 6819fc8e..a2e6697e 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorName.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorName.kt @@ -20,12 +20,12 @@ package dev.usbharu.hideout.core.domain.model.actor value class ActorName(val name: String) { init { require(name.isNotBlank()) - require(name.length <= length) + require(name.length <= LENGTH) require(regex.matches(name)) } companion object { - val length = 300 - private val regex = Regex("^[a-zA-Z0-9_-]{1,$length}\$") + const val LENGTH = 300 + private val regex = Regex("^[a-zA-Z0-9_-]{1,$LENGTH}\$") } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Role.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Role.kt index 39c3acd4..083ffc20 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Role.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Role.kt @@ -17,5 +17,8 @@ package dev.usbharu.hideout.core.domain.model.actor enum class Role { - LOCAL, MODERATOR, ADMINISTRATOR, REMOTE + LOCAL, + MODERATOR, + ADMINISTRATOR, + REMOTE; } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationship.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationship.kt index f4244ca5..90c7b529 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationship.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationship.kt @@ -22,13 +22,20 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.instance.InstanceId import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventStorable -data class ActorInstanceRelationship( +class ActorInstanceRelationship( val actorId: ActorId, val instanceId: InstanceId, - private var blocking: Boolean = false, - private var muting: Boolean = false, - private var doNotSendPrivate: Boolean = false, + blocking: Boolean = false, + muting: Boolean = false, + doNotSendPrivate: Boolean = false, ) : DomainEventStorable() { + var doNotSendPrivate = doNotSendPrivate + private set + var muting = muting + private set + var blocking = blocking + private set + fun block(): ActorInstanceRelationship { addDomainEvent(ActorInstanceRelationshipDomainEventFactory(this).createEvent(BLOCK)) blocking = true @@ -62,12 +69,6 @@ data class ActorInstanceRelationship( return this } - fun isBlocking() = blocking - - fun isMuting() = muting - - fun isDoNotSendPrivate() = doNotSendPrivate - override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterKeyword.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterKeyword.kt index 0e8774ba..9f234f6e 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterKeyword.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterKeyword.kt @@ -1,17 +1,8 @@ package dev.usbharu.hideout.core.domain.model.filter -import dev.usbharu.hideout.core.domain.model.filter.FilterMode.* - class FilterKeyword( val id: FilterKeywordId, var keyword: FilterKeywordKeyword, val mode: FilterMode ) { - fun match(string: String): Boolean { - when (mode) { - WHOLE_WORD -> TODO() - REGEX -> TODO() - NONE -> TODO() - } - } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorInstanceRelationshipRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorInstanceRelationshipRepository.kt index ab7ab447..1843c88a 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorInstanceRelationshipRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorInstanceRelationshipRepository.kt @@ -41,9 +41,9 @@ class ExposedActorInstanceRelationshipRepository(override val domainEventPublish ActorInstanceRelationships.upsert { it[actorId] = actorInstanceRelationship.actorId.id it[instanceId] = actorInstanceRelationship.instanceId.instanceId - it[blocking] = actorInstanceRelationship.isBlocking() - it[muting] = actorInstanceRelationship.isMuting() - it[doNotSendPrivate] = actorInstanceRelationship.isDoNotSendPrivate() + it[blocking] = actorInstanceRelationship.blocking + it[muting] = actorInstanceRelationship.muting + it[doNotSendPrivate] = actorInstanceRelationship.doNotSendPrivate } } update(actorInstanceRelationship) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorRepository.kt index 8e184021..a11d20f3 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorRepository.kt @@ -105,7 +105,7 @@ class ExposedActorRepository( object Actors : Table("actors") { val id = long("id") - val name = varchar("name", ActorName.length) + val name = varchar("name", ActorName.LENGTH) val domain = varchar("domain", Domain.LENGTH) val screenName = varchar("screen_name", ActorScreenName.length) val description = varchar("description", ActorDescription.length) diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorDescriptionTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorDescriptionTest.kt index acfa8b11..6bf6ab63 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorDescriptionTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorDescriptionTest.kt @@ -1,3 +1,13 @@ package dev.usbharu.hideout.core.domain.model.actor -class ActorDescriptionTest \ No newline at end of file +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals + +class ActorDescriptionTest { + @Test + fun actorDescriptionがlength以上なら無視される() { + val actorScreenName = ActorDescription("a".repeat(100000)) + + assertEquals(ActorDescription.length, actorScreenName.description.length) + } +} \ No newline at end of file diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorKeyIdTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorKeyIdTest.kt new file mode 100644 index 00000000..8de564da --- /dev/null +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorKeyIdTest.kt @@ -0,0 +1,25 @@ +package dev.usbharu.hideout.core.domain.model.actor + +import org.junit.jupiter.api.Assertions.assertDoesNotThrow +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows + +class ActorKeyIdTest { + @Test + fun keyIdはblankではいけない() { + assertThrows { + ActorKeyId("") + } + + assertThrows { + ActorKeyId(" ") + } + } + + @Test + fun keyIdがblankでなければ作成できる() { + assertDoesNotThrow { + ActorKeyId("aiueo") + } + } +} \ No newline at end of file diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPostsCountTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPostsCountTest.kt new file mode 100644 index 00000000..451913b5 --- /dev/null +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPostsCountTest.kt @@ -0,0 +1,20 @@ +package dev.usbharu.hideout.core.domain.model.actor + +import org.junit.jupiter.api.Assertions.assertDoesNotThrow +import org.junit.jupiter.api.Test + +class ActorPostsCountTest { + @Test + fun postsCountが負になることはない() { + org.junit.jupiter.api.assertThrows { + ActorPostsCount(-1) + } + } + + @Test + fun postsCountが正の数値なら設定できる() { + assertDoesNotThrow { + ActorPostsCount(1) + } + } +} \ No newline at end of file diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPrivateKeyTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPrivateKeyTest.kt new file mode 100644 index 00000000..68ff6877 --- /dev/null +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPrivateKeyTest.kt @@ -0,0 +1,18 @@ +package dev.usbharu.hideout.core.domain.model.actor + +import dev.usbharu.hideout.util.Base64Util +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import java.security.KeyPairGenerator + +class ActorPrivateKeyTest { + @Test + fun privateKeyから生成できる() { + val genKeyPair = KeyPairGenerator.getInstance("RSA").genKeyPair() + val actorPrivateKey = ActorPrivateKey.create(genKeyPair.private) + val key = "-----BEGIN PRIVATE KEY-----\n" + + Base64Util.encode(genKeyPair.private.encoded).chunked(64) + .joinToString("\n") + "\n-----END PRIVATE KEY-----" + assertEquals(key, actorPrivateKey.privateKey) + } +} \ No newline at end of file diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPublicKeyTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPublicKeyTest.kt index 37bb1938..a2ec7f79 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPublicKeyTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPublicKeyTest.kt @@ -1,3 +1,18 @@ package dev.usbharu.hideout.core.domain.model.actor -class ActorPublicKeyTest \ No newline at end of file +import dev.usbharu.hideout.util.Base64Util +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import java.security.KeyPairGenerator + +class ActorPublicKeyTest { + @Test + fun publicKeyから生成できる() { + val genKeyPair = KeyPairGenerator.getInstance("RSA").genKeyPair() + val actorPublicKey = ActorPublicKey.create(genKeyPair.public) + val key = "-----BEGIN PUBLIC KEY-----\n" + + Base64Util.encode(genKeyPair.public.encoded).chunked(64) + .joinToString("\n") + "\n-----END PUBLIC KEY-----" + assertEquals(key, actorPublicKey.publicKey) + } +} \ No newline at end of file diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorRelationshipCountTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorRelationshipCountTest.kt new file mode 100644 index 00000000..340d1563 --- /dev/null +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorRelationshipCountTest.kt @@ -0,0 +1,21 @@ +package dev.usbharu.hideout.core.domain.model.actor + +import org.junit.jupiter.api.Assertions.assertDoesNotThrow +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows + +class ActorRelationshipCountTest { + @Test + fun relationshipCountが負になることはない() { + assertThrows { + ActorRelationshipCount(-1) + } + } + + @Test + fun relationshipCountが正の数値なら設定できる() { + assertDoesNotThrow { + ActorRelationshipCount(1) + } + } +} \ No newline at end of file diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorsTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorsTest.kt index a8a67f4d..b50a6637 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorsTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorsTest.kt @@ -1,7 +1,9 @@ package dev.usbharu.hideout.core.domain.model.actor import dev.usbharu.hideout.core.domain.event.actor.ActorEvent +import dev.usbharu.hideout.core.domain.model.media.MediaId import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertDoesNotThrow import org.junit.jupiter.api.assertThrows import utils.AssertDomainEvent.assertContainsEvent import utils.AssertDomainEvent.assertEmpty @@ -127,4 +129,44 @@ class ActorsTest { assertContainsEvent(actor, ActorEvent.CHECK_UPDATE.eventName) } + + @Test + fun bannerが設定されたらupdateイベントが発生する() { + val actor = TestActorFactory.create(publicKey = ActorPublicKey("")) + + actor.setBannerUrl(MediaId(1), actor) + + assertContainsEvent(actor, ActorEvent.UPDATE.eventName) + } + + @Test + fun iconが設定されたらupdateイベントが発生する() { + val actor = TestActorFactory.create(publicKey = ActorPublicKey("")) + + actor.setIconUrl(MediaId(1), actor) + + assertContainsEvent(actor, ActorEvent.UPDATE.eventName) + } + + @Test + fun administratorロールを持っている人はroleを設定できる() { + val admin = TestActorFactory.create(roles = setOf(Role.ADMINISTRATOR)) + + val actor = TestActorFactory.create() + + assertDoesNotThrow { + actor.setRole(setOf(Role.MODERATOR), admin) + } + } + + @Test + fun administratorロールを持ってないとはroleを設定できない() { + val admin = TestActorFactory.create(roles = setOf(Role.MODERATOR)) + + val actor = TestActorFactory.create() + + assertThrows { + actor.setRole(setOf(Role.MODERATOR), admin) + } + } } \ No newline at end of file diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/TestActorFactory.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/TestActorFactory.kt index 0fb9087d..57e3d0d5 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/TestActorFactory.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/TestActorFactory.kt @@ -34,9 +34,10 @@ object TestActorFactory { lastPostDate: Instant? = null, suspend: Boolean = false, alsoKnownAs: Set = emptySet(), - moveTo: ActorId? = null, + moveTo: Long? = null, emojiIds: Set = emptySet(), deleted: Boolean = false, + roles: Set = emptySet(), ): Actor { return runBlocking { Actor( @@ -62,12 +63,13 @@ object TestActorFactory { lastPostAt = lastPostDate, suspend = suspend, alsoKnownAs = alsoKnownAs, - moveTo = moveTo, + moveTo = moveTo?.let { ActorId(it) }, emojiIds = emojiIds, deleted = deleted, - roles = emptySet(), + roles = roles, icon = null, - banner = null + banner = null, + ) } } diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationshipTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationshipTest.kt new file mode 100644 index 00000000..c24c559d --- /dev/null +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationshipTest.kt @@ -0,0 +1,77 @@ +package dev.usbharu.hideout.core.domain.model.actorinstancerelationship + +import dev.usbharu.hideout.core.domain.event.actorinstancerelationship.ActorInstanceRelationshipEvent +import dev.usbharu.hideout.core.domain.model.actor.ActorId +import dev.usbharu.hideout.core.domain.model.instance.InstanceId +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test +import utils.AssertDomainEvent.assertContainsEvent + +class ActorInstanceRelationshipTest { + @Test + fun blockするとBLOCKイベントが発生する() { + val actorInstanceRelationship = ActorInstanceRelationship(ActorId(1), InstanceId(2), false) + + actorInstanceRelationship.block() + + assertContainsEvent(actorInstanceRelationship, ActorInstanceRelationshipEvent.BLOCK.eventName) + assertTrue(actorInstanceRelationship.blocking) + } + + @Test + fun muteするとMUTEイベントが発生する() { + val actorInstanceRelationship = ActorInstanceRelationship(ActorId(1), InstanceId(2), false) + + actorInstanceRelationship.mute() + + assertContainsEvent(actorInstanceRelationship, ActorInstanceRelationshipEvent.MUTE.eventName) + assertTrue(actorInstanceRelationship.muting) + } + + @Test + fun unmuteするとUNMUTEイベントが発生する() { + val actorInstanceRelationship = ActorInstanceRelationship(ActorId(1), InstanceId(2), muting = true) + + actorInstanceRelationship.unmute() + + assertContainsEvent(actorInstanceRelationship, ActorInstanceRelationshipEvent.UNMUTE.eventName) + assertFalse(actorInstanceRelationship.muting) + } + + @Test + fun unblockで解除される() { + val actorInstanceRelationship = ActorInstanceRelationship(ActorId(1), InstanceId(2), true) + + actorInstanceRelationship.unblock() + + assertFalse(actorInstanceRelationship.blocking) + } + + @Test + fun doNotSendPrivateで設定される() { + val actorInstanceRelationship = ActorInstanceRelationship(ActorId(1), InstanceId(2)) + + actorInstanceRelationship.doNotSendPrivate() + + assertTrue(actorInstanceRelationship.doNotSendPrivate) + } + + @Test + fun doSendPrivateで解除される() { + val actorInstanceRelationship = ActorInstanceRelationship(ActorId(1), InstanceId(2), doNotSendPrivate = true) + + actorInstanceRelationship.doSendPrivate() + + assertFalse(actorInstanceRelationship.doNotSendPrivate) + } + + @Test + fun defaultで全部falseが作られる() { + val default = ActorInstanceRelationship.default(ActorId(1), InstanceId(2)) + + assertFalse(default.muting) + assertFalse(default.blocking) + assertFalse(default.doNotSendPrivate) + } +} \ No newline at end of file