mirror of https://github.com/usbharu/Hideout.git
test: Actorのテストを追加
This commit is contained in:
parent
2b23b21ec6
commit
845569a7f9
|
@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ class Actor(
|
|||
private set
|
||||
|
||||
fun setRole(roles: Set<Role>, actor: Actor) {
|
||||
require(actor.roles.contains(Role.ADMINISTRATOR).not())
|
||||
require(actor.roles.contains(Role.ADMINISTRATOR))
|
||||
|
||||
this.roles = roles
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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}\$")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,5 +17,8 @@
|
|||
package dev.usbharu.hideout.core.domain.model.actor
|
||||
|
||||
enum class Role {
|
||||
LOCAL, MODERATOR, ADMINISTRATOR, REMOTE
|
||||
LOCAL,
|
||||
MODERATOR,
|
||||
ADMINISTRATOR,
|
||||
REMOTE;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
package dev.usbharu.hideout.core.domain.model.actor
|
||||
|
||||
class ActorDescriptionTest
|
||||
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)
|
||||
}
|
||||
}
|
|
@ -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<IllegalArgumentException> {
|
||||
ActorKeyId("")
|
||||
}
|
||||
|
||||
assertThrows<IllegalArgumentException> {
|
||||
ActorKeyId(" ")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun keyIdがblankでなければ作成できる() {
|
||||
assertDoesNotThrow {
|
||||
ActorKeyId("aiueo")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<IllegalArgumentException> {
|
||||
ActorPostsCount(-1)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun postsCountが正の数値なら設定できる() {
|
||||
assertDoesNotThrow {
|
||||
ActorPostsCount(1)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -1,3 +1,18 @@
|
|||
package dev.usbharu.hideout.core.domain.model.actor
|
||||
|
||||
class ActorPublicKeyTest
|
||||
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)
|
||||
}
|
||||
}
|
|
@ -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<IllegalArgumentException> {
|
||||
ActorRelationshipCount(-1)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun relationshipCountが正の数値なら設定できる() {
|
||||
assertDoesNotThrow {
|
||||
ActorRelationshipCount(1)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<IllegalArgumentException> {
|
||||
actor.setRole(setOf(Role.MODERATOR), admin)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,9 +34,10 @@ object TestActorFactory {
|
|||
lastPostDate: Instant? = null,
|
||||
suspend: Boolean = false,
|
||||
alsoKnownAs: Set<ActorId> = emptySet(),
|
||||
moveTo: ActorId? = null,
|
||||
moveTo: Long? = null,
|
||||
emojiIds: Set<EmojiId> = emptySet(),
|
||||
deleted: Boolean = false,
|
||||
roles: Set<Role> = 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,
|
||||
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue