From 1de6aff598eaea9704386e93b14757affbe99638 Mon Sep 17 00:00:00 2001 From: usbharu Date: Wed, 19 Jun 2024 10:55:49 +0900 Subject: [PATCH] =?UTF-8?q?test:=20LocalActorMigrationCheckDomainServiceIm?= =?UTF-8?q?pl=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...calActorMigrationCheckDomainServiceImpl.kt | 2 +- ...ctorMigrationCheckDomainServiceImplTest.kt | 71 +++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/service/actor/local/LocalActorMigrationCheckDomainServiceImplTest.kt diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/local/LocalActorMigrationCheckDomainServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/local/LocalActorMigrationCheckDomainServiceImpl.kt index f74bf530..933f7201 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/local/LocalActorMigrationCheckDomainServiceImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/local/LocalActorMigrationCheckDomainServiceImpl.kt @@ -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}") } diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/service/actor/local/LocalActorMigrationCheckDomainServiceImplTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/service/actor/local/LocalActorMigrationCheckDomainServiceImplTest.kt new file mode 100644 index 00000000..7428222c --- /dev/null +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/service/actor/local/LocalActorMigrationCheckDomainServiceImplTest.kt @@ -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) + } +} \ No newline at end of file