From 07cf2c7c9d107f49dc8309d4285a7dbeb0756c8b Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Wed, 26 Apr 2023 17:08:27 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20UserEntity=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/usbharu/hideout/domain/model/Posts.kt | 1 + .../dev/usbharu/hideout/domain/model/User.kt | 66 --------------- .../domain/model/UserAuthentication.kt | 1 + .../hideout/domain/model/UsersFollowers.kt | 1 + .../hideout/repository/IUserRepository.kt | 21 +++-- .../hideout/repository/UserRepository.kt | 84 +++++++++++++------ .../hideout/service/impl/UserAuthService.kt | 1 - .../hideout/service/impl/UserService.kt | 19 ++--- .../hideout/plugins/ActivityPubKtTest.kt | 39 ++++++--- .../usbharu/hideout/plugins/KtorKeyMapTest.kt | 36 +++++--- .../hideout/repository/UserRepositoryTest.kt | 1 - .../ActivityPubFollowServiceImplTest.kt | 15 ++-- .../ActivityPubNoteServiceImplTest.kt | 26 ++++-- 13 files changed, 159 insertions(+), 152 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/Posts.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/Posts.kt index 3a6867db..d9e13915 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/Posts.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/Posts.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.domain.model +import dev.usbharu.hideout.repository.Users import org.jetbrains.exposed.sql.ResultRow import org.jetbrains.exposed.sql.Table diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/User.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/User.kt index 62c8fa47..ee46667a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/User.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/User.kt @@ -1,12 +1,6 @@ package dev.usbharu.hideout.domain.model -import org.h2.mvstore.type.LongDataType -import org.jetbrains.exposed.dao.id.LongIdTable -import org.jetbrains.exposed.sql.ResultRow -import org.jetbrains.exposed.sql.Table -import java.time.Instant import java.time.LocalDateTime -import java.time.ZoneId data class User( val id:Long, @@ -22,63 +16,3 @@ data class User( val privateKey:String? = null, val createdAt:LocalDateTime ) - -data class UserEntity( - val id: Long, - val name: String, - val domain: String, - val screenName: String, - val description: String, - val inbox: String, - val outbox: String, - val url: String -) { - constructor(id: Long, user: User) : this( - id, - user.name, - user.domain, - user.screenName, - user.description, - user.inbox, - user.outbox, - user.url - ) -} - -object Users : Table("users") { - val id = long("id").uniqueIndex() - val name = varchar("name", length = 64) - val domain = varchar("domain", length = 255) - val screenName = varchar("screen_name", length = 64) - val description = varchar("description", length = 600) - val password = varchar("password", length = 255).nullable() - val inbox = varchar("inbox", length = 255).uniqueIndex() - val outbox = varchar("outbox", length = 255).uniqueIndex() - val url = varchar("url", length = 255).uniqueIndex() - val publicKey = varchar("public_key", length = 10000) - val privateKey = varchar("private_key", length = 10000) - val createdAt = long("created_at") - - override val primaryKey: PrimaryKey = PrimaryKey(id) - init { - uniqueIndex(name, domain) - } -} - - -fun ResultRow.toUser(): User { - return User( - this[Users.id], - this[Users.name], - this[Users.domain], - this[Users.screenName], - this[Users.description], - this[Users.password], - this[Users.inbox], - this[Users.outbox], - this[Users.url], - this[Users.publicKey], - this[Users.privateKey], - LocalDateTime.ofInstant(Instant.ofEpochMilli((this[Users.createdAt])), ZoneId.systemDefault()) - ) -} diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/UserAuthentication.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/UserAuthentication.kt index c1f02961..5754021a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/UserAuthentication.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/UserAuthentication.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.domain.model +import dev.usbharu.hideout.repository.Users import org.jetbrains.exposed.dao.id.LongIdTable import org.jetbrains.exposed.sql.ReferenceOption diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/UsersFollowers.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/UsersFollowers.kt index 1f5de8ce..b5078c53 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/UsersFollowers.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/UsersFollowers.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.domain.model +import dev.usbharu.hideout.repository.Users import org.jetbrains.exposed.dao.id.LongIdTable object UsersFollowers : LongIdTable("users_followers") { diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/IUserRepository.kt b/src/main/kotlin/dev/usbharu/hideout/repository/IUserRepository.kt index dd89dbd9..73ac26a4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/IUserRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/IUserRepository.kt @@ -1,32 +1,31 @@ package dev.usbharu.hideout.repository import dev.usbharu.hideout.domain.model.User -import dev.usbharu.hideout.domain.model.UserEntity interface IUserRepository { - suspend fun create(user: User): UserEntity + suspend fun create(user: User): User - suspend fun findById(id: Long): UserEntity? + suspend fun findById(id: Long): User? - suspend fun findByIds(ids: List): List + suspend fun findByIds(ids: List): List - suspend fun findByName(name: String): UserEntity? + suspend fun findByName(name: String): User? - suspend fun findByNameAndDomains(names: List>): List + suspend fun findByNameAndDomains(names: List>): List - suspend fun findByUrl(url:String):UserEntity? + suspend fun findByUrl(url:String): User? - suspend fun findByUrls(urls: List): List + suspend fun findByUrls(urls: List): List - suspend fun update(userEntity: UserEntity) + suspend fun update(userEntity: User) suspend fun delete(id: Long) suspend fun findAll(): List - suspend fun findAllByLimitAndByOffset(limit: Int, offset: Long = 0): List + suspend fun findAllByLimitAndByOffset(limit: Int, offset: Long = 0): List suspend fun createFollower(id: Long, follower: Long) suspend fun deleteFollower(id: Long, follower: Long) - suspend fun findFollowersById(id: Long): List + suspend fun findFollowersById(id: Long): List } diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/UserRepository.kt b/src/main/kotlin/dev/usbharu/hideout/repository/UserRepository.kt index c0382755..051ceff0 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/UserRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/UserRepository.kt @@ -6,6 +6,9 @@ import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction import org.jetbrains.exposed.sql.transactions.transaction +import java.time.Instant +import java.time.LocalDateTime +import java.time.ZoneId class UserRepository(private val database: Database) : IUserRepository { init { @@ -17,25 +20,14 @@ class UserRepository(private val database: Database) : IUserRepository { } } - private fun ResultRow.toUserEntity(): UserEntity { - return UserEntity( - this[Users.id], - this[Users.name], - this[Users.domain], - this[Users.screenName], - this[Users.description], - this[Users.inbox], - this[Users.outbox], - this[Users.url], - ) - } + private fun ResultRow.toUserEntity(): User = toUser() suspend fun query(block: suspend () -> T): T = newSuspendedTransaction(Dispatchers.IO) { block() } - override suspend fun create(user: User): UserEntity { + override suspend fun create(user: User): User { return query { - UserEntity(Users.insert { + Users.insert { it[name] = user.name it[domain] = user.domain it[screenName] = user.screenName @@ -43,7 +35,8 @@ class UserRepository(private val database: Database) : IUserRepository { it[inbox] = user.inbox it[outbox] = user.outbox it[url] = user.url - }[Users.id], user) + } + return@query user } } @@ -56,7 +49,7 @@ class UserRepository(private val database: Database) : IUserRepository { } } - override suspend fun findById(id: Long): UserEntity? { + override suspend fun findById(id: Long): User? { return query { Users.select { Users.id eq id }.map { it.toUserEntity() @@ -64,7 +57,7 @@ class UserRepository(private val database: Database) : IUserRepository { } } - override suspend fun findByIds(ids: List): List { + override suspend fun findByIds(ids: List): List { return query { Users.select { Users.id inList ids }.map { it.toUserEntity() @@ -72,7 +65,7 @@ class UserRepository(private val database: Database) : IUserRepository { } } - override suspend fun findByName(name: String): UserEntity? { + override suspend fun findByName(name: String): User? { return query { Users.select { Users.name eq name }.map { it.toUserEntity() @@ -80,7 +73,7 @@ class UserRepository(private val database: Database) : IUserRepository { } } - override suspend fun findByNameAndDomains(names: List>): List { + override suspend fun findByNameAndDomains(names: List>): List { return query { val selectAll = Users.selectAll() names.forEach { (name, domain) -> @@ -90,19 +83,19 @@ class UserRepository(private val database: Database) : IUserRepository { } } - override suspend fun findByUrl(url: String): UserEntity? { + override suspend fun findByUrl(url: String): User? { return query { Users.select { Users.url eq url }.singleOrNull()?.toUserEntity() } } - override suspend fun findByUrls(urls: List): List { + override suspend fun findByUrls(urls: List): List { return query { Users.select { Users.url inList urls }.map { it.toUserEntity() } } } - override suspend fun findFollowersById(id: Long): List { + override suspend fun findFollowersById(id: Long): List { return query { val followers = Users.alias("FOLLOWERS") Users.innerJoin( @@ -127,22 +120,26 @@ class UserRepository(private val database: Database) : IUserRepository { ) .select { Users.id eq id } .map { - UserEntity( + User( id = it[followers[Users.id]], name = it[followers[Users.name]], domain = it[followers[Users.domain]], screenName = it[followers[Users.screenName]], description = it[followers[Users.description]], + password = it[followers[Users.password]], inbox = it[followers[Users.inbox]], outbox = it[followers[Users.outbox]], url = it[followers[Users.url]], + publicKey = it[followers[Users.publicKey]], + privateKey = it[followers[Users.privateKey]], + createdAt = LocalDateTime.ofInstant(Instant.ofEpochMilli(it[followers[Users.createdAt]]), ZoneId.systemDefault()) ) } } } - override suspend fun update(userEntity: UserEntity) { + override suspend fun update(userEntity: User) { return query { Users.update({ Users.id eq userEntity.id }) { it[name] = userEntity.name @@ -174,9 +171,46 @@ class UserRepository(private val database: Database) : IUserRepository { } } - override suspend fun findAllByLimitAndByOffset(limit: Int, offset: Long): List { + override suspend fun findAllByLimitAndByOffset(limit: Int, offset: Long): List { return query { Users.selectAll().limit(limit, offset).map { it.toUserEntity() } } } } + +object Users : Table("users") { + val id = long("id").uniqueIndex() + val name = varchar("name", length = 64) + val domain = varchar("domain", length = 255) + val screenName = varchar("screen_name", length = 64) + val description = varchar("description", length = 600) + val password = varchar("password", length = 255).nullable() + val inbox = varchar("inbox", length = 255).uniqueIndex() + val outbox = varchar("outbox", length = 255).uniqueIndex() + val url = varchar("url", length = 255).uniqueIndex() + val publicKey = varchar("public_key", length = 10000) + val privateKey = varchar("private_key", length = 10000) + val createdAt = long("created_at") + + override val primaryKey: PrimaryKey = PrimaryKey(id) + init { + uniqueIndex(name, domain) + } +} + +fun ResultRow.toUser(): User { + return User( + this[Users.id], + this[Users.name], + this[Users.domain], + this[Users.screenName], + this[Users.description], + this[Users.password], + this[Users.inbox], + this[Users.outbox], + this[Users.url], + this[Users.publicKey], + this[Users.privateKey], + LocalDateTime.ofInstant(Instant.ofEpochMilli((this[Users.createdAt])), ZoneId.systemDefault()) + ) +} diff --git a/src/main/kotlin/dev/usbharu/hideout/service/impl/UserAuthService.kt b/src/main/kotlin/dev/usbharu/hideout/service/impl/UserAuthService.kt index 5166082a..a0cdfabc 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/impl/UserAuthService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/impl/UserAuthService.kt @@ -4,7 +4,6 @@ import dev.usbharu.hideout.config.Config import dev.usbharu.hideout.domain.model.User import dev.usbharu.hideout.domain.model.UserAuthentication import dev.usbharu.hideout.domain.model.UserAuthenticationEntity -import dev.usbharu.hideout.domain.model.UserEntity import dev.usbharu.hideout.exception.UserNotFoundException import dev.usbharu.hideout.repository.IUserAuthRepository import dev.usbharu.hideout.repository.IUserRepository diff --git a/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt b/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt index a64ccd04..fcbc60cb 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt @@ -1,7 +1,6 @@ package dev.usbharu.hideout.service.impl import dev.usbharu.hideout.domain.model.User -import dev.usbharu.hideout.domain.model.UserEntity import dev.usbharu.hideout.exception.UserNotFoundException import dev.usbharu.hideout.repository.IUserRepository import java.lang.Integer.min @@ -9,7 +8,7 @@ import java.lang.Integer.min class UserService(private val userRepository: IUserRepository) { private val maxLimit = 100 - suspend fun findAll(limit: Int? = maxLimit, offset: Long? = 0): List { + suspend fun findAll(limit: Int? = maxLimit, offset: Long? = 0): List { return userRepository.findAllByLimitAndByOffset( min(limit ?: maxLimit, maxLimit), @@ -17,36 +16,36 @@ class UserService(private val userRepository: IUserRepository) { ) } - suspend fun findById(id: Long): UserEntity { + suspend fun findById(id: Long): User { return userRepository.findById(id) ?: throw UserNotFoundException("$id was not found.") } - suspend fun findByIds(ids: List): List { + suspend fun findByIds(ids: List): List { return userRepository.findByIds(ids) } - suspend fun findByName(name: String): UserEntity { + suspend fun findByName(name: String): User { return userRepository.findByName(name) ?: throw UserNotFoundException("$name was not found.") } - suspend fun findByNameAndDomains(names: List>): List { + suspend fun findByNameAndDomains(names: List>): List { return userRepository.findByNameAndDomains(names) } - suspend fun findByUrl(url: String): UserEntity { + suspend fun findByUrl(url: String): User { return userRepository.findByUrl(url) ?: throw UserNotFoundException("$url was not found.") } - suspend fun findByUrls(urls: List): List { + suspend fun findByUrls(urls: List): List { return userRepository.findByUrls(urls) } - suspend fun create(user: User): UserEntity { + suspend fun create(user: User): User { return userRepository.create(user) } - suspend fun findFollowersById(id: Long): List { + suspend fun findFollowersById(id: Long): List { return userRepository.findFollowersById(id) } diff --git a/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt b/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt index b5690c99..035f3143 100644 --- a/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt @@ -1,10 +1,9 @@ package dev.usbharu.hideout.plugins -import dev.usbharu.hideout.domain.model.ap.JsonLd import dev.usbharu.hideout.domain.model.User import dev.usbharu.hideout.domain.model.UserAuthentication import dev.usbharu.hideout.domain.model.UserAuthenticationEntity -import dev.usbharu.hideout.domain.model.UserEntity +import dev.usbharu.hideout.domain.model.ap.JsonLd import dev.usbharu.hideout.repository.IUserAuthRepository import dev.usbharu.hideout.repository.IUserRepository import dev.usbharu.hideout.service.impl.UserAuthService @@ -17,41 +16,55 @@ import org.junit.jupiter.api.Test import java.security.KeyPairGenerator import java.security.interfaces.RSAPrivateKey import java.security.interfaces.RSAPublicKey +import java.time.LocalDateTime class ActivityPubKtTest { @Test fun HttpSignTest(): Unit = runBlocking { val ktorKeyMap = KtorKeyMap(UserAuthService(object : IUserRepository { - override suspend fun create(user: User): UserEntity { + override suspend fun create(user: User): User { TODO("Not yet implemented") } - override suspend fun findById(id: Long): UserEntity? { + override suspend fun findById(id: Long): User? { TODO("Not yet implemented") } - override suspend fun findByIds(ids: List): List { + override suspend fun findByIds(ids: List): List { TODO("Not yet implemented") } - override suspend fun findByName(name: String): UserEntity? { - return UserEntity(1, "test", "localhost", "test", "","","","") + override suspend fun findByName(name: String): User? { + return User( + 1, + "test", + "localhost", + "test", + "", + "", + "", + "", + "", + "", + null, + LocalDateTime.now() + ) } - override suspend fun findByNameAndDomains(names: List>): List { + override suspend fun findByNameAndDomains(names: List>): List { TODO("Not yet implemented") } - override suspend fun findByUrl(url: String): UserEntity? { + override suspend fun findByUrl(url: String): User? { TODO("Not yet implemented") } - override suspend fun findByUrls(urls: List): List { + override suspend fun findByUrls(urls: List): List { TODO("Not yet implemented") } - override suspend fun update(userEntity: UserEntity) { + override suspend fun update(userEntity: User) { TODO("Not yet implemented") } @@ -63,7 +76,7 @@ class ActivityPubKtTest { TODO("Not yet implemented") } - override suspend fun findAllByLimitAndByOffset(limit: Int, offset: Long): List { + override suspend fun findAllByLimitAndByOffset(limit: Int, offset: Long): List { TODO("Not yet implemented") } @@ -75,7 +88,7 @@ class ActivityPubKtTest { TODO("Not yet implemented") } - override suspend fun findFollowersById(id: Long): List { + override suspend fun findFollowersById(id: Long): List { TODO("Not yet implemented") } diff --git a/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt b/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt index 02cfb9b4..edaeaff3 100644 --- a/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt @@ -3,7 +3,6 @@ package dev.usbharu.hideout.plugins import dev.usbharu.hideout.domain.model.User import dev.usbharu.hideout.domain.model.UserAuthentication import dev.usbharu.hideout.domain.model.UserAuthenticationEntity -import dev.usbharu.hideout.domain.model.UserEntity import dev.usbharu.hideout.repository.IUserAuthRepository import dev.usbharu.hideout.repository.IUserRepository import dev.usbharu.hideout.service.impl.UserAuthService @@ -12,41 +11,54 @@ import org.junit.jupiter.api.Test import java.security.KeyPairGenerator import java.security.interfaces.RSAPrivateKey import java.security.interfaces.RSAPublicKey +import java.time.LocalDateTime class KtorKeyMapTest { @Test fun getPrivateKey() { val ktorKeyMap = KtorKeyMap(UserAuthService(object : IUserRepository { - override suspend fun create(user: User): UserEntity { + override suspend fun create(user: User): User { TODO("Not yet implemented") } - override suspend fun findById(id: Long): UserEntity? { + override suspend fun findById(id: Long): User? { TODO("Not yet implemented") } - override suspend fun findByIds(ids: List): List { + override suspend fun findByIds(ids: List): List { TODO("Not yet implemented") } - override suspend fun findByName(name: String): UserEntity? { - return UserEntity(1, "test", "localhost", "test", "","","","") + override suspend fun findByName(name: String): User? { + return User( + 1, + "test", + "localhost", + "test", + "", + "", + "", + "", + "", + "", + createdAt = LocalDateTime.now() + ) } - override suspend fun findByNameAndDomains(names: List>): List { + override suspend fun findByNameAndDomains(names: List>): List { TODO("Not yet implemented") } - override suspend fun findByUrl(url: String): UserEntity? { + override suspend fun findByUrl(url: String): User? { TODO("Not yet implemented") } - override suspend fun findByUrls(urls: List): List { + override suspend fun findByUrls(urls: List): List { TODO("Not yet implemented") } - override suspend fun update(userEntity: UserEntity) { + override suspend fun update(userEntity: User) { TODO("Not yet implemented") } @@ -58,7 +70,7 @@ class KtorKeyMapTest { TODO("Not yet implemented") } - override suspend fun findAllByLimitAndByOffset(limit: Int, offset: Long): List { + override suspend fun findAllByLimitAndByOffset(limit: Int, offset: Long): List { TODO("Not yet implemented") } @@ -70,7 +82,7 @@ class KtorKeyMapTest { TODO("Not yet implemented") } - override suspend fun findFollowersById(id: Long): List { + override suspend fun findFollowersById(id: Long): List { TODO("Not yet implemented") } diff --git a/src/test/kotlin/dev/usbharu/hideout/repository/UserRepositoryTest.kt b/src/test/kotlin/dev/usbharu/hideout/repository/UserRepositoryTest.kt index 740bc90e..54b6dc69 100644 --- a/src/test/kotlin/dev/usbharu/hideout/repository/UserRepositoryTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/repository/UserRepositoryTest.kt @@ -3,7 +3,6 @@ package dev.usbharu.hideout.repository import dev.usbharu.hideout.domain.model.User -import dev.usbharu.hideout.domain.model.Users import dev.usbharu.hideout.domain.model.UsersFollowers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest diff --git a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubFollowServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubFollowServiceImplTest.kt index c5a0bb5f..3de7494d 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubFollowServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubFollowServiceImplTest.kt @@ -6,7 +6,7 @@ package dev.usbharu.hideout.service.activitypub import com.fasterxml.jackson.module.kotlin.readValue import dev.usbharu.hideout.config.Config import dev.usbharu.hideout.config.ConfigData -import dev.usbharu.hideout.domain.model.UserEntity +import dev.usbharu.hideout.domain.model.User import dev.usbharu.hideout.domain.model.ap.* import dev.usbharu.hideout.domain.model.job.ReceiveFollowJob import dev.usbharu.hideout.service.impl.UserService @@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test import org.mockito.ArgumentMatchers.anyString import org.mockito.kotlin.* import utils.JsonObjectMapper +import java.time.LocalDateTime class ActivityPubFollowServiceImplTest { @Test @@ -88,7 +89,7 @@ class ActivityPubFollowServiceImplTest { } val userService = mock { onBlocking { findByUrls(any()) } doReturn listOf( - UserEntity( + User( id = 1L, name = "test", domain = "example.com", @@ -96,9 +97,11 @@ class ActivityPubFollowServiceImplTest { description = "This user is test user.", inbox = "https://example.com/inbox", outbox = "https://example.com/outbox", - url = "https://example.com" + url = "https://example.com", + publicKey = "", + createdAt = LocalDateTime.now() ), - UserEntity( + User( id = 2L, name = "follower", domain = "follower.example.com", @@ -106,7 +109,9 @@ class ActivityPubFollowServiceImplTest { description = "This user is test follower user.", inbox = "https://follower.example.com/inbox", outbox = "https://follower.example.com/outbox", - url = "https://follower.example.com" + url = "https://follower.example.com", + publicKey = "", + createdAt = LocalDateTime.now() ) ) onBlocking { addFollowers(any(), any()) } doReturn Unit diff --git a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImplTest.kt index 8d820be6..a9445572 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImplTest.kt @@ -6,7 +6,7 @@ package dev.usbharu.hideout.service.activitypub import dev.usbharu.hideout.config.Config import dev.usbharu.hideout.config.ConfigData import dev.usbharu.hideout.domain.model.PostEntity -import dev.usbharu.hideout.domain.model.UserEntity +import dev.usbharu.hideout.domain.model.User import dev.usbharu.hideout.domain.model.job.DeliverPostJob import dev.usbharu.hideout.service.impl.UserService import dev.usbharu.hideout.service.job.JobQueueParentService @@ -20,13 +20,14 @@ import org.junit.jupiter.api.Test import org.mockito.Mockito.eq import org.mockito.kotlin.* import utils.JsonObjectMapper +import java.time.LocalDateTime import kotlin.test.assertEquals class ActivityPubNoteServiceImplTest { @Test fun `createPost 新しい投稿`() = runTest { - val followers = listOf( - UserEntity( + val followers = listOf( + User( 2L, "follower", "follower.example.com", @@ -34,9 +35,12 @@ class ActivityPubNoteServiceImplTest { "test follower user", "https://follower.example.com/inbox", "https://follower.example.com/outbox", - "https://follower.example.com" + "https://follower.example.com", + "", + publicKey = "", + createdAt = LocalDateTime.now() ), - UserEntity( + User( 3L, "follower2", "follower2.example.com", @@ -44,11 +48,14 @@ class ActivityPubNoteServiceImplTest { "test follower2 user", "https://follower2.example.com/inbox", "https://follower2.example.com/outbox", - "https:.//follower2.example.com" + "https://follower2.example.com", + "", + publicKey = "", + createdAt = LocalDateTime.now() ) ) val userService = mock { - onBlocking { findById(eq(1L)) } doReturn UserEntity( + onBlocking { findById(eq(1L)) } doReturn User( 1L, "test", "example.com", @@ -56,7 +63,10 @@ class ActivityPubNoteServiceImplTest { "test user", "https://example.com/inbox", "https://example.com/outbox", - "https:.//example.com" + "https:.//example.com", + "", + publicKey = "", + createdAt = LocalDateTime.now() ) onBlocking { findFollowersById(eq(1L)) } doReturn followers }