From 29cbb5f93e6b7e15e20969973c2801127e8d593e Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 10 Sep 2024 19:56:08 +0900 Subject: [PATCH] =?UTF-8?q?test:=20InstanceRepositoryImpl=E3=81=AE?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InstanceRepositoryImplTest.kt | 123 ++++++++++++++++++ .../kotlin/utils/AbstractRepositoryTest.kt | 4 + 2 files changed, 127 insertions(+) diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/InstanceRepositoryImplTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/InstanceRepositoryImplTest.kt index 29d1bdfe..8955aca5 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/InstanceRepositoryImplTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/InstanceRepositoryImplTest.kt @@ -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) diff --git a/hideout-core/src/test/kotlin/utils/AbstractRepositoryTest.kt b/hideout-core/src/test/kotlin/utils/AbstractRepositoryTest.kt index 15530abd..a473df03 100644 --- a/hideout-core/src/test/kotlin/utils/AbstractRepositoryTest.kt +++ b/hideout-core/src/test/kotlin/utils/AbstractRepositoryTest.kt @@ -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