test: InstanceRepositoryImplのテストを追加

This commit is contained in:
usbharu 2024-09-10 19:56:08 +09:00
parent 37c8335165
commit 29cbb5f93e
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
2 changed files with 127 additions and 0 deletions

View File

@ -173,6 +173,129 @@ class InstanceRepositoryImplTest : AbstractRepositoryTest(InstanceTable) {
assertNull(InstanceRepositoryImpl().findById(InstanceId(1)))
}
@Test
fun findByUrl_指定したURLで存在したら返す() = runTest {
dbSetup(to = dataSource) {
insertInto(InstanceTable.tableName) {
columns(
"ID",
"name",
"DESCRIPTION",
"URL",
"ICON_URL",
"SHARED_INBOX",
"SOFTWARE",
"VERSION",
"IS_BLOCKED",
"IS_MUTED",
"MODERATION_NOTE",
"CREATED_AT"
)
values(
1,
"test",
"description",
"https://www.example.com",
"https://www.example.com",
null,
"",
"",
false,
false,
"",
Timestamp.from(Instant.parse("2020-01-01T00:00:00Z"))
)
}
}.launch()
val actual = InstanceRepositoryImpl().findByUrl(URI.create("https://www.example.com"))
val expected = Instance(
id = InstanceId(1),
name = InstanceName("test"),
description = InstanceDescription("description"),
url = URI.create("https://www.example.com"),
iconUrl = URI.create("https://www.example.com"),
sharedInbox = null,
software = InstanceSoftware(""),
version = InstanceVersion(""),
isBlocked = false,
isMuted = false,
moderationNote = InstanceModerationNote(""),
createdAt = Instant.parse("2020-01-01T00:00:00Z"),
)
assertEquals(expected, actual)
}
@Test
fun findByUrl_指定したURLで存在しないとnull() = runTest {
assertNull(InstanceRepositoryImpl().findByUrl(URI.create("https://www.example.com")))
}
@Test
fun delete_削除() = runTest {
dbSetup(to = dataSource) {
insertInto(InstanceTable.tableName) {
columns(
"ID",
"name",
"DESCRIPTION",
"URL",
"ICON_URL",
"SHARED_INBOX",
"SOFTWARE",
"VERSION",
"IS_BLOCKED",
"IS_MUTED",
"MODERATION_NOTE",
"CREATED_AT"
)
values(
1,
"test",
"description",
"https://www.example.com",
"https://www.example.com",
null,
"",
"",
false,
false,
"",
Timestamp.from(Instant.parse("2020-01-01T00:00:00Z"))
)
}
}.launch()
val instance = Instance(
id = InstanceId(1),
name = InstanceName("test"),
description = InstanceDescription("description"),
url = URI.create("https://www.example.com"),
iconUrl = URI.create("https://www.example.com"),
sharedInbox = null,
software = InstanceSoftware(""),
version = InstanceVersion(""),
isBlocked = false,
isMuted = false,
moderationNote = InstanceModerationNote(""),
createdAt = Instant.parse("2020-01-01T00:00:00Z"),
)
change.setStartPointNow()
InstanceRepositoryImpl().delete(instance)
change.setEndPointNow()
assertThat(change)
.hasNumberOfChanges(1)
.changeOfDeletionOnTable(InstanceTable.tableName)
.rowAtStartPoint()
.value(InstanceTable.id.name).isEqualTo(1)
}
companion object {
fun assertEquals(expected: Instance, actual: Instance?) {
assertNotNull(actual)

View File

@ -4,6 +4,7 @@ import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
import org.assertj.db.api.TableRowAssert
import org.assertj.db.api.TableRowValueAssert
import org.assertj.db.type.Changes
import org.assertj.db.type.Table
import org.flywaydb.core.Flyway
import org.jetbrains.exposed.sql.Column
@ -31,11 +32,14 @@ abstract class AbstractRepositoryTest(private val exposedTable: org.jetbrains.ex
private lateinit var transaction: Transaction
protected lateinit var change: Changes
@BeforeEach
fun setUp() {
flyway.clean()
flyway.migrate()
transaction = TransactionManager.currentOrNew(Connection.TRANSACTION_READ_UNCOMMITTED)
change = Changes(assertTable)
}
@AfterEach