From 58077d13f69efd093b86fbded59d392297dd5860 Mon Sep 17 00:00:00 2001 From: usbharu Date: Wed, 29 May 2024 12:31:51 +0900 Subject: [PATCH] wip --- .../hideout/core/domain/model/actor/Actor2.kt | 4 +-- .../core/domain/model/actor/Actor2Test.kt | 18 ++++++++++- .../domain/model/actor/TestActor2Factory.kt | 2 +- .../RemoteActorCheckDomainServiceTest.kt | 31 +++++++++++++++++-- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor2.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor2.kt index db95bacc..08cf77c6 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor2.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor2.kt @@ -47,7 +47,7 @@ class Actor2 private constructor( var lastPostDate: Instant? = null, suspend: Boolean, var lastUpdate: Instant = createdAt, - alsoKnownAs: List = emptyList(), + alsoKnownAs: Set = emptySet(), moveTo: ActorId? = null, ) : DomainEventStorable() { @@ -64,7 +64,7 @@ class Actor2 private constructor( var alsoKnownAs = alsoKnownAs set(value) { require(value.find { it == id } == null) - field = value.distinct() + field = value } var moveTo = moveTo diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor2Test.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor2Test.kt index bf053cfa..00272d61 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor2Test.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor2Test.kt @@ -1,10 +1,26 @@ package dev.usbharu.hideout.core.domain.model.actor import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows class Actor2Test { @Test fun alsoKnownAsに自分自身が含まれてはいけない() { - TestActor2Factory.create() + val actor = TestActor2Factory.create(publicKey = ActorPublicKey("")) + + assertThrows { + actor.alsoKnownAs = setOf(actor.id) + } } + + @Test + fun moveToに自分自身が設定されてはいけない() { + val actor = TestActor2Factory.create(publicKey = ActorPublicKey("")) + + assertThrows { + actor.moveTo = actor.id + } + } + + } \ No newline at end of file diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/TestActor2Factory.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/TestActor2Factory.kt index 6ff26446..7a30bdc6 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/TestActor2Factory.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/TestActor2Factory.kt @@ -20,7 +20,7 @@ object TestActor2Factory : Actor2.Actor2Factory() { outbox: URI = URI.create("https://example.com/$id/outbox"), uri: URI = URI.create("https://example.com/$id"), publicKey: ActorPublicKey, - privateKey: ActorPrivateKey?, + privateKey: ActorPrivateKey? = null, createdAt: Instant = Instant.now(), keyId: String = "https://example.com/$id#key-id", followersEndpoint: URI = URI.create("https://example.com/$id/followers"), diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/service/actor/RemoteActorCheckDomainServiceTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/service/actor/RemoteActorCheckDomainServiceTest.kt index 8cd71362..7903a999 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/service/actor/RemoteActorCheckDomainServiceTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/service/actor/RemoteActorCheckDomainServiceTest.kt @@ -1,14 +1,41 @@ package dev.usbharu.hideout.core.domain.service.actor import dev.usbharu.hideout.application.config.ApplicationConfig +import dev.usbharu.hideout.core.domain.model.actor.ActorPublicKey +import dev.usbharu.hideout.core.domain.model.actor.TestActor2Factory import org.junit.jupiter.api.Test import java.net.URI +import kotlin.test.assertFalse +import kotlin.test.assertTrue class RemoteActorCheckDomainServiceTest { @Test fun リモートのドメインならtrueを返す() { - val actor = + val actor = TestActor2Factory.create(publicKey = ActorPublicKey("")) - RemoteActorCheckDomainService(ApplicationConfig(URI.create("https://example.com").toURL())).isRemoteActor() + val remoteActor = RemoteActorCheckDomainService( + ApplicationConfig( + URI.create("https://local.example.com").toURL() + ) + ).isRemoteActor( + actor + ) + + assertTrue(remoteActor) + } + + @Test + fun ローカルのActorならfalseを返す() { + val actor = TestActor2Factory.create(domain = "local.example.com", publicKey = ActorPublicKey("")) + + val localActor = RemoteActorCheckDomainService( + ApplicationConfig( + URI.create("https://local.example.com").toURL() + ) + ).isRemoteActor( + actor + ) + + assertFalse(localActor) } } \ No newline at end of file