mirror of https://github.com/usbharu/Hideout.git
test: テストをPagination APIに対応
This commit is contained in:
parent
370869af62
commit
942d5d71e3
|
@ -1,6 +1,7 @@
|
||||||
package dev.usbharu.hideout.mastodon.interfaces.api.account
|
package dev.usbharu.hideout.mastodon.interfaces.api.account
|
||||||
|
|
||||||
import dev.usbharu.hideout.application.config.ActivityPubConfig
|
import dev.usbharu.hideout.application.config.ActivityPubConfig
|
||||||
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.core.infrastructure.springframework.security.OAuth2JwtLoginUserContextHolder
|
import dev.usbharu.hideout.core.infrastructure.springframework.security.OAuth2JwtLoginUserContextHolder
|
||||||
import dev.usbharu.hideout.domain.mastodon.model.generated.AccountSource
|
import dev.usbharu.hideout.domain.mastodon.model.generated.AccountSource
|
||||||
import dev.usbharu.hideout.domain.mastodon.model.generated.CredentialAccount
|
import dev.usbharu.hideout.domain.mastodon.model.generated.CredentialAccount
|
||||||
|
@ -26,6 +27,7 @@ import org.springframework.test.web.servlet.get
|
||||||
import org.springframework.test.web.servlet.post
|
import org.springframework.test.web.servlet.post
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders
|
||||||
import utils.TestTransaction
|
import utils.TestTransaction
|
||||||
|
import java.net.URL
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension::class)
|
@ExtendWith(MockitoExtension::class)
|
||||||
class MastodonAccountApiControllerTest {
|
class MastodonAccountApiControllerTest {
|
||||||
|
@ -41,6 +43,9 @@ class MastodonAccountApiControllerTest {
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var accountApiService: AccountApiService
|
private lateinit var accountApiService: AccountApiService
|
||||||
|
|
||||||
|
@Spy
|
||||||
|
private val applicationConfig: ApplicationConfig = ApplicationConfig(URL("https://example.com"))
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private lateinit var mastodonAccountApiController: MastodonAccountApiController
|
private lateinit var mastodonAccountApiController: MastodonAccountApiController
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package dev.usbharu.hideout.mastodon.interfaces.api.timeline
|
package dev.usbharu.hideout.mastodon.interfaces.api.timeline
|
||||||
|
|
||||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
|
import dev.usbharu.hideout.application.infrastructure.exposed.PaginationList
|
||||||
import dev.usbharu.hideout.core.infrastructure.springframework.security.OAuth2JwtLoginUserContextHolder
|
import dev.usbharu.hideout.core.infrastructure.springframework.security.OAuth2JwtLoginUserContextHolder
|
||||||
import dev.usbharu.hideout.domain.mastodon.model.generated.Account
|
import dev.usbharu.hideout.domain.mastodon.model.generated.Account
|
||||||
import dev.usbharu.hideout.domain.mastodon.model.generated.Status
|
import dev.usbharu.hideout.domain.mastodon.model.generated.Status
|
||||||
|
@ -21,6 +23,7 @@ import org.springframework.test.web.servlet.MockMvc
|
||||||
import org.springframework.test.web.servlet.get
|
import org.springframework.test.web.servlet.get
|
||||||
import org.springframework.test.web.servlet.post
|
import org.springframework.test.web.servlet.post
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders
|
||||||
|
import java.net.URL
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension::class)
|
@ExtendWith(MockitoExtension::class)
|
||||||
class MastodonTimelineApiControllerTest {
|
class MastodonTimelineApiControllerTest {
|
||||||
|
@ -31,6 +34,9 @@ class MastodonTimelineApiControllerTest {
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var timelineApiService: TimelineApiService
|
private lateinit var timelineApiService: TimelineApiService
|
||||||
|
|
||||||
|
@Spy
|
||||||
|
private val applicationConfig: ApplicationConfig = ApplicationConfig(URL("https://example.com"))
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private lateinit var mastodonTimelineApiController: MastodonTimelineApiController
|
private lateinit var mastodonTimelineApiController: MastodonTimelineApiController
|
||||||
|
|
||||||
|
@ -41,7 +47,8 @@ class MastodonTimelineApiControllerTest {
|
||||||
mockMvc = MockMvcBuilders.standaloneSetup(mastodonTimelineApiController).build()
|
mockMvc = MockMvcBuilders.standaloneSetup(mastodonTimelineApiController).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
val statusList = listOf<Status>(
|
val statusList = PaginationList<Status, Long>(
|
||||||
|
listOf<Status>(
|
||||||
Status(
|
Status(
|
||||||
id = "",
|
id = "",
|
||||||
uri = "",
|
uri = "",
|
||||||
|
@ -142,6 +149,7 @@ class MastodonTimelineApiControllerTest {
|
||||||
editedAt = null
|
editedAt = null
|
||||||
|
|
||||||
)
|
)
|
||||||
|
), null, null
|
||||||
)
|
)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -156,10 +164,7 @@ class MastodonTimelineApiControllerTest {
|
||||||
whenever(
|
whenever(
|
||||||
timelineApiService.homeTimeline(
|
timelineApiService.homeTimeline(
|
||||||
eq(1234),
|
eq(1234),
|
||||||
eq(123456),
|
any()
|
||||||
eq(54321),
|
|
||||||
eq(1234567),
|
|
||||||
eq(20)
|
|
||||||
)
|
)
|
||||||
).doReturn(statusList)
|
).doReturn(statusList)
|
||||||
|
|
||||||
|
@ -183,10 +188,7 @@ class MastodonTimelineApiControllerTest {
|
||||||
whenever(
|
whenever(
|
||||||
timelineApiService.homeTimeline(
|
timelineApiService.homeTimeline(
|
||||||
eq(1234),
|
eq(1234),
|
||||||
isNull(),
|
any()
|
||||||
isNull(),
|
|
||||||
isNull(),
|
|
||||||
eq(20)
|
|
||||||
)
|
)
|
||||||
).doReturn(statusList)
|
).doReturn(statusList)
|
||||||
|
|
||||||
|
@ -213,10 +215,7 @@ class MastodonTimelineApiControllerTest {
|
||||||
localOnly = eq(false),
|
localOnly = eq(false),
|
||||||
remoteOnly = eq(true),
|
remoteOnly = eq(true),
|
||||||
mediaOnly = eq(false),
|
mediaOnly = eq(false),
|
||||||
maxId = eq(1234),
|
any()
|
||||||
minId = eq(4321),
|
|
||||||
sinceId = eq(12345),
|
|
||||||
limit = eq(20)
|
|
||||||
)
|
)
|
||||||
).doAnswer {
|
).doAnswer {
|
||||||
println(it.arguments.joinToString())
|
println(it.arguments.joinToString())
|
||||||
|
@ -245,10 +244,7 @@ class MastodonTimelineApiControllerTest {
|
||||||
localOnly = eq(false),
|
localOnly = eq(false),
|
||||||
remoteOnly = eq(false),
|
remoteOnly = eq(false),
|
||||||
mediaOnly = eq(false),
|
mediaOnly = eq(false),
|
||||||
maxId = isNull(),
|
any()
|
||||||
minId = isNull(),
|
|
||||||
sinceId = isNull(),
|
|
||||||
limit = eq(20)
|
|
||||||
)
|
)
|
||||||
).doAnswer {
|
).doAnswer {
|
||||||
println(it.arguments.joinToString())
|
println(it.arguments.joinToString())
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package dev.usbharu.hideout.mastodon.service.account
|
package dev.usbharu.hideout.mastodon.service.account
|
||||||
|
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
|
import dev.usbharu.hideout.application.infrastructure.exposed.Page
|
||||||
|
import dev.usbharu.hideout.application.infrastructure.exposed.PaginationList
|
||||||
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
||||||
import dev.usbharu.hideout.core.query.FollowerQueryService
|
import dev.usbharu.hideout.core.query.FollowerQueryService
|
||||||
|
@ -55,7 +57,8 @@ class AccountApiServiceImplTest {
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private lateinit var accountApiServiceImpl: AccountApiServiceImpl
|
private lateinit var accountApiServiceImpl: AccountApiServiceImpl
|
||||||
|
|
||||||
private val statusList = listOf(
|
private val statusList = PaginationList<Status, Long>(
|
||||||
|
listOf(
|
||||||
Status(
|
Status(
|
||||||
id = "",
|
id = "",
|
||||||
uri = "",
|
uri = "",
|
||||||
|
@ -105,6 +108,7 @@ class AccountApiServiceImplTest {
|
||||||
text = "Test",
|
text = "Test",
|
||||||
editedAt = null
|
editedAt = null
|
||||||
)
|
)
|
||||||
|
), null, null
|
||||||
)
|
)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -114,16 +118,13 @@ class AccountApiServiceImplTest {
|
||||||
whenever(
|
whenever(
|
||||||
statusQueryService.accountsStatus(
|
statusQueryService.accountsStatus(
|
||||||
accountId = eq(userId),
|
accountId = eq(userId),
|
||||||
maxId = isNull(),
|
|
||||||
sinceId = isNull(),
|
|
||||||
minId = isNull(),
|
|
||||||
limit = eq(20),
|
|
||||||
onlyMedia = eq(false),
|
onlyMedia = eq(false),
|
||||||
excludeReplies = eq(false),
|
excludeReplies = eq(false),
|
||||||
excludeReblogs = eq(false),
|
excludeReblogs = eq(false),
|
||||||
pinned = eq(false),
|
pinned = eq(false),
|
||||||
tagged = isNull(),
|
tagged = isNull(),
|
||||||
includeFollowers = eq(false)
|
includeFollowers = eq(false),
|
||||||
|
page = any()
|
||||||
)
|
)
|
||||||
).doReturn(
|
).doReturn(
|
||||||
statusList
|
statusList
|
||||||
|
@ -132,16 +133,13 @@ class AccountApiServiceImplTest {
|
||||||
|
|
||||||
val accountsStatuses = accountApiServiceImpl.accountsStatuses(
|
val accountsStatuses = accountApiServiceImpl.accountsStatuses(
|
||||||
userid = userId,
|
userid = userId,
|
||||||
maxId = null,
|
|
||||||
sinceId = null,
|
|
||||||
minId = null,
|
|
||||||
limit = 20,
|
|
||||||
onlyMedia = false,
|
onlyMedia = false,
|
||||||
excludeReplies = false,
|
excludeReplies = false,
|
||||||
excludeReblogs = false,
|
excludeReblogs = false,
|
||||||
pinned = false,
|
pinned = false,
|
||||||
tagged = null,
|
tagged = null,
|
||||||
loginUser = null
|
loginUser = null,
|
||||||
|
Page.of()
|
||||||
)
|
)
|
||||||
|
|
||||||
assertThat(accountsStatuses).hasSize(1)
|
assertThat(accountsStatuses).hasSize(1)
|
||||||
|
@ -156,31 +154,25 @@ class AccountApiServiceImplTest {
|
||||||
whenever(
|
whenever(
|
||||||
statusQueryService.accountsStatus(
|
statusQueryService.accountsStatus(
|
||||||
accountId = eq(userId),
|
accountId = eq(userId),
|
||||||
maxId = isNull(),
|
|
||||||
sinceId = isNull(),
|
|
||||||
minId = isNull(),
|
|
||||||
limit = eq(20),
|
|
||||||
onlyMedia = eq(false),
|
onlyMedia = eq(false),
|
||||||
excludeReplies = eq(false),
|
excludeReplies = eq(false),
|
||||||
excludeReblogs = eq(false),
|
excludeReblogs = eq(false),
|
||||||
pinned = eq(false),
|
pinned = eq(false),
|
||||||
tagged = isNull(),
|
tagged = isNull(),
|
||||||
includeFollowers = eq(false)
|
includeFollowers = eq(false),
|
||||||
|
page = any()
|
||||||
)
|
)
|
||||||
).doReturn(statusList)
|
).doReturn(statusList)
|
||||||
|
|
||||||
val accountsStatuses = accountApiServiceImpl.accountsStatuses(
|
val accountsStatuses = accountApiServiceImpl.accountsStatuses(
|
||||||
userid = userId,
|
userid = userId,
|
||||||
maxId = null,
|
|
||||||
sinceId = null,
|
|
||||||
minId = null,
|
|
||||||
limit = 20,
|
|
||||||
onlyMedia = false,
|
onlyMedia = false,
|
||||||
excludeReplies = false,
|
excludeReplies = false,
|
||||||
excludeReblogs = false,
|
excludeReblogs = false,
|
||||||
pinned = false,
|
pinned = false,
|
||||||
tagged = null,
|
tagged = null,
|
||||||
loginUser = loginUser
|
loginUser = loginUser,
|
||||||
|
Page.of()
|
||||||
)
|
)
|
||||||
|
|
||||||
assertThat(accountsStatuses).hasSize(1)
|
assertThat(accountsStatuses).hasSize(1)
|
||||||
|
@ -193,16 +185,13 @@ class AccountApiServiceImplTest {
|
||||||
whenever(
|
whenever(
|
||||||
statusQueryService.accountsStatus(
|
statusQueryService.accountsStatus(
|
||||||
accountId = eq(userId),
|
accountId = eq(userId),
|
||||||
maxId = isNull(),
|
|
||||||
sinceId = isNull(),
|
|
||||||
minId = isNull(),
|
|
||||||
limit = eq(20),
|
|
||||||
onlyMedia = eq(false),
|
onlyMedia = eq(false),
|
||||||
excludeReplies = eq(false),
|
excludeReplies = eq(false),
|
||||||
excludeReblogs = eq(false),
|
excludeReblogs = eq(false),
|
||||||
pinned = eq(false),
|
pinned = eq(false),
|
||||||
tagged = isNull(),
|
tagged = isNull(),
|
||||||
includeFollowers = eq(true)
|
includeFollowers = eq(true),
|
||||||
|
page = any()
|
||||||
)
|
)
|
||||||
).doReturn(statusList)
|
).doReturn(statusList)
|
||||||
|
|
||||||
|
@ -221,16 +210,13 @@ class AccountApiServiceImplTest {
|
||||||
|
|
||||||
val accountsStatuses = accountApiServiceImpl.accountsStatuses(
|
val accountsStatuses = accountApiServiceImpl.accountsStatuses(
|
||||||
userid = userId,
|
userid = userId,
|
||||||
maxId = null,
|
|
||||||
sinceId = null,
|
|
||||||
minId = null,
|
|
||||||
limit = 20,
|
|
||||||
onlyMedia = false,
|
onlyMedia = false,
|
||||||
excludeReplies = false,
|
excludeReplies = false,
|
||||||
excludeReblogs = false,
|
excludeReblogs = false,
|
||||||
pinned = false,
|
pinned = false,
|
||||||
tagged = null,
|
tagged = null,
|
||||||
loginUser = loginUser
|
loginUser = loginUser,
|
||||||
|
Page.of()
|
||||||
)
|
)
|
||||||
|
|
||||||
assertThat(accountsStatuses).hasSize(1)
|
assertThat(accountsStatuses).hasSize(1)
|
||||||
|
|
Loading…
Reference in New Issue