mirror of https://github.com/usbharu/Hideout.git
commit
ab4a346935
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -17,4 +17,8 @@
|
|||
package dev.usbharu.hideout.core.domain.model.application
|
||||
|
||||
@JvmInline
|
||||
value class ApplicationId(val id: Long)
|
||||
value class ApplicationId(val id: Long) {
|
||||
init {
|
||||
require(0 <= id)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,4 +17,12 @@
|
|||
package dev.usbharu.hideout.core.domain.model.application
|
||||
|
||||
@JvmInline
|
||||
value class ApplicationName(val name: String)
|
||||
value class ApplicationName(val name: String) {
|
||||
init {
|
||||
require(name.length <= LENGTH)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val LENGTH = 300
|
||||
}
|
||||
}
|
|
@ -17,4 +17,8 @@
|
|||
package dev.usbharu.hideout.core.domain.model.emoji
|
||||
|
||||
@JvmInline
|
||||
value class EmojiId(val emojiId: Long)
|
||||
value class EmojiId(val emojiId: Long) {
|
||||
init {
|
||||
require(0 <= emojiId)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,11 @@ class Filter(
|
|||
this.filterKeywords = filterKeywords
|
||||
}
|
||||
|
||||
/**
|
||||
* フィルターを正規表現として表現したものを返します
|
||||
*
|
||||
* @return フィルターの正規表現
|
||||
*/
|
||||
fun compileFilter(): Regex {
|
||||
val words = mutableListOf<String>()
|
||||
val wholeWords = mutableListOf<String>()
|
||||
|
@ -33,10 +38,11 @@ class Filter(
|
|||
NONE -> words.add(filterKeyword.keyword.keyword)
|
||||
}
|
||||
}
|
||||
val wholeWordsRegex = wholeWords.takeIf { it.isNotEmpty() }?.joinToString("|", "\\b(", ")\\b")
|
||||
val noneWordsRegex = words.takeIf { it.isNotEmpty() }?.joinToString("|", "(", ")")
|
||||
val regex = regexes.takeIf { it.isNotEmpty() }?.joinToString("|", "(", ")")
|
||||
|
||||
return (wholeWords + regexes + wholeWords)
|
||||
.joinToString("|")
|
||||
.toRegex()
|
||||
return listOfNotNull(wholeWordsRegex, noneWordsRegex, regex).joinToString("|").toRegex()
|
||||
}
|
||||
|
||||
fun reconstructWith(filterKeywords: Set<FilterKeyword>): Filter {
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
package dev.usbharu.hideout.core.domain.model.filter
|
||||
|
||||
@JvmInline
|
||||
value class FilterId(val id: Long)
|
||||
value class FilterId(val id: Long) {
|
||||
init {
|
||||
require(0 <= id)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
package dev.usbharu.hideout.core.domain.model.filter
|
||||
|
||||
@JvmInline
|
||||
value class FilterName(val name: String)
|
||||
|
||||
class FilterName(name: String) {
|
||||
|
||||
|
||||
val name = name.take(LENGTH)
|
||||
|
||||
companion object {
|
||||
const val LENGTH = 300
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -298,9 +299,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
|
||||
)
|
||||
|
|
|
@ -34,7 +34,7 @@ class LocalActorMigrationCheckDomainServiceImpl : LocalActorMigrationCheckDomain
|
|||
return AccountMigrationCheck.AlreadyMoved("${from.name}@${from.domain} was move to ${from.moveTo}")
|
||||
}
|
||||
|
||||
if (to.alsoKnownAs.contains(to.id).not()) {
|
||||
if (to.alsoKnownAs.contains(from.id).not()) {
|
||||
return AccountMigrationCheck.AlsoKnownAsNotFound("${to.id} has ${to.alsoKnownAs}")
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -19,7 +19,6 @@ package dev.usbharu.hideout
|
|||
import com.fasterxml.jackson.module.kotlin.isKotlinClass
|
||||
import com.jparams.verifier.tostring.ToStringVerifier
|
||||
import com.jparams.verifier.tostring.preset.Presets
|
||||
import dev.usbharu.hideout.core.domain.model.emoji.UnicodeEmoji
|
||||
import nl.jqno.equalsverifier.EqualsVerifier
|
||||
import nl.jqno.equalsverifier.Warning
|
||||
import nl.jqno.equalsverifier.internal.reflection.PackageScanner
|
||||
|
@ -115,7 +114,6 @@ class EqualsAndToStringTest {
|
|||
.filterNot {
|
||||
it.superclass.isSealed
|
||||
}
|
||||
.filterNot { it == UnicodeEmoji::class.java }
|
||||
.map {
|
||||
|
||||
dynamicTest(it.name) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package dev.usbharu.hideout.core.domain.model.application
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertDoesNotThrow
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class ApplicationIdTest {
|
||||
@Test
|
||||
fun applicationIdは0以上である必要がある() {
|
||||
org.junit.jupiter.api.assertThrows<IllegalArgumentException> {
|
||||
ApplicationId(-1)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun applicationIdが0以上なら設定できる() {
|
||||
assertDoesNotThrow {
|
||||
ApplicationId(1)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package dev.usbharu.hideout.core.domain.model.application
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertDoesNotThrow
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class ApplicationNameTest {
|
||||
@Test
|
||||
fun applicationNameがlength以上の時エラー() {
|
||||
org.junit.jupiter.api.assertThrows<IllegalArgumentException> {
|
||||
ApplicationName("a".repeat(1000))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun applicationNameがlength未満の時設定できる() {
|
||||
assertDoesNotThrow {
|
||||
ApplicationName("a".repeat(100))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package dev.usbharu.hideout.core.domain.model.application
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class ApplicationTest {
|
||||
@Test
|
||||
fun インスタンスを生成できる() {
|
||||
Application(
|
||||
ApplicationId(1),
|
||||
ApplicationName("aiueo")
|
||||
)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package dev.usbharu.hideout.core.domain.model.emoji
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertDoesNotThrow
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class EmojiIdTest {
|
||||
@Test
|
||||
fun emojiIdは0以上である必要がある() {
|
||||
org.junit.jupiter.api.assertThrows<IllegalArgumentException> {
|
||||
EmojiId(-1)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun emojiIdは0以上なら設定できる() {
|
||||
assertDoesNotThrow {
|
||||
EmojiId(1)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package dev.usbharu.hideout.core.domain.model.filter
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertDoesNotThrow
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class FilterIdTest {
|
||||
@Test
|
||||
fun filterIdは0以上である必要がある() {
|
||||
org.junit.jupiter.api.assertThrows<IllegalArgumentException> {
|
||||
FilterId(-1)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun filterIdが0以上なら設定できる() {
|
||||
assertDoesNotThrow {
|
||||
FilterId(1)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package dev.usbharu.hideout.core.domain.model.filter
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class FilterNameTest {
|
||||
@Test
|
||||
fun FilterNameがlength以上のときは無視される() {
|
||||
val filterName = FilterName("a".repeat(1000))
|
||||
|
||||
assertEquals(FilterName.LENGTH, filterName.name.length)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
package dev.usbharu.hideout.core.domain.model.filter
|
||||
|
||||
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetail
|
||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailHashedPassword
|
||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
||||
import org.junit.jupiter.api.Assertions.assertDoesNotThrow
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class FilterTest {
|
||||
@Test
|
||||
fun `setFilterKeywords 所有者のみ変更できる`() {
|
||||
val filter = Filter.create(
|
||||
id = FilterId(1),
|
||||
userDetailId = UserDetailId(1),
|
||||
name = FilterName("aiueo"),
|
||||
filterContext = setOf(),
|
||||
filterAction = FilterAction.HIDE,
|
||||
filterKeywords = setOf()
|
||||
)
|
||||
|
||||
val userDetail = UserDetail.create(
|
||||
id = UserDetailId(1),
|
||||
actorId = ActorId(1),
|
||||
password = UserDetailHashedPassword(""),
|
||||
autoAcceptFolloweeFollowRequest = false,
|
||||
lastMigration = null
|
||||
)
|
||||
|
||||
assertDoesNotThrow {
|
||||
filter.setFilterKeywords(
|
||||
setOf(
|
||||
FilterKeyword(
|
||||
FilterKeywordId(1),
|
||||
FilterKeywordKeyword("keyword"),
|
||||
FilterMode.NONE
|
||||
)
|
||||
), userDetail
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun compileFilterで正規表現として表すことができるNONE() {
|
||||
val filter = Filter(
|
||||
id = FilterId(1),
|
||||
userDetailId = UserDetailId(1),
|
||||
name = FilterName("aiueo"),
|
||||
filterContext = setOf(),
|
||||
filterAction = FilterAction.HIDE,
|
||||
filterKeywords = setOf(
|
||||
FilterKeyword(
|
||||
FilterKeywordId(1),
|
||||
FilterKeywordKeyword("hoge"),
|
||||
FilterMode.NONE
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
kotlin.test.assertEquals("(hoge)", filter.compileFilter().pattern)
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun compileFilterで正規表現として表すことができるWHOLE_WORD() {
|
||||
val filter = Filter(
|
||||
id = FilterId(1),
|
||||
userDetailId = UserDetailId(1),
|
||||
name = FilterName("aiueo"),
|
||||
filterContext = setOf(),
|
||||
filterAction = FilterAction.HIDE,
|
||||
filterKeywords = setOf(
|
||||
FilterKeyword(
|
||||
FilterKeywordId(1),
|
||||
FilterKeywordKeyword("hoge"),
|
||||
FilterMode.WHOLE_WORD
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
kotlin.test.assertEquals("\\b(hoge)\\b", filter.compileFilter().pattern)
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun compileFilterで正規表現として表すことができるREGEX() {
|
||||
val filter = Filter(
|
||||
id = FilterId(1),
|
||||
userDetailId = UserDetailId(1),
|
||||
name = FilterName("aiueo"),
|
||||
filterContext = setOf(),
|
||||
filterAction = FilterAction.HIDE,
|
||||
filterKeywords = setOf(
|
||||
FilterKeyword(
|
||||
FilterKeywordId(1),
|
||||
FilterKeywordKeyword("hoge"),
|
||||
FilterMode.REGEX
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
kotlin.test.assertEquals("(hoge)", filter.compileFilter().pattern)
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun compileFilterで正規表現として表すことができる() {
|
||||
val filter = Filter(
|
||||
id = FilterId(1),
|
||||
userDetailId = UserDetailId(1),
|
||||
name = FilterName("aiueo"),
|
||||
filterContext = setOf(),
|
||||
filterAction = FilterAction.HIDE,
|
||||
filterKeywords = setOf(
|
||||
FilterKeyword(
|
||||
FilterKeywordId(1),
|
||||
FilterKeywordKeyword("hoge"),
|
||||
FilterMode.WHOLE_WORD
|
||||
),
|
||||
FilterKeyword(
|
||||
FilterKeywordId(2),
|
||||
FilterKeywordKeyword("hoge"),
|
||||
FilterMode.REGEX
|
||||
),
|
||||
FilterKeyword(
|
||||
FilterKeywordId(3),
|
||||
FilterKeywordKeyword("hoge"),
|
||||
FilterMode.NONE
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
kotlin.test.assertEquals("\\b(hoge)\\b|(hoge)|(hoge)", filter.compileFilter().pattern)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -4,12 +4,18 @@ 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.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
|
||||
import utils.AssertDomainEvent.assertContainsEvent
|
||||
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 {
|
||||
|
@ -260,5 +266,422 @@ 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<IllegalArgumentException> {
|
||||
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<IllegalArgumentException> {
|
||||
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
|
||||
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `create actorがsuspedの時visibilityがpublicの登校はunlistedになる`() {
|
||||
val actor = TestActorFactory.create(suspend = true)
|
||||
|
||||
val post = 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
|
||||
)
|
||||
|
||||
assertEquals(Visibility.UNLISTED, post.visibility)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `create actorがsuspedの時visibilityがunlistedの登校は変わらない`() {
|
||||
val actor = TestActorFactory.create(suspend = true)
|
||||
|
||||
val post = Post.create(
|
||||
id = PostId(1),
|
||||
actorId = actor.id,
|
||||
overview = null,
|
||||
content = PostContent.empty,
|
||||
createdAt = Instant.now(),
|
||||
visibility = Visibility.UNLISTED,
|
||||
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
|
||||
)
|
||||
|
||||
assertEquals(Visibility.UNLISTED, post.visibility)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `create 作成できる`() {
|
||||
val actor = TestActorFactory.create(suspend = true)
|
||||
|
||||
|
||||
assertDoesNotThrow {
|
||||
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `create 作成できる2`() {
|
||||
val actor = TestActorFactory.create(suspend = true)
|
||||
|
||||
|
||||
assertDoesNotThrow {
|
||||
|
||||
Post.create(
|
||||
id = PostId(1),
|
||||
actorId = actor.id,
|
||||
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(),
|
||||
actor = actor
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `emojiIds hideがtrueの時empty`() {
|
||||
val actor = TestActorFactory.create()
|
||||
val emojiIds = listOf(EmojiId(1), EmojiId(2))
|
||||
val post = Post.create(
|
||||
id = PostId(1),
|
||||
actorId = actor.id,
|
||||
content = PostContent("aaa", "aaa", emojiIds),
|
||||
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(),
|
||||
actor = actor,
|
||||
hide = true
|
||||
)
|
||||
|
||||
assertEquals(PostContent.empty.emojiIds, post.emojiIds)
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `emojiIds hideがfalseの時中身が返される`() {
|
||||
val actor = TestActorFactory.create()
|
||||
val emojiIds = listOf(EmojiId(1), EmojiId(2))
|
||||
val post = Post.create(
|
||||
id = PostId(1),
|
||||
actorId = actor.id,
|
||||
content = PostContent("aaa", "aaa", emojiIds),
|
||||
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(),
|
||||
actor = actor,
|
||||
hide = false
|
||||
)
|
||||
|
||||
assertEquals(emojiIds, post.emojiIds)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `reconstructWith 与えた引数で上書きされる`() {
|
||||
val post = TestPostFactory.create()
|
||||
val mediaIds = listOf<MediaId>(MediaId(1))
|
||||
val visibleActors = setOf<ActorId>((ActorId(2)))
|
||||
val emojis = listOf<EmojiId>(EmojiId(3))
|
||||
val reconstructWith = post.reconstructWith(mediaIds, emojis, visibleActors)
|
||||
|
||||
assertEquals(mediaIds, reconstructWith.mediaIds)
|
||||
assertEquals(visibleActors, reconstructWith.visibleActors)
|
||||
assertEquals(emojis, reconstructWith.emojiIds)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `mediaIds hideがtrueの時emptyが返される`() {
|
||||
val actor = TestActorFactory.create()
|
||||
val emojiIds = listOf(EmojiId(1), EmojiId(2))
|
||||
val mediaIds = listOf(MediaId(1))
|
||||
val post = Post.create(
|
||||
id = PostId(1),
|
||||
actorId = actor.id,
|
||||
content = PostContent("aaa", "aaa", emojiIds),
|
||||
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 = mediaIds,
|
||||
actor = actor,
|
||||
hide = true
|
||||
)
|
||||
|
||||
assertEquals(emptyList(), post.mediaIds)
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `mediaIds hideがfalseの時中身が返される`() {
|
||||
val actor = TestActorFactory.create()
|
||||
val emojiIds = listOf(EmojiId(1), EmojiId(2))
|
||||
val mediaIds = listOf(MediaId(2))
|
||||
val post = Post.create(
|
||||
id = PostId(1),
|
||||
actorId = actor.id,
|
||||
content = PostContent("aaa", "aaa", emojiIds),
|
||||
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 = mediaIds,
|
||||
actor = actor,
|
||||
hide = false
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package dev.usbharu.hideout.core.domain.service.actor.local
|
||||
|
||||
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
||||
import dev.usbharu.hideout.core.domain.model.actor.TestActorFactory
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Assertions.assertInstanceOf
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class LocalActorMigrationCheckDomainServiceImplTest {
|
||||
@Test
|
||||
fun 自分自身に引っ越しできない(): Unit = runTest {
|
||||
|
||||
val from = TestActorFactory.create()
|
||||
val to = TestActorFactory.create()
|
||||
|
||||
val localActorMigrationCheckDomainServiceImpl = LocalActorMigrationCheckDomainServiceImpl()
|
||||
|
||||
val canAccountMigration = localActorMigrationCheckDomainServiceImpl.canAccountMigration(from, from)
|
||||
|
||||
assertInstanceOf(AccountMigrationCheck.SelfReferences::class.java, canAccountMigration)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun 引越し先が引っ越している場合は引っ越しできない(): Unit = runTest {
|
||||
|
||||
val from = TestActorFactory.create()
|
||||
val to = TestActorFactory.create(moveTo = 100)
|
||||
|
||||
val localActorMigrationCheckDomainServiceImpl = LocalActorMigrationCheckDomainServiceImpl()
|
||||
|
||||
val canAccountMigration = localActorMigrationCheckDomainServiceImpl.canAccountMigration(from, to)
|
||||
|
||||
assertInstanceOf(AccountMigrationCheck.AlreadyMoved::class.java, canAccountMigration)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun 自分自身が引っ越している場合は引っ越しできない() = runTest {
|
||||
val from = TestActorFactory.create(moveTo = 100)
|
||||
val to = TestActorFactory.create()
|
||||
|
||||
val localActorMigrationCheckDomainServiceImpl = LocalActorMigrationCheckDomainServiceImpl()
|
||||
|
||||
val canAccountMigration = localActorMigrationCheckDomainServiceImpl.canAccountMigration(from, to)
|
||||
|
||||
assertInstanceOf(AccountMigrationCheck.AlreadyMoved::class.java, canAccountMigration)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun 引越し先のalsoKnownAsに引越し元が含まれてない場合失敗する() = runTest {
|
||||
val from = TestActorFactory.create()
|
||||
val to = TestActorFactory.create(alsoKnownAs = setOf(ActorId(100)))
|
||||
|
||||
val localActorMigrationCheckDomainServiceImpl = LocalActorMigrationCheckDomainServiceImpl()
|
||||
|
||||
val canAccountMigration = localActorMigrationCheckDomainServiceImpl.canAccountMigration(from, to)
|
||||
|
||||
assertInstanceOf(AccountMigrationCheck.AlsoKnownAsNotFound::class.java, canAccountMigration)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun 正常に設定されている場合は成功する() = runTest {
|
||||
val from = TestActorFactory.create()
|
||||
val to = TestActorFactory.create(alsoKnownAs = setOf(from.id, ActorId(100)))
|
||||
|
||||
val localActorMigrationCheckDomainServiceImpl = LocalActorMigrationCheckDomainServiceImpl()
|
||||
|
||||
val canAccountMigration = localActorMigrationCheckDomainServiceImpl.canAccountMigration(from, to)
|
||||
|
||||
assertInstanceOf(AccountMigrationCheck.CanAccountMigration::class.java, canAccountMigration)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue