mirror of https://github.com/usbharu/Hideout.git
test: ExposedTimelineRepositoryのテストを追加
This commit is contained in:
parent
daae3b2912
commit
24e97abf3f
|
@ -26,6 +26,20 @@ class Timeline(
|
|||
addDomainEvent(TimelineEventFactory(this).createEvent(TimelineEvent.CHANGE_VISIBILITY))
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as Timeline
|
||||
|
||||
return id == other.id
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return id.hashCode()
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
fun create(
|
||||
id: TimelineId,
|
||||
|
|
|
@ -8,16 +8,17 @@ import dev.usbharu.hideout.core.domain.model.timeline.TimelineVisibility
|
|||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
||||
import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventPublisher
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.db.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.mockito.InjectMocks
|
||||
import org.mockito.Mock
|
||||
import org.mockito.junit.jupiter.MockitoExtension
|
||||
import utils.AbstractRepositoryTest
|
||||
import utils.columns
|
||||
import utils.disableReferenceIntegrityConstraints
|
||||
import utils.isEqualTo
|
||||
import utils.*
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertNull
|
||||
|
||||
@ExtendWith(MockitoExtension::class)
|
||||
class ExposedTimelineRepositoryTest : AbstractRepositoryTest(Timelines) {
|
||||
|
@ -87,4 +88,105 @@ class ExposedTimelineRepositoryTest : AbstractRepositoryTest(Timelines) {
|
|||
.isEqualTo(Timelines.visibility, timeline.visibility.name)
|
||||
.isEqualTo(Timelines.isSystem, timeline.isSystem)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun delete_削除される() = runTest {
|
||||
dbSetup(to = dataSource) {
|
||||
execute(disableReferenceIntegrityConstraints)
|
||||
insertInto(UserDetails.tableName) {
|
||||
columns(UserDetails.columns)
|
||||
values(1, 1, "veeeeeeeeeeeeeeryStrongPassword", true, null, null)
|
||||
}
|
||||
insertInto(Timelines.tableName) {
|
||||
columns(Timelines.columns)
|
||||
values(1, 1, "test-timeline", "PUBLIC", true)
|
||||
}
|
||||
|
||||
}.launch()
|
||||
val timeline = Timeline(
|
||||
id = TimelineId(1),
|
||||
userDetailId = UserDetailId(1),
|
||||
name = TimelineName("timeline"),
|
||||
visibility = TimelineVisibility.PRIVATE,
|
||||
isSystem = false
|
||||
)
|
||||
|
||||
change.withSuspend {
|
||||
repository.delete(timeline)
|
||||
}
|
||||
|
||||
assertThat(change)
|
||||
.changeOfDeletionOnTable(Timelines.tableName)
|
||||
.rowAtStartPoint()
|
||||
.value(Timelines.id.name).isEqualTo(timeline.id.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findByIds_指定されたIdすべて返す() = runTest {
|
||||
dbSetup(to = dataSource) {
|
||||
execute(disableReferenceIntegrityConstraints)
|
||||
insertInto(Timelines.tableName) {
|
||||
columns(Timelines.columns)
|
||||
values(1, 1, "test-timeline", "PUBLIC", true)
|
||||
values(2, 1, "test-timeline2", "PUBLIC", true)
|
||||
values(3, 1, "test-timeline3", "PUBLIC", true)
|
||||
}
|
||||
}.launch()
|
||||
|
||||
val findByIds = repository.findByIds(listOf(TimelineId(1), TimelineId(3)))
|
||||
|
||||
assertThat(findByIds)
|
||||
.hasSize(2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findById_指定されたIdが存在したら返す() = runTest {
|
||||
dbSetup(to = dataSource) {
|
||||
execute(disableReferenceIntegrityConstraints)
|
||||
insertInto(Timelines.tableName) {
|
||||
columns(Timelines.columns)
|
||||
values(1, 1, "test-timeline", "PUBLIC", true)
|
||||
values(2, 1, "test-timeline2", "PUBLIC", true)
|
||||
values(3, 1, "test-timeline3", "PUBLIC", true)
|
||||
}
|
||||
}.launch()
|
||||
|
||||
val actual = repository.findById(TimelineId(1))
|
||||
|
||||
val expected = Timeline(
|
||||
TimelineId(1), UserDetailId(1), TimelineName("test-timeline"), TimelineVisibility.PUBLIC, true
|
||||
)
|
||||
|
||||
assertEquals(expected, actual)
|
||||
assertNotNull(actual)
|
||||
assertEquals(expected.id, actual.id)
|
||||
assertEquals(expected.userDetailId, actual.userDetailId)
|
||||
assertEquals(expected.name, actual.name)
|
||||
assertEquals(expected.visibility, actual.visibility)
|
||||
assertEquals(expected.isSystem, actual.isSystem)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findById_指定されたIdがなければnull() = runTest {
|
||||
assertNull(repository.findById(TimelineId(1)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findAllByUserDetailIdANdVisibilityIn_指定されたVisibilityで指定されたUserDetailId全部返す() = runTest {
|
||||
dbSetup(to = dataSource) {
|
||||
execute(disableReferenceIntegrityConstraints)
|
||||
insertInto(Timelines.tableName) {
|
||||
columns(Timelines.columns)
|
||||
values(1, 1, "test-timeline", "PUBLIC", true)
|
||||
values(2, 1, "test-timeline2", "PRIVATE", true)
|
||||
values(3, 1, "test-timeline3", "PUBLIC", true)
|
||||
}
|
||||
}.launch()
|
||||
|
||||
val timelines =
|
||||
repository.findAllByUserDetailIdAndVisibilityIn(UserDetailId(1), listOf(TimelineVisibility.PUBLIC))
|
||||
|
||||
assertThat(timelines)
|
||||
.hasSize(2)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue