test: ExposedActorRepositoryのテストを追加

This commit is contained in:
usbharu 2024-09-11 15:55:42 +09:00
parent 575763c605
commit 57430b7e4a
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
10 changed files with 675 additions and 30 deletions

View File

@ -56,7 +56,7 @@ class MigrationLocalActorApplicationService(
val canAccountMigration = val canAccountMigration =
localActorMigrationCheckDomainService.canAccountMigration(userDetail, fromActor, toActor) localActorMigrationCheckDomainService.canAccountMigration(userDetail, fromActor, toActor)
if (canAccountMigration.canMigration) { if (canAccountMigration.canMigration) {
fromActor.moveTo = toActorId fromActor.setMoveTo(toActorId)
actorRepository.save(fromActor) actorRepository.save(fromActor)
} else { } else {
when (canAccountMigration) { when (canAccountMigration) {

View File

@ -85,31 +85,40 @@ class Actor(
} }
var alsoKnownAs = alsoKnownAs var alsoKnownAs = alsoKnownAs
set(value) { private set
require(value.none { it == id })
field = value fun setAlsoKnownAs(alsoKnownAs: Set<ActorId>) {
} require(alsoKnownAs.none { it == id })
this.alsoKnownAs = alsoKnownAs
}
var moveTo = moveTo var moveTo = moveTo
set(value) { private set
require(value != id)
addDomainEvent(ActorDomainEventFactory(this).createEvent(MOVE)) fun setMoveTo(moveTo: ActorId?) {
field = value require(moveTo != id)
} addDomainEvent(ActorDomainEventFactory(this).createEvent(MOVE))
this.moveTo = moveTo
}
var emojis = emojiIds var emojis = emojiIds
private set private set
var description = description var description = description
set(value) { private set
addDomainEvent(ActorDomainEventFactory(this).createEvent(UPDATE))
field = value fun setDescription(description: ActorDescription) {
} addDomainEvent(ActorDomainEventFactory(this).createEvent(UPDATE))
this.description = description
}
var screenName = screenName var screenName = screenName
set(value) { private set
addDomainEvent(ActorDomainEventFactory(this).createEvent(UPDATE))
field = value fun setScreenName(screenName: ActorScreenName) {
} addDomainEvent(ActorDomainEventFactory(this).createEvent(UPDATE))
this.screenName = screenName
}
var deleted = deleted var deleted = deleted
private set private set
@ -135,4 +144,52 @@ class Actor(
fun checkUpdate() { fun checkUpdate() {
addDomainEvent(ActorDomainEventFactory(this).createEvent(CHECK_UPDATE)) addDomainEvent(ActorDomainEventFactory(this).createEvent(CHECK_UPDATE))
} }
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as Actor
return id == other.id
}
override fun hashCode(): Int {
return id.hashCode()
}
override fun toString(): String {
return "Actor(" +
"id=$id, " +
"name=$name, " +
"domain=$domain, " +
"inbox=$inbox, " +
"outbox=$outbox, " +
"url=$url, " +
"publicKey=$publicKey, " +
"privateKey=$privateKey, " +
"createdAt=$createdAt, " +
"keyId=$keyId, " +
"followersEndpoint=$followersEndpoint, " +
"followingEndpoint=$followingEndpoint, " +
"instance=$instance, " +
"locked=$locked, " +
"followersCount=$followersCount, " +
"followingCount=$followingCount, " +
"postsCount=$postsCount, " +
"lastPostAt=$lastPostAt, " +
"lastUpdateAt=$lastUpdateAt, " +
"banner=$banner, " +
"icon=$icon, " +
"suspend=$suspend, " +
"alsoKnownAs=$alsoKnownAs, " +
"moveTo=$moveTo, " +
"emojis=$emojis, " +
"description=$description, " +
"screenName=$screenName, " +
"deleted=$deleted" +
")"
}
} }

View File

@ -19,6 +19,19 @@ package dev.usbharu.hideout.core.domain.model.actor
class ActorDescription(description: String) { class ActorDescription(description: String) {
val description: String = description.take(LENGTH) val description: String = description.take(LENGTH)
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as ActorDescription
return description == other.description
}
override fun hashCode(): Int {
return description.hashCode()
}
companion object { companion object {
const val LENGTH = 10000 const val LENGTH = 10000
val empty = ActorDescription("") val empty = ActorDescription("")

View File

@ -20,6 +20,19 @@ class ActorScreenName(screenName: String) {
val screenName: String = screenName.take(LENGTH) val screenName: String = screenName.take(LENGTH)
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as ActorScreenName
return screenName == other.screenName
}
override fun hashCode(): Int {
return screenName.hashCode()
}
companion object { companion object {
const val LENGTH = 300 const val LENGTH = 300
val empty = ActorScreenName("") val empty = ActorScreenName("")

View File

@ -35,7 +35,7 @@ class ActorQueryMapper(private val actorResultRowMapper: ResultRowMapper<Actor>)
.first() .first()
.let(actorResultRowMapper::map) .let(actorResultRowMapper::map)
.apply { .apply {
alsoKnownAs = buildAlsoKnownAs(it) setAlsoKnownAs(buildAlsoKnownAs(it))
clearDomainEvents() clearDomainEvents()
} }
} }

View File

@ -69,8 +69,8 @@ class ExposedActorRepository(
override suspend fun delete(actor: Actor) { override suspend fun delete(actor: Actor) {
query { query {
Actors.deleteWhere { id eq actor.id.id }
ActorsAlsoKnownAs.deleteWhere { actorId eq actor.id.id } ActorsAlsoKnownAs.deleteWhere { actorId eq actor.id.id }
Actors.deleteWhere { id eq actor.id.id }
onComplete { onComplete {
update(actor) update(actor)
} }

View File

@ -34,7 +34,7 @@ class ActorsTest {
val actor = TestActorFactory.create(publicKey = ActorPublicKey("")) val actor = TestActorFactory.create(publicKey = ActorPublicKey(""))
val actorIds = setOf(ActorId(100), ActorId(200)) val actorIds = setOf(ActorId(100), ActorId(200))
actor.alsoKnownAs = actorIds actor.setAlsoKnownAs(actorIds)
assertEquals(actorIds, actor.alsoKnownAs) assertEquals(actorIds, actor.alsoKnownAs)
} }
@ -44,7 +44,7 @@ class ActorsTest {
val actor = TestActorFactory.create(publicKey = ActorPublicKey("")) val actor = TestActorFactory.create(publicKey = ActorPublicKey(""))
actor.moveTo = ActorId(100) actor.setMoveTo(ActorId(100))
assertContainsEvent(actor, ActorEvent.MOVE.eventName) assertContainsEvent(actor, ActorEvent.MOVE.eventName)
} }
@ -54,7 +54,7 @@ class ActorsTest {
val actor = TestActorFactory.create(publicKey = ActorPublicKey("")) val actor = TestActorFactory.create(publicKey = ActorPublicKey(""))
assertThrows<IllegalArgumentException> { assertThrows<IllegalArgumentException> {
actor.alsoKnownAs = setOf(actor.id) actor.setAlsoKnownAs(setOf(actor.id))
} }
} }
@ -63,7 +63,7 @@ class ActorsTest {
val actor = TestActorFactory.create(publicKey = ActorPublicKey("")) val actor = TestActorFactory.create(publicKey = ActorPublicKey(""))
assertThrows<IllegalArgumentException> { assertThrows<IllegalArgumentException> {
actor.moveTo = actor.id actor.setMoveTo(actor.id)
} }
} }
@ -71,7 +71,7 @@ class ActorsTest {
fun descriptionが更新されたときupdateイベントが発生する() { fun descriptionが更新されたときupdateイベントが発生する() {
val actor = TestActorFactory.create(publicKey = ActorPublicKey("")) val actor = TestActorFactory.create(publicKey = ActorPublicKey(""))
actor.description = ActorDescription("hoge fuga") actor.setDescription(ActorDescription("hoge fuga"))
assertContainsEvent(actor, ActorEvent.UPDATE.eventName) assertContainsEvent(actor, ActorEvent.UPDATE.eventName)
} }
@ -80,7 +80,7 @@ class ActorsTest {
fun screenNameが更新されたときupdateイベントが発生する() { fun screenNameが更新されたときupdateイベントが発生する() {
val actor = TestActorFactory.create(publicKey = ActorPublicKey("")) val actor = TestActorFactory.create(publicKey = ActorPublicKey(""))
actor.screenName = ActorScreenName("fuga hoge") actor.setScreenName(ActorScreenName("fuga hoge"))
assertContainsEvent(actor, ActorEvent.UPDATE.eventName) assertContainsEvent(actor, ActorEvent.UPDATE.eventName)
} }

View File

@ -2,6 +2,7 @@ package dev.usbharu.hideout.core.domain.model.actor
import dev.usbharu.hideout.core.domain.model.emoji.CustomEmojiId import dev.usbharu.hideout.core.domain.model.emoji.CustomEmojiId
import dev.usbharu.hideout.core.domain.model.instance.InstanceId import dev.usbharu.hideout.core.domain.model.instance.InstanceId
import dev.usbharu.hideout.core.domain.model.media.MediaId
import dev.usbharu.hideout.core.domain.model.support.domain.Domain import dev.usbharu.hideout.core.domain.model.support.domain.Domain
import dev.usbharu.hideout.core.infrastructure.other.TwitterSnowflakeIdGenerateService import dev.usbharu.hideout.core.infrastructure.other.TwitterSnowflakeIdGenerateService
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
@ -32,12 +33,14 @@ object TestActorFactory {
followingCount: Int = 0, followingCount: Int = 0,
postCount: Int = 0, postCount: Int = 0,
lastPostDate: Instant? = null, lastPostDate: Instant? = null,
lastUpdateAt: Instant = createdAt,
suspend: Boolean = false, suspend: Boolean = false,
alsoKnownAs: Set<ActorId> = emptySet(), alsoKnownAs: Set<ActorId> = emptySet(),
moveTo: Long? = null, moveTo: Long? = null,
emojiIds: Set<CustomEmojiId> = emptySet(), emojiIds: Set<CustomEmojiId> = emptySet(),
deleted: Boolean = false, deleted: Boolean = false,
roles: Set<Role> = emptySet(), icon: Long? = null,
banner: Long? = null,
): Actor { ): Actor {
return runBlocking { return runBlocking {
Actor( Actor(
@ -61,13 +64,14 @@ object TestActorFactory {
followingCount = ActorRelationshipCount(followingCount), followingCount = ActorRelationshipCount(followingCount),
postsCount = ActorPostsCount(postCount), postsCount = ActorPostsCount(postCount),
lastPostAt = lastPostDate, lastPostAt = lastPostDate,
lastUpdateAt = lastUpdateAt,
suspend = suspend, suspend = suspend,
alsoKnownAs = alsoKnownAs, alsoKnownAs = alsoKnownAs,
moveTo = moveTo?.let { ActorId(it) }, moveTo = moveTo?.let { ActorId(it) },
emojiIds = emojiIds, emojiIds = emojiIds,
deleted = deleted, deleted = deleted,
icon = null, icon = icon?.let { MediaId(it) },
banner = null, banner = banner?.let { MediaId(it) },
) )
} }

View File

@ -0,0 +1,558 @@
package dev.usbharu.hideout.core.infrastructure.exposedrepository
import com.ninja_squad.dbsetup_kotlin.dbSetup
import dev.usbharu.hideout.core.domain.model.actor.*
import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventPublisher
import dev.usbharu.hideout.core.infrastructure.exposed.ActorQueryMapper
import dev.usbharu.hideout.core.infrastructure.exposed.ActorResultRowMapper
import kotlinx.coroutines.test.runTest
import org.assertj.core.api.Assertions.assertThat
import org.assertj.db.api.Assertions.assertThat
import org.assertj.db.type.Changes
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.Spy
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.kotlin.any
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
import utils.*
import java.net.URI
import java.sql.Timestamp
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
@ExtendWith(MockitoExtension::class)
class ExposedActorRepositoryTest : AbstractRepositoryTest(Actors) {
@InjectMocks
lateinit var repository: ExposedActorRepository
@Mock
lateinit var domainEventPublisher: DomainEventPublisher
@Spy
val actorQueryMapper = ActorQueryMapper(ActorResultRowMapper())
@Test
fun save_idが同じレコードがない場合はinsert() = runTest {
dbSetup(to = dataSource) {
execute(disableReferenceIntegrityConstraints)
insertInto(Instance.tableName) {
columns(Instance.columns)
values(
1,
"system",
"",
"https://example.com",
"",
null,
"",
"",
false,
false,
"",
"2024-09-10 16:59:50.160202"
)
}
execute(enableReferenceIntegrityConstraints)
}.launch()
val actor = TestActorFactory.create()
repository.save(actor)
assertThat(assertTable)
.row(1)
.isEqualTo(Actors.id, actor.id.id)
.isEqualTo(Actors.name, actor.name.name)
.isEqualTo(Actors.domain, actor.domain.domain)
.isEqualTo(Actors.screenName, actor.screenName.screenName)
.isEqualTo(Actors.description, actor.description.description)
.value(Actors.url).isEqualTo(actor.url.toString())
.value(Actors.inbox).isEqualTo(actor.inbox.toString())
.value(Actors.outbox).isEqualTo(actor.outbox.toString())
.isEqualTo(Actors.publicKey, actor.publicKey.publicKey)
.isEqualTo(Actors.privateKey, actor.privateKey?.privateKey)
}
@Test
fun save_idが同じレコードがある場合はupdate() = runTest {
dbSetup(to = dataSource) {
execute(disableReferenceIntegrityConstraints)
insertInto(Instance.tableName) {
columns(Instance.columns)
values(
1,
"system",
"",
"https://example.com",
"",
null,
"",
"",
false,
false,
"",
"2024-09-10 16:59:50.160202"
)
}
insertInto("public.actors") {
columns(Actors.columns)
values(
1,
"b",
"test-hideout-dev.usbharu.dev",
"b",
"",
"https://test-hideout-dev.usbharu.dev/users/b/inbox",
"https://test-hideout-dev.usbharu.dev/users/b/outbox",
"https://test-hideout-dev.usbharu.dev/users/b",
"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyuMjzmQBsSxzK6NkOpZh\nWuohaUbzCY7AafXt+3+tiL6LulYNg/YRIqKc7Q/vTJE6CHrqo7RA/OqYrSMxF/LC\nf8aX5aHwJE1A2gSgCcs1IL5GJaYRlp4NcuazpBC9NO4xIrvH//jcVnZGXGWsCbls\nHXZGZdurWOF0Bl3mYN8CdupVumrGuOPs+wbI/Gh+OHw611TcXMyAwFwU2UjvPEgk\nEACW9OvJaq1K40jVCAa3b1nXt53vlXXZEUlL78L0C9xuFbJG0K/GKMBN44GyftJO\nhA95Rf1Nhd0vKDLBiRocGcARmBo9PaSCR5651gJEk5/wfLUnNAf0xj3R8LBoOhnT\nCQIDAQAB\n-----END PUBLIC KEY-----",
"-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDK4yPOZAGxLHMr\no2Q6lmFa6iFpRvMJjsBp9e37f62Ivou6Vg2D9hEiopztD+9MkToIeuqjtED86pit\nIzEX8sJ/xpflofAkTUDaBKAJyzUgvkYlphGWng1y5rOkEL007jEiu8f/+NxWdkZc\nZawJuWwddkZl26tY4XQGXeZg3wJ26lW6asa44+z7Bsj8aH44fDrXVNxczIDAXBTZ\nSO88SCQQAJb068lqrUrjSNUIBrdvWde3ne+VddkRSUvvwvQL3G4VskbQr8YowE3j\ngbJ+0k6ED3lF/U2F3S8oMsGJGhwZwBGYGj09pIJHnrnWAkSTn/B8tSc0B/TGPdHw\nsGg6GdMJAgMBAAECggEAHkEhLEb70kdOGgJLUR9D/5zYBE0eXdz/MsMyd1AH+Shs\n9AmetKsYzWDmuhp9Cp5swyn328Hmn7B+DvInVn+5YvjNhY07SbaJcVls4g5UQFXk\nu6WC4ZfKap7IyAeaUg54858r8677xcWXuByN5dn+1iU2hJGYK3Cx7r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IOA\nZPFif8bVfcZqeimxrFaV6YI=\n-----END PRIVATE KEY-----",
"2024-09-09 17:12:03.941339",
"https://test-hideout-dev.usbharu.dev/users/b#main-key",
"https://test-hideout-dev.usbharu.dev/users/b/following",
"https://test-hideout-dev.usbharu.dev/users/b/followers",
1,
false,
0,
0,
0,
null,
"2024-09-09 17:12:03.941339",
false,
null,
"",
false,
null,
null
)
}
insertInto(ActorsAlsoKnownAs.tableName) {
columns(ActorsAlsoKnownAs.columns)
values(1, 2)
}
execute(enableReferenceIntegrityConstraints)
}.launch()
val actor = TestActorFactory.create(1, alsoKnownAs = setOf(ActorId(1)))
repository.save(actor)
assertThat(assertTable)
.row(1)
.isEqualTo(Actors.id, actor.id.id)
.isEqualTo(Actors.name, actor.name.name)
.isEqualTo(Actors.domain, actor.domain.domain)
.isEqualTo(Actors.screenName, actor.screenName.screenName)
.isEqualTo(Actors.description, actor.description.description)
.value(Actors.url).isEqualTo(actor.url.toString())
.value(Actors.inbox).isEqualTo(actor.inbox.toString())
.value(Actors.outbox).isEqualTo(actor.outbox.toString())
.isEqualTo(Actors.publicKey, actor.publicKey.publicKey)
.isEqualTo(Actors.privateKey, actor.privateKey?.privateKey)
assertThat(getTable(ActorsAlsoKnownAs.tableName))
.row(0)
.isEqualTo(ActorsAlsoKnownAs.actorId, 1)
.isEqualTo(ActorsAlsoKnownAs.alsoKnownAs, 1)
}
@Test
fun delete_削除される() = runTest {
dbSetup(to = dataSource) {
execute(disableReferenceIntegrityConstraints)
insertInto("public.actors") {
columns(Actors.columns)
values(
1,
"b",
"test-hideout-dev.usbharu.dev",
"b",
"",
"https://test-hideout-dev.usbharu.dev/users/b/inbox",
"https://test-hideout-dev.usbharu.dev/users/b/outbox",
"https://test-hideout-dev.usbharu.dev/users/b",
"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyuMjzmQBsSxzK6NkOpZh\nWuohaUbzCY7AafXt+3+tiL6LulYN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fpkt2pnixuwg96LaVr4OpVxujhNlwKBgQD1827VuKFGrneNO+c+\n4EIvh+vLh462bJiaVsMHfRhNZF1/5i8gfNJ16ST60hJo11E4riHPzi3q6GWuxOYl\nCkVKvhJ2g3mgnhoehcgnT7UBkasaC7JYd+LsFDnWOTVSJOy2OqfLdLDGAuSTN3kO\nBF4p0ZqQ/AouFNin57WNRGVZ7wKBgQDTLUZtfTkOU3G1nIMTRKmZjqdER5glzHCm\n9o/1ZsQktL+nzSXqYeoWh9fr7fkmC0k/07+SHzzfWvOhWWWlRenUVL5mj7FRq+L9\n9kDjChLR3Jr4L6Sj1iaQ+0uqDSQNYSYO9ctMjAVjFiNhiAd+S6B451Q1VbDKTCHt\nkRW9omz6hwKBgBFTsgY6eJorJl77zmG+mMsSb0kqZqJxahrNa/X2GSUyoeelxsIq\nKQWHhERrUkKykJVGpzkllFSNRMSYOIJ5g8ItO82/m2z2Vm66DAzA78aJhZ1TH6Bd\n6c2p6x0tcJU15rs7zKBnuyBoCcRZTxzur9eQXaxDJVBzxYOmrkKig+VfAoGBAMCP\n2Fiehxh5HobsYNmBEuXjHsM0RZiyA0c8LakoPFL8PodUme5PupUw6cNJDJeUUwbQ\nny8vLOK+nMnUKsu6JK5pV/VNsfM3OZU6p5Bf7ylOcEE/sHF1JVWu0CAQO3+3xmx9\n1RPH2mGwHjMhRzPy4jFdP3wi10KgiY+HbLuvEJChAoGAYCsh3UhtTzGUOlPBkmLL\n17bD0wN4J/fOv8BoXPZ8H2CdqVgWy0s+s+QaPqRxNcA6YyGymBqrmQAn1Uii25r9\nKAwVAjg3S2KDEMSI2RbMMmQJSZ1u0GkxqOUC/MMeZqBYTYxVeqcQPoqJZ0Nk7IOA\nZPFif8bVfcZqeimxrFaV6YI=\n-----END PRIVATE KEY-----",
"2024-09-09 17:12:03.941339",
"https://test-hideout-dev.usbharu.dev/users/b#main-key",
"https://test-hideout-dev.usbharu.dev/users/b/following",
"https://test-hideout-dev.usbharu.dev/users/b/followers",
1,
false,
0,
0,
0,
null,
"2024-09-09 17:12:03.941339",
false,
null,
"",
false,
null,
null
)
}
insertInto(ActorsAlsoKnownAs.tableName) {
columns(ActorsAlsoKnownAs.columns)
values(1, 1)
}
}.launch()
val actor = TestActorFactory.create(1, alsoKnownAs = setOf(ActorId(1)))
val changes = Changes(dataSource)
changes.withSuspend {
repository.delete(actor)
}
assertThat(changes)
.changeOfDeletionOnTable(Actors.tableName)
.rowAtStartPoint()
.value(Actors.id.name).isEqualTo(actor.id.id)
.changeOfDeletionOnTable(ActorsAlsoKnownAs.tableName)
.rowAtStartPoint()
.value(ActorsAlsoKnownAs.alsoKnownAs.name)
.isEqualTo(actor.alsoKnownAs.first().id)
}
@Test
fun findById_指定されたIdがあれば返す() = runTest {
dbSetup(to = dataSource) {
execute(disableReferenceIntegrityConstraints)
insertInto("public.actors") {
columns(Actors.columns)
values(
1,
"b",
"test-hideout-dev.usbharu.dev",
"b",
"",
"https://test-hideout-dev.usbharu.dev/users/b/inbox",
"https://test-hideout-dev.usbharu.dev/users/b/outbox",
"https://test-hideout-dev.usbharu.dev/users/b",
"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyuMjzmQBsSxzK6NkOpZh\nWuohaUbzCY7AafXt+3+tiL6LulYNg/YRIqKc7Q/vTJE6CHrqo7RA/OqYrSMxF/LC\nf8aX5aHwJE1A2gSgCcs1IL5GJaYRlp4NcuazpBC9NO4xIrvH//jcVnZGXGWsCbls\nHXZGZdurWOF0Bl3mYN8CdupVumrGuOPs+wbI/Gh+OHw611TcXMyAwFwU2UjvPEgk\nEACW9OvJaq1K40jVCAa3b1nXt53vlXXZEUlL78L0C9xuFbJG0K/GKMBN44GyftJO\nhA95Rf1Nhd0vKDLBiRocGcARmBo9PaSCR5651gJEk5/wfLUnNAf0xj3R8LBoOhnT\nCQIDAQAB\n-----END PUBLIC KEY-----",
"-----BEGIN PRIVATE KEY-----\nMIIEvQIBAD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iNhiAd+S6B451Q1VbDKTCHt\nkRW9omz6hwKBgBFTsgY6eJorJl77zmG+mMsSb0kqZqJxahrNa/X2GSUyoeelxsIq\nKQWHhERrUkKykJVGpzkllFSNRMSYOIJ5g8ItO82/m2z2Vm66DAzA78aJhZ1TH6Bd\n6c2p6x0tcJU15rs7zKBnuyBoCcRZTxzur9eQXaxDJVBzxYOmrkKig+VfAoGBAMCP\n2Fiehxh5HobsYNmBEuXjHsM0RZiyA0c8LakoPFL8PodUme5PupUw6cNJDJeUUwbQ\nny8vLOK+nMnUKsu6JK5pV/VNsfM3OZU6p5Bf7ylOcEE/sHF1JVWu0CAQO3+3xmx9\n1RPH2mGwHjMhRzPy4jFdP3wi10KgiY+HbLuvEJChAoGAYCsh3UhtTzGUOlPBkmLL\n17bD0wN4J/fOv8BoXPZ8H2CdqVgWy0s+s+QaPqRxNcA6YyGymBqrmQAn1Uii25r9\nKAwVAjg3S2KDEMSI2RbMMmQJSZ1u0GkxqOUC/MMeZqBYTYxVeqcQPoqJZ0Nk7IOA\nZPFif8bVfcZqeimxrFaV6YI=\n-----END PRIVATE KEY-----",
"2024-09-09 17:12:03.941339",
"https://test-hideout-dev.usbharu.dev/users/b#main-key",
"https://test-hideout-dev.usbharu.dev/users/b/following",
"https://test-hideout-dev.usbharu.dev/users/b/followers",
1,
false,
0,
0,
0,
null,
"2024-09-09 17:12:03.941339",
false,
null,
"",
false,
null,
null
)
}
}.launch()
val expect = TestActorFactory.create(
id = 1,
actorName = "b",
domain = "test-hideout-dev.usbharu.dev",
actorScreenName = "b",
description = "",
inbox = URI.create("https://test-hideout-dev.usbharu.dev/users/b/inbox"),
outbox = URI.create("https://test-hideout-dev.usbharu.dev/users/b/outbox"),
uri = URI.create("https://test-hideout-dev.usbharu.dev/users/b"),
publicKey = ActorPublicKey("-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyuMjzmQBsSxzK6NkOpZh\nWuohaUb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I2izeAfoGs1OsCSpuPy6s\nV5f0X3HYM7CA+Fpkt2pnixuwg96LaVr4OpVxujhNlwKBgQD1827VuKFGrneNO+c+\n4EIvh+vLh462bJiaVsMHfRhNZF1/5i8gfNJ16ST60hJo11E4riHPzi3q6GWuxOYl\nCkVKvhJ2g3mgnhoehcgnT7UBkasaC7JYd+LsFDnWOTVSJOy2OqfLdLDGAuSTN3kO\nBF4p0ZqQ/AouFNin57WNRGVZ7wKBgQDTLUZtfTkOU3G1nIMTRKmZjqdER5glzHCm\n9o/1ZsQktL+nzSXqYeoWh9fr7fkmC0k/07+SHzzfWvOhWWWlRenUVL5mj7FRq+L9\n9kDjChLR3Jr4L6Sj1iaQ+0uqDSQNYSYO9ctMjAVjFiNhiAd+S6B451Q1VbDKTCHt\nkRW9omz6hwKBgBFTsgY6eJorJl77zmG+mMsSb0kqZqJxahrNa/X2GSUyoeelxsIq\nKQWHhERrUkKykJVGpzkllFSNRMSYOIJ5g8ItO82/m2z2Vm66DAzA78aJhZ1TH6Bd\n6c2p6x0tcJU15rs7zKBnuyBoCcRZTxzur9eQXaxDJVBzxYOmrkKig+VfAoGBAMCP\n2Fiehxh5HobsYNmBEuXjHsM0RZiyA0c8LakoPFL8PodUme5PupUw6cNJDJeUUwbQ\nny8vLOK+nMnUKsu6JK5pV/VNsfM3OZU6p5Bf7ylOcEE/sHF1JVWu0CAQO3+3xmx9\n1RPH2mGwHjMhRzPy4jFdP3wi10KgiY+HbLuvEJChAoGAYCsh3UhtTzGUOlPBkmLL\n17bD0wN4J/fOv8BoXPZ8H2CdqVgWy0s+s+QaPqRxNcA6YyGymBqrmQAn1Uii25r9\nKAwVAjg3S2KDEMSI2RbMMmQJSZ1u0GkxqOUC/MMeZqBYTYxVeqcQPoqJZ0Nk7IOA\nZPFif8bVfcZqeimxrFaV6YI=\n-----END PRIVATE KEY-----",
),
createdAt = Timestamp.valueOf("2024-09-09 17:12:03.941339").toInstant(),
keyId = "https://test-hideout-dev.usbharu.dev/users/b#main-key",
followingEndpoint = URI.create("https://test-hideout-dev.usbharu.dev/users/b/following"),
followersEndpoint = URI.create("https://test-hideout-dev.usbharu.dev/users/b/followers"),
instanceId = 1,
locked = false,
followersCount = 0,
followingCount = 0,
postCount = 0,
lastPostDate = null,
lastUpdateAt = Timestamp.valueOf("2024-09-09 17:12:03.941339").toInstant(),
suspend = false,
alsoKnownAs = emptySet(),
moveTo = null,
emojiIds = emptySet(),
deleted = false,
banner = null,
icon = null
)
val actual = repository.findById(ActorId(1))
assertEquals(actual, expect)
}
private fun assertEquals(
actual: Actor?,
expect: Actor
) {
assertNotNull(actual)
kotlin.test.assertEquals(expect, actual)
assertEquals(expect.id, actual.id)
assertEquals(expect.name, actual.name)
assertEquals(expect.domain, actual.domain)
assertEquals(expect.screenName, actual.screenName)
assertEquals(expect.description, actual.description)
assertEquals(expect.inbox, actual.inbox)
assertEquals(expect.outbox, actual.outbox)
assertEquals(expect.url, actual.url)
assertEquals(expect.publicKey, actual.publicKey)
assertEquals(expect.privateKey, actual.privateKey)
assertEquals(expect.createdAt, actual.createdAt)
assertEquals(expect.keyId, actual.keyId)
assertEquals(expect.followingEndpoint, actual.followingEndpoint)
assertEquals(expect.followersEndpoint, actual.followersEndpoint)
assertEquals(expect.postsCount, actual.postsCount)
assertEquals(expect.lastPostAt, actual.lastPostAt)
assertEquals(expect.lastUpdateAt, actual.lastUpdateAt)
assertEquals(expect.suspend, actual.suspend)
assertEquals(expect.moveTo, actual.moveTo)
assertEquals(expect.emojis, actual.emojis)
assertEquals(expect.deleted, actual.deleted)
assertEquals(expect.banner, actual.banner)
assertEquals(expect.icon, actual.icon)
assertEquals(expect.banner, actual.banner)
}
@Test
fun findById_指定されたIdがなければnull() = runTest {
assertNull(repository.findById(ActorId(1)))
}
@Test
fun findByNameAndDomain_指定されたNameとDomainがあれば返す() = runTest {
dbSetup(to = dataSource) {
execute(disableReferenceIntegrityConstraints)
insertInto("public.actors") {
columns(Actors.columns)
values(
1,
"b",
"test-hideout-dev.usbharu.dev",
"b",
"",
"https://test-hideout-dev.usbharu.dev/users/b/inbox",
"https://test-hideout-dev.usbharu.dev/users/b/outbox",
"https://test-hideout-dev.usbharu.dev/users/b",
"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyuMjzmQBsSxzK6NkOpZh\nWuohaUbzCY7AafXt+3+tiL6LulYNg/YRIqKc7Q/vTJE6CHrqo7RA/OqYrSMxF/LC\nf8aX5aHwJE1A2gSgCcs1IL5GJaYRlp4NcuazpBC9NO4xIrvH//jcVnZGXGWsCbls\nHXZGZdurWOF0Bl3mYN8CdupVumrGuOPs+wbI/Gh+OHw611TcXMyAwFwU2UjvPEgk\nEACW9OvJaq1K40jVCAa3b1nXt53vlXXZEUlL78L0C9xuFbJG0K/GKMBN44GyftJO\nhA95Rf1Nhd0vKDLBiRocGcARmBo9PaSCR5651gJEk5/wfLUnNAf0xj3R8LBoOhnT\nCQIDAQAB\n-----END PUBLIC KEY-----",
"-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDK4yPOZAGxLHMr\no2Q6lmFa6iFpRvMJjsBp9e37f62Ivou6Vg2D9hEiopztD+9MkToIeuqjtED86pit\nIzEX8sJ/xpflofAkTUDaBKAJyzUgvkYlphGWng1y5rOkEL007jEiu8f/+NxWdkZc\nZawJuWwddkZl26tY4XQGXeZg3wJ26lW6asa44+z7Bsj8aH44fDrXVNxczIDAXBTZ\nSO88SCQQAJb068lqrUrjSNUIBrdvWde3ne+VddkRSUvvwvQL3G4VskbQr8YowE3j\ngbJ+0k6ED3lF/U2F3S8oMsGJGhwZwBGYGj09pIJHnrnWAkSTn/B8tSc0B/TGPdHw\nsGg6GdMJAgMBAAECggEAHkEhLEb70kdOGgJLUR9D/5zYBE0eXdz/MsMyd1AH+Shs\n9AmetKsYzWDmuhp9Cp5swyn328Hmn7B+DvInVn+5YvjNh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r9\nKAwVAjg3S2KDEMSI2RbMMmQJSZ1u0GkxqOUC/MMeZqBYTYxVeqcQPoqJZ0Nk7IOA\nZPFif8bVfcZqeimxrFaV6YI=\n-----END PRIVATE KEY-----",
"2024-09-09 17:12:03.941339",
"https://test-hideout-dev.usbharu.dev/users/b#main-key",
"https://test-hideout-dev.usbharu.dev/users/b/following",
"https://test-hideout-dev.usbharu.dev/users/b/followers",
1,
false,
0,
0,
0,
null,
"2024-09-09 17:12:03.941339",
false,
null,
"",
false,
null,
null
)
}
}.launch()
val expect = TestActorFactory.create(
id = 1,
actorName = "b",
domain = "test-hideout-dev.usbharu.dev",
actorScreenName = "b",
description = "",
inbox = URI.create("https://test-hideout-dev.usbharu.dev/users/b/inbox"),
outbox = URI.create("https://test-hideout-dev.usbharu.dev/users/b/outbox"),
uri = URI.create("https://test-hideout-dev.usbharu.dev/users/b"),
publicKey = ActorPublicKey("-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyuMjzmQBsSxzK6NkOpZh\nWuohaUbzCY7AafXt+3+tiL6LulYNg/YRIqKc7Q/vTJE6CHrqo7RA/OqYrSMxF/LC\nf8aX5aHwJE1A2gSgCcs1IL5GJaYRlp4NcuazpBC9NO4xIrvH//jcVnZGXGWsCbls\nHXZGZdurWOF0Bl3mYN8CdupVumrGuOPs+wbI/Gh+OHw611TcXMyAwFwU2UjvPEgk\nEACW9OvJaq1K40jVCAa3b1nXt53vlXXZEUlL78L0C9xuFbJG0K/GKMBN44GyftJO\nhA95Rf1Nhd0vKDLBiRocGcARmBo9PaSCR5651gJEk5/wfLUnNAf0xj3R8LBoOhnT\nCQIDAQAB\n-----END PUBLIC KEY-----"),
privateKey = ActorPrivateKey(
"-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDK4yPOZAGxLHMr\no2Q6lmFa6iFpRvMJjsBp9e37f62Ivou6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nKQWHhERrUkKykJVGpzkllFSNRMSYOIJ5g8ItO82/m2z2Vm66DAzA78aJhZ1TH6Bd\n6c2p6x0tcJU15rs7zKBnuyBoCcRZTxzur9eQXaxDJVBzxYOmrkKig+VfAoGBAMCP\n2Fiehxh5HobsYNmBEuXjHsM0RZiyA0c8LakoPFL8PodUme5PupUw6cNJDJeUUwbQ\nny8vLOK+nMnUKsu6JK5pV/VNsfM3OZU6p5Bf7ylOcEE/sHF1JVWu0CAQO3+3xmx9\n1RPH2mGwHjMhRzPy4jFdP3wi10KgiY+HbLuvEJChAoGAYCsh3UhtTzGUOlPBkmLL\n17bD0wN4J/fOv8BoXPZ8H2CdqVgWy0s+s+QaPqRxNcA6YyGymBqrmQAn1Uii25r9\nKAwVAjg3S2KDEMSI2RbMMmQJSZ1u0GkxqOUC/MMeZqBYTYxVeqcQPoqJZ0Nk7IOA\nZPFif8bVfcZqeimxrFaV6YI=\n-----END PRIVATE KEY-----",
),
createdAt = Timestamp.valueOf("2024-09-09 17:12:03.941339").toInstant(),
keyId = "https://test-hideout-dev.usbharu.dev/users/b#main-key",
followingEndpoint = URI.create("https://test-hideout-dev.usbharu.dev/users/b/following"),
followersEndpoint = URI.create("https://test-hideout-dev.usbharu.dev/users/b/followers"),
instanceId = 1,
locked = false,
followersCount = 0,
followingCount = 0,
postCount = 0,
lastPostDate = null,
lastUpdateAt = Timestamp.valueOf("2024-09-09 17:12:03.941339").toInstant(),
suspend = false,
alsoKnownAs = emptySet(),
moveTo = null,
emojiIds = emptySet(),
deleted = false,
banner = null,
icon = null
)
val actual = repository.findByNameAndDomain("b", "test-hideout-dev.usbharu.dev")
assertEquals(actual, expect)
}
@Test
fun findByNameAndDomain_指定されたNameとDomainがなければnull() = runTest {
assertNull(repository.findByNameAndDomain("a", "b"))
}
@Test
fun findAllById_指定されたIdすべて返す() = runTest {
dbSetup(to = dataSource) {
execute(disableReferenceIntegrityConstraints)
insertInto("public.actors") {
columns(Actors.columns)
values(
1,
"b",
"test-hideout-dev.usbharu.dev",
"b",
"",
"https://test-hideout-dev.usbharu.dev/users/b/inbox",
"https://test-hideout-dev.usbharu.dev/users/b/outbox",
"https://test-hideout-dev.usbharu.dev/users/b",
"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyuMjzmQBsSxzK6NkOpZh\nWuohaUbzCY7AafXt+3+tiL6LulYNg/YRIqKc7Q/vTJE6CHrqo7RA/OqYrSMxF/LC\nf8aX5aHwJE1A2gSgCcs1IL5GJaYRlp4NcuazpBC9NO4xIrvH//jcVnZGXGWsCbls\nHXZGZdurWOF0Bl3mYN8CdupVumrGuOPs+wbI/Gh+OHw611TcXMyAwFwU2UjvPEgk\nEACW9OvJaq1K40jVCAa3b1nXt53vlXXZEUlL78L0C9xuFbJG0K/GKMBN44GyftJO\nhA95Rf1Nhd0vKDLBiRocGcARmBo9PaSCR5651gJEk5/wfLUnNAf0xj3R8LBoOhnT\nCQIDAQAB\n-----END PUBLIC KEY-----",
"-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDK4yPOZAGxLHMr\no2Q6lmFa6iFpRvMJjsBp9e37f62Ivou6Vg2D9hEiopztD+9MkToIeuqjtED86pit\nIzEX8sJ/xpflofAkTUDaBKAJyzUgvkYlphGWng1y5rOkEL007jEiu8f/+NxWdkZc\nZawJuWwddkZl26tY4XQGXeZg3wJ26lW6asa44+z7Bsj8aH44fDrXVNxczIDAXBTZ\nSO88SCQQAJb068lqrUrjSNUIBrdvWde3ne+VddkRSUvvwvQL3G4VskbQr8YowE3j\ngbJ+0k6ED3lF/U2F3S8oMsGJGhwZwBGYGj09pIJHnrnWAkSTn/B8tSc0B/TGPdHw\nsGg6GdMJAgMBAAECggEAHkEhLEb70kdOGgJLUR9D/5zYBE0eXdz/MsMyd1AH+Shs\n9AmetKsYzWDmuhp9Cp5swyn328Hmn7B+DvInVn+5Yvj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ii25r9\nKAwVAjg3S2KDEMSI2RbMMmQJSZ1u0GkxqOUC/MMeZqBYTYxVeqcQPoqJZ0Nk7IOA\nZPFif8bVfcZqeimxrFaV6YI=\n-----END PRIVATE KEY-----",
"2024-09-09 17:12:03.941339",
"https://test-hideout-dev.usbharu.dev/users/b#main-key",
"https://test-hideout-dev.usbharu.dev/users/b/following",
"https://test-hideout-dev.usbharu.dev/users/b/followers",
1,
false,
0,
0,
0,
null,
"2024-09-09 17:12:03.941339",
false,
null,
"",
false,
null,
null
)
values(
2,
"a",
"test-hideout-dev.usbharu.dev",
"a",
"",
"https://test-hideout-dev.usbharu.dev/users/a/inbox",
"https://test-hideout-dev.usbharu.dev/users/a/outbox",
"https://test-hideout-dev.usbharu.dev/users/a",
"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyuMjzmQBsSxzK6NkOpZh\nWuohaUbzCY7AafXt+3+tiL6LulYNg/YRIqKc7Q/vTJE6CHrqo7RA/OqYrSMxF/LC\nf8aX5aHwJE1A2gSgCcs1IL5GJaYRlp4NcuazpBC9NO4xIrvH//jcVnZGXGWsCbls\nHXZGZdurWOF0Bl3mYN8CdupVumrGuOPs+wbI/Gh+OHw611TcXMyAwFwU2UjvPEgk\nEACW9OvJaq1K40jVCAa3b1nXt53vlXXZEUlL78L0C9xuFbJG0K/GKMBN44GyftJO\nhA95Rf1Nhd0vKDLBiRocGcARmBo9PaSCR5651gJEk5/wfLUnNAf0xj3R8LBoOhnT\nCQIDAQAB\n-----END PUBLIC KEY-----",
"-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDK4yPOZAGxLHMr\no2Q6lmFa6iFpRvMJjsBp9e37f62Ivou6Vg2D9hEiopztD+9MkToIeuqjtED86pit\nIzEX8sJ/xpflofAkTUDaBKAJyzUgvkYlphGWng1y5rOkEL007jEiu8f/+NxWdkZc\nZawJu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xzur9eQXaxDJVBzxYOmrkKig+VfAoGBAMCP\n2Fiehxh5HobsYNmBEuXjHsM0RZiyA0c8LakoPFL8PodUme5PupUw6cNJDJeUUwbQ\nny8vLOK+nMnUKsu6JK5pV/VNsfM3OZU6p5Bf7ylOcEE/sHF1JVWu0CAQO3+3xmx9\n1RPH2mGwHjMhRzPy4jFdP3wi10KgiY+HbLuvEJChAoGAYCsh3UhtTzGUOlPBkmLL\n17bD0wN4J/fOv8BoXPZ8H2CdqVgWy0s+s+QaPqRxNcA6YyGymBqrmQAn1Uii25r9\nKAwVAjg3S2KDEMSI2RbMMmQJSZ1u0GkxqOUC/MMeZqBYTYxVeqcQPoqJZ0Nk7IOA\nZPFif8bVfcZqeimxrFaV6YI=\n-----END PRIVATE KEY-----",
"2024-09-09 17:12:03.941339",
"https://test-hideout-dev.usbharu.dev/users/a#main-key",
"https://test-hideout-dev.usbharu.dev/users/a/following",
"https://test-hideout-dev.usbharu.dev/users/a/followers",
1,
false,
0,
0,
0,
null,
"2024-09-09 17:12:03.941339",
false,
null,
"",
false,
null,
null
)
}
}.launch()
val findAllById = repository.findAllById(listOf(ActorId(1), ActorId(2)))
assertThat(findAllById)
.hasSize(2)
}
@Test
fun save_ドメインイベントがパブリッシュされる() = runTest {
dbSetup(to = dataSource) {
execute(disableReferenceIntegrityConstraints)
}.launch()
val actor = TestActorFactory.create()
actor.checkUpdate()
repository.save(actor)
TransactionManager.current().commit()
verify(domainEventPublisher, times(1)).publishEvent(any())
}
@Test
fun delete_ドメインイベントがパブリッシュされる() = runTest {
dbSetup(to = dataSource) {
execute(disableReferenceIntegrityConstraints)
insertInto("public.actors") {
columns(Actors.columns)
values(
1,
"b",
"test-hideout-dev.usbharu.dev",
"b",
"",
"https://test-hideout-dev.usbharu.dev/users/b/inbox",
"https://test-hideout-dev.usbharu.dev/users/b/outbox",
"https://test-hideout-dev.usbharu.dev/users/b",
"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAA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/users/b#main-key",
"https://test-hideout-dev.usbharu.dev/users/b/following",
"https://test-hideout-dev.usbharu.dev/users/b/followers",
1,
false,
0,
0,
0,
null,
"2024-09-09 17:12:03.941339",
false,
null,
"",
false,
null,
null
)
}
insertInto(ActorsAlsoKnownAs.tableName) {
columns(ActorsAlsoKnownAs.columns)
values(1, 1)
}
}.launch()
val actor = TestActorFactory.create(1, alsoKnownAs = setOf(ActorId(1)))
actor.delete()
repository.delete(actor)
TransactionManager.current().commit()
verify(domainEventPublisher, times(1)).publishEvent(any())
}
}

View File

@ -59,7 +59,7 @@ class UserDetailsServiceImplTest {
fun userDetailが見つからない場合失敗() = runTest { fun userDetailが見つからない場合失敗() = runTest {
whenever(actorRepository.findByNameAndDomain(eq("test"), eq("example.com"))).doReturn( whenever(actorRepository.findByNameAndDomain(eq("test"), eq("example.com"))).doReturn(
TestActorFactory.create( TestActorFactory.create(
actorName = "test", id = 1 id = 1, actorName = "test"
) )
) )
assertThrows<UsernameNotFoundException> { assertThrows<UsernameNotFoundException> {