mirror of https://github.com/usbharu/Hideout.git
style: テストのスタイルを修正
This commit is contained in:
parent
fcabce7380
commit
028c988475
|
@ -3,5 +3,4 @@ package dev.usbharu.hideout
|
|||
import io.ktor.server.application.*
|
||||
|
||||
fun Application.empty() {
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ import java.time.Instant
|
|||
class ActivityPubKtTest {
|
||||
@Test
|
||||
fun HttpSignTest(): Unit = runBlocking {
|
||||
|
||||
val ktorKeyMap = KtorKeyMap(object : IUserRepository {
|
||||
override suspend fun save(user: User): User {
|
||||
TODO("Not yet implemented")
|
||||
|
@ -96,12 +95,13 @@ class ActivityPubKtTest {
|
|||
override suspend fun nextId(): Long {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
val httpClient = HttpClient(MockEngine { httpRequestData ->
|
||||
val httpClient = HttpClient(
|
||||
MockEngine { httpRequestData ->
|
||||
respondOk()
|
||||
}) {
|
||||
}
|
||||
) {
|
||||
install(httpSignaturePlugin) {
|
||||
keyMap = ktorKeyMap
|
||||
}
|
||||
|
@ -112,7 +112,5 @@ class ActivityPubKtTest {
|
|||
}
|
||||
|
||||
httpClient.postAp("https://localhost", "test", JsonLd(emptyList()))
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,6 @@ class KtorKeyMapTest {
|
|||
generateKeyPair.private.toPem(),
|
||||
createdAt = Instant.now()
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
override suspend fun findByDomain(domain: String): List<User> {
|
||||
|
@ -92,7 +91,6 @@ class KtorKeyMapTest {
|
|||
override suspend fun nextId(): Long {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
ktorKeyMap.getPrivateKey("test")
|
||||
|
|
|
@ -18,7 +18,6 @@ import java.time.Clock
|
|||
import java.time.Instant
|
||||
import java.time.ZoneId
|
||||
|
||||
|
||||
class UserRepositoryTest {
|
||||
|
||||
lateinit var db: Database
|
||||
|
@ -35,7 +34,6 @@ class UserRepositoryTest {
|
|||
@AfterEach
|
||||
fun tearDown() {
|
||||
transaction(db) {
|
||||
|
||||
SchemaUtils.drop(UsersFollowers)
|
||||
SchemaUtils.drop(Users)
|
||||
}
|
||||
|
@ -43,11 +41,14 @@ class UserRepositoryTest {
|
|||
|
||||
@Test
|
||||
fun `findFollowersById フォロワー一覧を取得`() = runTest {
|
||||
val userRepository = UserRepository(db, object : IdGenerateService {
|
||||
val userRepository = UserRepository(
|
||||
db,
|
||||
object : IdGenerateService {
|
||||
override suspend fun generateId(): Long {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
val user = userRepository.save(
|
||||
User(
|
||||
id = 0L,
|
||||
|
@ -98,16 +99,18 @@ class UserRepositoryTest {
|
|||
userRepository.findFollowersById(user.id).let {
|
||||
assertIterableEquals(listOf(follower, follower2), it)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `createFollower フォロワー追加`() = runTest {
|
||||
val userRepository = UserRepository(db, object : IdGenerateService {
|
||||
val userRepository = UserRepository(
|
||||
db,
|
||||
object : IdGenerateService {
|
||||
override suspend fun generateId(): Long {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
val user = userRepository.save(
|
||||
User(
|
||||
0L,
|
||||
|
@ -140,11 +143,9 @@ class UserRepositoryTest {
|
|||
)
|
||||
userRepository.createFollower(user.id, follower.id)
|
||||
transaction {
|
||||
|
||||
val followerIds =
|
||||
UsersFollowers.select { UsersFollowers.userId eq user.id }.map { it[UsersFollowers.followerId] }
|
||||
assertIterableEquals(listOf(follower.id), followerIds)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ import java.time.Instant
|
|||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
|
||||
class UsersAPTest {
|
||||
|
||||
@Test()
|
||||
|
@ -100,8 +99,8 @@ class UsersAPTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test()
|
||||
// @Disabled
|
||||
@Test()
|
||||
fun `ユーザのURLにAcceptヘッダーをActivityとJson-LDにしてアクセスしたときPersonが返ってくる`() = testApplication {
|
||||
environment {
|
||||
config = ApplicationConfig("empty.conf")
|
||||
|
@ -167,16 +166,21 @@ class UsersAPTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// @Disabled
|
||||
@Test
|
||||
fun contentType_Test() {
|
||||
|
||||
assertTrue(ContentType.Application.Activity.match("application/activity+json"))
|
||||
val listOf = listOf(ContentType.Application.JsonLd, ContentType.Application.Activity)
|
||||
assertTrue(listOf.find { contentType ->
|
||||
assertTrue(
|
||||
listOf.find { contentType ->
|
||||
contentType.match("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
|
||||
}.let { it != null })
|
||||
assertTrue(ContentType.Application.JsonLd.match("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""))
|
||||
}.let { it != null }
|
||||
)
|
||||
assertTrue(
|
||||
ContentType.Application.JsonLd.match(
|
||||
"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -16,17 +16,13 @@ class TwitterSnowflakeIdGenerateServiceTest {
|
|||
val mutex = Mutex()
|
||||
val mutableListOf = mutableListOf<Long>()
|
||||
coroutineScope {
|
||||
|
||||
repeat(500000) {
|
||||
|
||||
launch(Dispatchers.IO) {
|
||||
val id = TwitterSnowflakeIdGenerateService.generateId()
|
||||
mutex.withLock {
|
||||
mutableListOf.add(id)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,8 @@ class ActivityPubFollowServiceImplTest {
|
|||
mock(),
|
||||
activityPubUserService,
|
||||
userService,
|
||||
HttpClient(MockEngine { httpRequestData ->
|
||||
HttpClient(
|
||||
MockEngine { httpRequestData ->
|
||||
assertEquals(person.inbox, httpRequestData.url.toString())
|
||||
val accept = Accept(
|
||||
type = emptyList(),
|
||||
|
@ -143,7 +144,8 @@ class ActivityPubFollowServiceImplTest {
|
|||
)
|
||||
)
|
||||
respondOk()
|
||||
})
|
||||
}
|
||||
)
|
||||
)
|
||||
activityPubFollowService.receiveFollowJob(
|
||||
JobProps(
|
||||
|
|
|
@ -73,7 +73,13 @@ class ActivityPubNoteServiceImplTest {
|
|||
val jobQueueParentService = mock<JobQueueParentService>()
|
||||
val activityPubNoteService = ActivityPubNoteServiceImpl(mock(), jobQueueParentService, userService)
|
||||
val postEntity = PostEntity(
|
||||
1L, 1L, null, "test text", 1L, 1, "https://example.com"
|
||||
1L,
|
||||
1L,
|
||||
null,
|
||||
"test text",
|
||||
1L,
|
||||
1,
|
||||
"https://example.com"
|
||||
)
|
||||
activityPubNoteService.createNote(postEntity)
|
||||
verify(jobQueueParentService, times(2)).schedule(eq(DeliverPostJob), any())
|
||||
|
@ -82,10 +88,12 @@ class ActivityPubNoteServiceImplTest {
|
|||
@Test
|
||||
fun `createPostJob 新しい投稿のJob`() = runTest {
|
||||
Config.configData = ConfigData(objectMapper = JsonObjectMapper.objectMapper)
|
||||
val httpClient = HttpClient(MockEngine { httpRequestData ->
|
||||
val httpClient = HttpClient(
|
||||
MockEngine { httpRequestData ->
|
||||
assertEquals("https://follower.example.com/inbox", httpRequestData.url.toString())
|
||||
respondOk()
|
||||
})
|
||||
}
|
||||
)
|
||||
val activityPubNoteService = ActivityPubNoteServiceImpl(httpClient, mock(), mock())
|
||||
activityPubNoteService.createNoteJob(
|
||||
JobProps(
|
||||
|
|
|
@ -50,10 +50,8 @@ class UserServiceTest {
|
|||
|
||||
@Test
|
||||
fun `createRemoteUser リモートユーザーを作成できる`() = runTest {
|
||||
|
||||
Config.configData = ConfigData(domain = "example.com", url = "https://example.com")
|
||||
|
||||
|
||||
val userRepository = mock<IUserRepository> {
|
||||
onBlocking { nextId() } doReturn 113345L
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import org.jetbrains.exposed.sql.Database
|
|||
import org.jetbrains.exposed.sql.DatabaseConfig
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
|
||||
|
||||
@ExtendWith(DBResetInterceptor::class)
|
||||
abstract class DatabaseTestBase {
|
||||
companion object {
|
||||
|
@ -12,7 +11,8 @@ abstract class DatabaseTestBase {
|
|||
Database.connect(
|
||||
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1",
|
||||
driver = "org.h2.Driver",
|
||||
databaseConfig = DatabaseConfig { useNestedTransactions = true })
|
||||
databaseConfig = DatabaseConfig { useNestedTransactions = true }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue