mirror of https://github.com/usbharu/Hideout.git
test: ExposedApplicationRepositoryとExposedCustomEmojiRepositoryとExposedFilterRepositoryのテストを追加
This commit is contained in:
parent
934e032b70
commit
7ce7e3085a
|
@ -4,4 +4,17 @@ class FilterKeyword(
|
|||
val id: FilterKeywordId,
|
||||
var keyword: FilterKeywordKeyword,
|
||||
val mode: FilterMode
|
||||
)
|
||||
) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as FilterKeyword
|
||||
|
||||
return id == other.id
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return id.hashCode()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,22 @@ class FilterName(name: String) {
|
|||
|
||||
val name = name.take(LENGTH)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as FilterName
|
||||
|
||||
return name == other.name
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return name.hashCode()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val LENGTH = 300
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ class FilterQueryMapper(private val filterResultRowMapper: ResultRowMapper<Filte
|
|||
it
|
||||
.first()
|
||||
.let(filterResultRowMapper::map)
|
||||
.apply {
|
||||
.run {
|
||||
reconstructWith(
|
||||
it.mapNotNull { resultRow: ResultRow ->
|
||||
FilterKeyword(
|
||||
|
|
|
@ -31,8 +31,7 @@ import org.springframework.stereotype.Repository
|
|||
import java.net.URI
|
||||
|
||||
@Repository
|
||||
class ExposedCustomEmojiRepository : CustomEmojiRepository,
|
||||
AbstractRepository() {
|
||||
class ExposedCustomEmojiRepository : CustomEmojiRepository, AbstractRepository() {
|
||||
override val logger: Logger
|
||||
get() = Companion.logger
|
||||
|
||||
|
@ -50,7 +49,12 @@ class ExposedCustomEmojiRepository : CustomEmojiRepository,
|
|||
}
|
||||
|
||||
override suspend fun findById(id: Long): CustomEmoji? = query {
|
||||
return@query CustomEmojis.selectAll().where { CustomEmojis.id eq id }.singleOrNull()?.toCustomEmoji()
|
||||
CustomEmojis
|
||||
.selectAll()
|
||||
.where { CustomEmojis.id eq id }
|
||||
.limit(1)
|
||||
.singleOrNull()
|
||||
?.toCustomEmoji()
|
||||
}
|
||||
|
||||
override suspend fun delete(customEmoji: CustomEmoji): Unit = query {
|
||||
|
@ -58,7 +62,7 @@ class ExposedCustomEmojiRepository : CustomEmojiRepository,
|
|||
}
|
||||
|
||||
override suspend fun findByNamesAndDomain(names: List<String>, domain: String): List<CustomEmoji> = query {
|
||||
return@query CustomEmojis
|
||||
CustomEmojis
|
||||
.selectAll()
|
||||
.where {
|
||||
CustomEmojis.name inList names and (CustomEmojis.domain eq domain)
|
||||
|
@ -67,7 +71,7 @@ class ExposedCustomEmojiRepository : CustomEmojiRepository,
|
|||
}
|
||||
|
||||
override suspend fun findByIds(ids: List<Long>): List<CustomEmoji> = query {
|
||||
return@query CustomEmojis
|
||||
CustomEmojis
|
||||
.selectAll()
|
||||
.where {
|
||||
CustomEmojis.id inList ids
|
||||
|
|
|
@ -63,18 +63,20 @@ class ExposedFilterRepository(private val filterQueryMapper: QueryMapper<Filter>
|
|||
val filterId = FilterKeywords
|
||||
.selectAll()
|
||||
.where { FilterKeywords.id eq filterKeywordId.id }
|
||||
.limit(1)
|
||||
.firstOrNull()?.get(FilterKeywords.filterId) ?: return@query null
|
||||
val where = Filters.selectAll().where { Filters.id eq filterId }
|
||||
val where = Filters.leftJoin(FilterKeywords).selectAll().where { Filters.id eq filterId }
|
||||
return@query filterQueryMapper.map(where).firstOrNull()
|
||||
}
|
||||
|
||||
override suspend fun findByFilterId(filterId: FilterId): Filter? = query {
|
||||
val where = Filters.selectAll().where { Filters.id eq filterId.id }
|
||||
val where = Filters.leftJoin(FilterKeywords).selectAll().where { Filters.id eq filterId.id }
|
||||
return@query filterQueryMapper.map(where).firstOrNull()
|
||||
}
|
||||
|
||||
override suspend fun findByUserDetailId(userDetailId: UserDetailId): List<Filter> = query {
|
||||
return@query Filters.selectAll().where { Filters.userId eq userDetailId.id }.let(filterQueryMapper::map)
|
||||
return@query Filters.leftJoin(FilterKeywords).selectAll().where { Filters.userId eq userDetailId.id }
|
||||
.let(filterQueryMapper::map)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package dev.usbharu.hideout.core.infrastructure.exposedrepository
|
||||
|
||||
import com.ninja_squad.dbsetup_kotlin.dbSetup
|
||||
import dev.usbharu.hideout.core.domain.model.application.Application
|
||||
import dev.usbharu.hideout.core.domain.model.application.ApplicationId
|
||||
import dev.usbharu.hideout.core.domain.model.application.ApplicationName
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.assertj.db.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import utils.AbstractRepositoryTest
|
||||
import utils.columns
|
||||
import utils.isEqualTo
|
||||
import utils.withSuspend
|
||||
|
||||
class ExposedApplicationRepositoryTest : AbstractRepositoryTest(Applications) {
|
||||
@Test
|
||||
fun save_idが同じレコードが存在しないとinsert() = runTest {
|
||||
val application = Application(ApplicationId(1), ApplicationName("test-application"))
|
||||
|
||||
ExposedApplicationRepository().save(application)
|
||||
|
||||
assertThat(assertTable)
|
||||
.row(0)
|
||||
.isEqualTo(Applications.id, application.applicationId.id)
|
||||
.isEqualTo(Applications.name, application.name.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun save_idが同じレコードが存在したらupdate() = runTest {
|
||||
dbSetup(to = dataSource) {
|
||||
insertInto(Applications.tableName) {
|
||||
columns(Applications.columns)
|
||||
values(1, "application-test")
|
||||
}
|
||||
}.launch()
|
||||
|
||||
val application = Application(ApplicationId(1), ApplicationName("test-application"))
|
||||
|
||||
ExposedApplicationRepository().save(application)
|
||||
|
||||
assertThat(assertTable)
|
||||
.row(0)
|
||||
.isEqualTo(Applications.id, application.applicationId.id)
|
||||
.isEqualTo(Applications.name, application.name.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun delete_削除される() = runTest {
|
||||
dbSetup(to = dataSource) {
|
||||
insertInto(Applications.tableName) {
|
||||
columns(Applications.columns)
|
||||
values(1, "test-application")
|
||||
}
|
||||
}.launch()
|
||||
|
||||
val application = Application(ApplicationId(1), ApplicationName("test-application"))
|
||||
|
||||
change.withSuspend {
|
||||
ExposedApplicationRepository().delete(application)
|
||||
}
|
||||
|
||||
assertThat(change)
|
||||
.changeOfDeletionOnTable(Applications.tableName)
|
||||
.rowAtStartPoint()
|
||||
.value(Applications.id.name).isEqualTo(application.applicationId.id)
|
||||
.value(Applications.name.name).isEqualTo(application.name.name)
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,324 @@
|
|||
package dev.usbharu.hideout.core.infrastructure.exposedrepository
|
||||
|
||||
import com.ninja_squad.dbsetup_kotlin.dbSetup
|
||||
import dev.usbharu.hideout.core.domain.model.emoji.CustomEmoji
|
||||
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.support.domain.Domain
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.assertj.db.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import utils.*
|
||||
import java.net.URI
|
||||
import java.sql.Timestamp
|
||||
import java.time.Instant
|
||||
import kotlin.test.assertContentEquals
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertNull
|
||||
|
||||
class ExposedCustomEmojiRepositoryTest : AbstractRepositoryTest(CustomEmojis) {
|
||||
@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 customEmoji = CustomEmoji(
|
||||
CustomEmojiId(1),
|
||||
"name",
|
||||
Domain("example.com"),
|
||||
InstanceId(1),
|
||||
URI.create("https://example.com"),
|
||||
null,
|
||||
Instant.parse("2020-01-01T00:00:00Z")
|
||||
)
|
||||
|
||||
ExposedCustomEmojiRepository().save(customEmoji)
|
||||
|
||||
assertThat(assertTable).row(0).isEqualTo(CustomEmojis.id, customEmoji.id.emojiId)
|
||||
.isEqualTo(CustomEmojis.name, customEmoji.name).isEqualTo(CustomEmojis.domain, customEmoji.domain.domain)
|
||||
.isEqualTo(CustomEmojis.instanceId, customEmoji.instanceId.instanceId)
|
||||
.isEqualTo(CustomEmojis.url, customEmoji.url.toString())
|
||||
.isEqualTo(CustomEmojis.category, customEmoji.category).value(CustomEmojis.createdAt.name)
|
||||
.isEqualTo(Timestamp.from(customEmoji.createdAt))
|
||||
}
|
||||
|
||||
@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(CustomEmojis.tableName) {
|
||||
columns(CustomEmojis.columns)
|
||||
values(
|
||||
1,
|
||||
"emoji",
|
||||
"example.com",
|
||||
1,
|
||||
"https://example.com",
|
||||
null,
|
||||
Timestamp.from(Instant.parse("2020-01-01T00:00:00Z"))
|
||||
)
|
||||
}
|
||||
execute(enableReferenceIntegrityConstraints)
|
||||
}.launch()
|
||||
val customEmoji = CustomEmoji(
|
||||
CustomEmojiId(1),
|
||||
"name",
|
||||
Domain("example.com"),
|
||||
InstanceId(1),
|
||||
URI.create("https://example.com"),
|
||||
null,
|
||||
Instant.parse("2020-01-01T00:00:00Z")
|
||||
)
|
||||
|
||||
ExposedCustomEmojiRepository().save(customEmoji)
|
||||
|
||||
assertThat(assertTable).row(0).isEqualTo(CustomEmojis.id, customEmoji.id.emojiId)
|
||||
.isEqualTo(CustomEmojis.name, customEmoji.name).isEqualTo(CustomEmojis.domain, customEmoji.domain.domain)
|
||||
.isEqualTo(CustomEmojis.instanceId, customEmoji.instanceId.instanceId)
|
||||
.isEqualTo(CustomEmojis.url, customEmoji.url.toString())
|
||||
.isEqualTo(CustomEmojis.category, customEmoji.category).value(CustomEmojis.createdAt.name)
|
||||
.isEqualTo(Timestamp.from(customEmoji.createdAt))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun delete_削除される() = runTest {
|
||||
|
||||
dbSetup(to = dataSource) {
|
||||
execute(disableReferenceIntegrityConstraints)
|
||||
insertInto(CustomEmojis.tableName) {
|
||||
columns(CustomEmojis.columns)
|
||||
values(
|
||||
1,
|
||||
"emoji",
|
||||
"example.com",
|
||||
1,
|
||||
"https://example.com",
|
||||
null,
|
||||
Timestamp.from(Instant.parse("2020-01-01T00:00:00Z"))
|
||||
)
|
||||
}
|
||||
}.launch()
|
||||
|
||||
val customEmoji = CustomEmoji(
|
||||
CustomEmojiId(1),
|
||||
"name",
|
||||
Domain("example.com"),
|
||||
InstanceId(1),
|
||||
URI.create("https://example.com"),
|
||||
null,
|
||||
Instant.parse("2020-01-01T00:00:00Z")
|
||||
)
|
||||
|
||||
|
||||
change.withSuspend {
|
||||
ExposedCustomEmojiRepository().delete(customEmoji)
|
||||
}
|
||||
|
||||
assertThat(change).changeOfDeletionOnTable(CustomEmojis.tableName).rowAtStartPoint().value(CustomEmojis.id.name)
|
||||
.isEqualTo(customEmoji.id.emojiId)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findById_指定したIdで存在したら返す() = runTest {
|
||||
dbSetup(to = dataSource) {
|
||||
execute(disableReferenceIntegrityConstraints)
|
||||
insertInto(CustomEmojis.tableName) {
|
||||
columns(CustomEmojis.columns)
|
||||
values(
|
||||
1,
|
||||
"emoji",
|
||||
"example.com",
|
||||
1,
|
||||
"https://example.com",
|
||||
null,
|
||||
Timestamp.from(Instant.parse("2020-01-01T00:00:00Z"))
|
||||
)
|
||||
}
|
||||
}.launch()
|
||||
|
||||
val customEmoji = CustomEmoji(
|
||||
CustomEmojiId(1),
|
||||
"emoji",
|
||||
Domain("example.com"),
|
||||
InstanceId(1),
|
||||
URI.create("https://example.com"),
|
||||
null,
|
||||
Instant.parse("2020-01-01T00:00:00Z")
|
||||
)
|
||||
|
||||
val actual = ExposedCustomEmojiRepository().findById(1)
|
||||
|
||||
assertEquals(customEmoji, actual)
|
||||
assertNotNull(actual)
|
||||
assertEquals(customEmoji.id, actual.id)
|
||||
assertEquals(customEmoji.createdAt, actual.createdAt)
|
||||
assertEquals(customEmoji.url, actual.url)
|
||||
assertEquals(customEmoji.category, actual.category)
|
||||
assertEquals(customEmoji.instanceId, actual.instanceId)
|
||||
assertEquals(customEmoji.domain, actual.domain)
|
||||
assertEquals(customEmoji.name, actual.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findById_指定したIdで存在しないとnull() = runTest {
|
||||
assertNull(ExposedCustomEmojiRepository().findById(1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findByNamesAndDomain_指定した条件全部返す() = runTest {
|
||||
dbSetup(to = dataSource) {
|
||||
execute(disableReferenceIntegrityConstraints)
|
||||
insertInto(CustomEmojis.tableName) {
|
||||
columns(CustomEmojis.columns)
|
||||
values(
|
||||
1,
|
||||
"emoji",
|
||||
"example.com",
|
||||
1,
|
||||
"https://example.com/1",
|
||||
null,
|
||||
Timestamp.from(Instant.parse("2020-01-01T00:00:00Z"))
|
||||
)
|
||||
values(
|
||||
2,
|
||||
"emoji2",
|
||||
"example.com",
|
||||
1,
|
||||
"https://example.com/2",
|
||||
null,
|
||||
Timestamp.from(Instant.parse("2020-01-01T00:00:00Z"))
|
||||
)
|
||||
values(
|
||||
3,
|
||||
"emoji3",
|
||||
"example.com",
|
||||
1,
|
||||
"https://example.com/3",
|
||||
null,
|
||||
Timestamp.from(Instant.parse("2020-01-01T00:00:00Z"))
|
||||
)
|
||||
}
|
||||
}.launch()
|
||||
|
||||
val expected = listOf(
|
||||
CustomEmoji(
|
||||
CustomEmojiId(1),
|
||||
"emoji",
|
||||
Domain("example.com"),
|
||||
InstanceId(1),
|
||||
URI.create("https://example.com/1"),
|
||||
null,
|
||||
Instant.parse("2020-01-01T00:00:00Z")
|
||||
), CustomEmoji(
|
||||
CustomEmojiId(2),
|
||||
"emoji2",
|
||||
Domain("example.com"),
|
||||
InstanceId(1),
|
||||
URI.create("https://example.com/2"),
|
||||
null,
|
||||
Instant.parse("2020-01-01T00:00:00Z")
|
||||
)
|
||||
)
|
||||
|
||||
val actual = ExposedCustomEmojiRepository().findByNamesAndDomain(listOf("emoji", "emoji2"), "example.com")
|
||||
|
||||
assertContentEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findByIds_指定された条件全部返す() = runTest {
|
||||
dbSetup(to = dataSource) {
|
||||
execute(disableReferenceIntegrityConstraints)
|
||||
insertInto(CustomEmojis.tableName) {
|
||||
columns(CustomEmojis.columns)
|
||||
values(
|
||||
1,
|
||||
"emoji",
|
||||
"example.com",
|
||||
1,
|
||||
"https://example.com/1",
|
||||
null,
|
||||
Timestamp.from(Instant.parse("2020-01-01T00:00:00Z"))
|
||||
)
|
||||
values(
|
||||
2,
|
||||
"emoji2",
|
||||
"example.com",
|
||||
1,
|
||||
"https://example.com/2",
|
||||
null,
|
||||
Timestamp.from(Instant.parse("2020-01-01T00:00:00Z"))
|
||||
)
|
||||
values(
|
||||
3,
|
||||
"emoji3",
|
||||
"example.com",
|
||||
1,
|
||||
"https://example.com/3",
|
||||
null,
|
||||
Timestamp.from(Instant.parse("2020-01-01T00:00:00Z"))
|
||||
)
|
||||
}
|
||||
}.launch()
|
||||
|
||||
val expected = listOf(
|
||||
CustomEmoji(
|
||||
CustomEmojiId(1),
|
||||
"emoji",
|
||||
Domain("example.com"),
|
||||
InstanceId(1),
|
||||
URI.create("https://example.com/1"),
|
||||
null,
|
||||
Instant.parse("2020-01-01T00:00:00Z")
|
||||
), CustomEmoji(
|
||||
CustomEmojiId(3),
|
||||
"emoji3",
|
||||
Domain("example.com"),
|
||||
InstanceId(1),
|
||||
URI.create("https://example.com/3"),
|
||||
null,
|
||||
Instant.parse("2020-01-01T00:00:00Z")
|
||||
)
|
||||
)
|
||||
|
||||
val actual = ExposedCustomEmojiRepository().findByIds(listOf(1, 3))
|
||||
|
||||
assertContentEquals(expected, actual)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,280 @@
|
|||
package dev.usbharu.hideout.core.infrastructure.exposedrepository
|
||||
|
||||
import com.ninja_squad.dbsetup_kotlin.dbSetup
|
||||
import dev.usbharu.hideout.core.domain.model.filter.*
|
||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
||||
import dev.usbharu.hideout.core.infrastructure.exposed.FilterQueryMapper
|
||||
import dev.usbharu.hideout.core.infrastructure.exposed.FilterResultRowMapper
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.assertj.db.api.Assertions.assertThat
|
||||
import org.assertj.db.type.Changes
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.mockito.InjectMocks
|
||||
import org.mockito.Spy
|
||||
import org.mockito.junit.jupiter.MockitoExtension
|
||||
import utils.*
|
||||
import kotlin.test.assertContentEquals
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertNull
|
||||
|
||||
@ExtendWith(MockitoExtension::class)
|
||||
class ExposedFilterRepositoryTest : AbstractRepositoryTest(Filters) {
|
||||
|
||||
@InjectMocks
|
||||
lateinit var repository: ExposedFilterRepository
|
||||
|
||||
@Spy
|
||||
val filterQueryMapper: FilterQueryMapper = FilterQueryMapper(FilterResultRowMapper())
|
||||
|
||||
@Test
|
||||
fun save_idが同じレコードが存在しないとinsert() = runTest {
|
||||
dbSetup(to = dataSource) {
|
||||
execute(disableReferenceIntegrityConstraints)
|
||||
insertInto(UserDetails.tableName) {
|
||||
columns(UserDetails.columns)
|
||||
values(1, 2, "VeeeeeeeeeeeeeeeeryStrongPassword", false, null, null)
|
||||
}
|
||||
execute(enableReferenceIntegrityConstraints)
|
||||
}.launch()
|
||||
|
||||
val filter = Filter(
|
||||
FilterId(1),
|
||||
UserDetailId(1),
|
||||
FilterName("filter"),
|
||||
setOf(),
|
||||
FilterAction.HIDE,
|
||||
setOf(FilterKeyword(FilterKeywordId(1), FilterKeywordKeyword("keyword"), FilterMode.NONE))
|
||||
)
|
||||
repository.save(filter)
|
||||
|
||||
assertThat(assertTable).row(0).isEqualTo(Filters.id, filter.id.id)
|
||||
.isEqualTo(Filters.userId, filter.userDetailId.id).isEqualTo(Filters.name, filter.name.name)
|
||||
.isEqualTo(Filters.filterAction, filter.filterAction.name)
|
||||
.isEqualTo(Filters.context, filter.filterContext.joinToString(",") { it.name })
|
||||
|
||||
assertThat(getTable(FilterKeywords.tableName)).row(0)
|
||||
.isEqualTo(FilterKeywords.id, filter.filterKeywords.first().id.id)
|
||||
.isEqualTo(FilterKeywords.filterId, filter.id.id)
|
||||
.isEqualTo(FilterKeywords.keyword, filter.filterKeywords.first().keyword.keyword)
|
||||
.isEqualTo(FilterKeywords.mode, filter.filterKeywords.first().mode.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun save_idが同じレコードが存在したらupdate() = runTest {
|
||||
dbSetup(to = dataSource) {
|
||||
execute(disableReferenceIntegrityConstraints)
|
||||
insertInto(UserDetails.tableName) {
|
||||
columns(UserDetails.columns)
|
||||
values(1, 2, "VeeeeeeeeeeeeeeeeryStrongPassword", false, null, null)
|
||||
}
|
||||
insertInto(Filters.tableName) {
|
||||
columns(Filters.columns)
|
||||
values(1, 1, "name", "", "WARN")
|
||||
}
|
||||
insertInto(FilterKeywords.tableName) {
|
||||
columns(FilterKeywords.columns)
|
||||
values(1, 1, "aaaaaaaaaaaaaaaaa", "REGEX")
|
||||
}
|
||||
execute(enableReferenceIntegrityConstraints)
|
||||
}.launch()
|
||||
|
||||
val filter = Filter(
|
||||
FilterId(1),
|
||||
UserDetailId(1),
|
||||
FilterName("filter"),
|
||||
setOf(),
|
||||
FilterAction.HIDE,
|
||||
setOf(FilterKeyword(FilterKeywordId(1), FilterKeywordKeyword("keyword"), FilterMode.NONE))
|
||||
)
|
||||
repository.save(filter)
|
||||
|
||||
assertThat(assertTable).row(0).isEqualTo(Filters.id, filter.id.id)
|
||||
.isEqualTo(Filters.userId, filter.userDetailId.id).isEqualTo(Filters.name, filter.name.name)
|
||||
.isEqualTo(Filters.filterAction, filter.filterAction.name)
|
||||
.isEqualTo(Filters.context, filter.filterContext.joinToString(",") { it.name })
|
||||
|
||||
assertThat(getTable(FilterKeywords.tableName)).row(0)
|
||||
.isEqualTo(FilterKeywords.id, filter.filterKeywords.first().id.id)
|
||||
.isEqualTo(FilterKeywords.filterId, filter.id.id)
|
||||
.isEqualTo(FilterKeywords.keyword, filter.filterKeywords.first().keyword.keyword)
|
||||
.isEqualTo(FilterKeywords.mode, filter.filterKeywords.first().mode.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun delete_削除される() = runTest {
|
||||
dbSetup(to = dataSource) {
|
||||
execute(disableReferenceIntegrityConstraints)
|
||||
insertInto(UserDetails.tableName) {
|
||||
columns(UserDetails.columns)
|
||||
values(1, 2, "VeeeeeeeeeeeeeeeeryStrongPassword", false, null, null)
|
||||
}
|
||||
insertInto(Filters.tableName) {
|
||||
columns(Filters.columns)
|
||||
values(1, 1, "name", "", "WARN")
|
||||
}
|
||||
insertInto(FilterKeywords.tableName) {
|
||||
columns(FilterKeywords.columns)
|
||||
values(1, 1, "aaaaaaaaaaaaaaaaa", "REGEX")
|
||||
}
|
||||
execute(enableReferenceIntegrityConstraints)
|
||||
}.launch()
|
||||
|
||||
val filter = Filter(
|
||||
FilterId(1),
|
||||
UserDetailId(1),
|
||||
FilterName("filter"),
|
||||
setOf(),
|
||||
FilterAction.HIDE,
|
||||
setOf(FilterKeyword(FilterKeywordId(1), FilterKeywordKeyword("keyword"), FilterMode.NONE))
|
||||
)
|
||||
|
||||
val changes = Changes(dataSource)
|
||||
changes.withSuspend {
|
||||
repository.delete(filter)
|
||||
}
|
||||
|
||||
assertThat(changes).changeOfDeletionOnTable(Filters.tableName).rowAtStartPoint().value(Filters.id.name)
|
||||
.isEqualTo(filter.id.id).changeOfDeletionOnTable(FilterKeywords.tableName).rowAtStartPoint()
|
||||
.value(FilterKeywords.id.name).isEqualTo(filter.filterKeywords.first().id.id)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findByFilterKeywordId_指定された条件で存在したら返す() = runTest {
|
||||
dbSetup(to = dataSource) {
|
||||
execute(disableReferenceIntegrityConstraints)
|
||||
|
||||
insertInto(Filters.tableName) {
|
||||
columns(Filters.columns)
|
||||
values(1, 1, "name", "PUBLIC", "WARN")
|
||||
}
|
||||
insertInto(FilterKeywords.tableName) {
|
||||
columns(FilterKeywords.columns)
|
||||
values(1, 1, "keyword", "REGEX")
|
||||
}
|
||||
|
||||
execute(enableReferenceIntegrityConstraints)
|
||||
}.launch()
|
||||
|
||||
val expected = Filter(
|
||||
FilterId(1),
|
||||
UserDetailId(1),
|
||||
FilterName("name"),
|
||||
setOf(FilterContext.PUBLIC),
|
||||
FilterAction.WARN,
|
||||
setOf(FilterKeyword(FilterKeywordId(1), FilterKeywordKeyword("keyword"), FilterMode.REGEX))
|
||||
)
|
||||
|
||||
val actual = repository.findByFilterKeywordId(FilterKeywordId(1))
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
private fun assertEquals(
|
||||
expected: Filter, actual: Filter?
|
||||
) {
|
||||
kotlin.test.assertEquals(expected, actual)
|
||||
assertNotNull(actual)
|
||||
assertEquals(expected.id, actual.id)
|
||||
assertEquals(expected.name, actual.name)
|
||||
assertContentEquals(expected.filterContext, actual.filterContext.asIterable())
|
||||
assertEquals(expected.userDetailId, actual.userDetailId)
|
||||
assertEquals(expected.filterKeywords.size, actual.filterKeywords.size)
|
||||
assertContentEquals(expected.filterKeywords, actual.filterKeywords.asIterable())
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun findByFilterKeywordId_指定された条件で存在しないとnull() = runTest {
|
||||
assertNull(repository.findByFilterKeywordId(FilterKeywordId(1)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findByFilterId_指定された条件で存在したら返す() = runTest {
|
||||
dbSetup(to = dataSource) {
|
||||
execute(disableReferenceIntegrityConstraints)
|
||||
|
||||
insertInto(Filters.tableName) {
|
||||
columns(Filters.columns)
|
||||
values(1, 1, "name", "PUBLIC", "WARN")
|
||||
}
|
||||
insertInto(FilterKeywords.tableName) {
|
||||
columns(FilterKeywords.columns)
|
||||
values(1, 1, "keyword", "REGEX")
|
||||
}
|
||||
|
||||
execute(enableReferenceIntegrityConstraints)
|
||||
}.launch()
|
||||
|
||||
val expected = Filter(
|
||||
FilterId(1),
|
||||
UserDetailId(1),
|
||||
FilterName("name"),
|
||||
setOf(FilterContext.PUBLIC),
|
||||
FilterAction.WARN,
|
||||
setOf(FilterKeyword(FilterKeywordId(1), FilterKeywordKeyword("keyword"), FilterMode.REGEX))
|
||||
)
|
||||
|
||||
val actual = repository.findByFilterId(FilterId(1))
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findByFilterId_指定された条件で存在しないとnull() = runTest {
|
||||
assertNull(repository.findByFilterId(FilterId(1)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findByUserDetailId_指定された条件全部返す() = runTest {
|
||||
dbSetup(to = dataSource) {
|
||||
execute(disableReferenceIntegrityConstraints)
|
||||
|
||||
insertInto(Filters.tableName) {
|
||||
columns(Filters.columns)
|
||||
values(1, 1, "name", "PUBLIC", "WARN")
|
||||
values(2, 1, "name2", "PUBLIC", "WARN")
|
||||
values(3, 1, "name3", "PUBLIC", "HIDE")
|
||||
}
|
||||
insertInto(FilterKeywords.tableName) {
|
||||
columns(FilterKeywords.columns)
|
||||
values(1, 1, "keyword", "REGEX")
|
||||
values(2, 2, "keyword2", "REGEX")
|
||||
values(3, 1, "keyword3", "REGEX")
|
||||
}
|
||||
|
||||
execute(enableReferenceIntegrityConstraints)
|
||||
}.launch()
|
||||
|
||||
val expected = listOf(
|
||||
Filter(
|
||||
FilterId(1), UserDetailId(1), FilterName("name"), setOf(FilterContext.PUBLIC), FilterAction.WARN, setOf(
|
||||
FilterKeyword(FilterKeywordId(1), FilterKeywordKeyword("keyword"), FilterMode.REGEX),
|
||||
FilterKeyword(FilterKeywordId(3), FilterKeywordKeyword("keyword3"), FilterMode.REGEX)
|
||||
)
|
||||
), Filter(
|
||||
FilterId(2),
|
||||
UserDetailId(1),
|
||||
FilterName("name2"),
|
||||
setOf(FilterContext.PUBLIC),
|
||||
FilterAction.WARN,
|
||||
setOf(
|
||||
FilterKeyword(FilterKeywordId(2), FilterKeywordKeyword("keyword2"), FilterMode.REGEX)
|
||||
)
|
||||
), Filter(
|
||||
FilterId(3),
|
||||
UserDetailId(1),
|
||||
FilterName("name3"),
|
||||
setOf(FilterContext.PUBLIC),
|
||||
FilterAction.HIDE,
|
||||
setOf(
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val actual = repository.findByUserDetailId(UserDetailId(1))
|
||||
|
||||
assertContentEquals(expected, actual)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue