This commit is contained in:
usbharu 2024-05-29 12:31:51 +09:00
parent 997e28bdf6
commit 58077d13f6
4 changed files with 49 additions and 6 deletions

View File

@ -47,7 +47,7 @@ class Actor2 private constructor(
var lastPostDate: Instant? = null,
suspend: Boolean,
var lastUpdate: Instant = createdAt,
alsoKnownAs: List<ActorId> = emptyList(),
alsoKnownAs: Set<ActorId> = 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

View File

@ -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<IllegalArgumentException> {
actor.alsoKnownAs = setOf(actor.id)
}
}
@Test
fun moveToに自分自身が設定されてはいけない() {
val actor = TestActor2Factory.create(publicKey = ActorPublicKey(""))
assertThrows<IllegalArgumentException> {
actor.moveTo = actor.id
}
}
}

View File

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

View File

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