test: LocalActorMigrationCheckDomainServiceImplのテストを追加

This commit is contained in:
usbharu 2024-06-19 10:55:49 +09:00
parent 19ee832a6f
commit 1de6aff598
2 changed files with 72 additions and 1 deletions

View File

@ -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}")
}

View File

@ -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)
}
}