test: テストをPagination APIに対応

This commit is contained in:
usbharu 2024-01-29 20:55:28 +09:00
parent 370869af62
commit 942d5d71e3
3 changed files with 177 additions and 190 deletions

View File

@ -1,6 +1,7 @@
package dev.usbharu.hideout.mastodon.interfaces.api.account
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.domain.mastodon.model.generated.AccountSource
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.setup.MockMvcBuilders
import utils.TestTransaction
import java.net.URL
@ExtendWith(MockitoExtension::class)
class MastodonAccountApiControllerTest {
@ -41,6 +43,9 @@ class MastodonAccountApiControllerTest {
@Mock
private lateinit var accountApiService: AccountApiService
@Spy
private val applicationConfig: ApplicationConfig = ApplicationConfig(URL("https://example.com"))
@InjectMocks
private lateinit var mastodonAccountApiController: MastodonAccountApiController

View File

@ -1,6 +1,8 @@
package dev.usbharu.hideout.mastodon.interfaces.api.timeline
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.domain.mastodon.model.generated.Account
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.post
import org.springframework.test.web.servlet.setup.MockMvcBuilders
import java.net.URL
@ExtendWith(MockitoExtension::class)
class MastodonTimelineApiControllerTest {
@ -31,6 +34,9 @@ class MastodonTimelineApiControllerTest {
@Mock
private lateinit var timelineApiService: TimelineApiService
@Spy
private val applicationConfig: ApplicationConfig = ApplicationConfig(URL("https://example.com"))
@InjectMocks
private lateinit var mastodonTimelineApiController: MastodonTimelineApiController
@ -41,7 +47,8 @@ class MastodonTimelineApiControllerTest {
mockMvc = MockMvcBuilders.standaloneSetup(mastodonTimelineApiController).build()
}
val statusList = listOf<Status>(
val statusList = PaginationList<Status, Long>(
listOf<Status>(
Status(
id = "",
uri = "",
@ -142,6 +149,7 @@ class MastodonTimelineApiControllerTest {
editedAt = null
)
), null, null
)
@Test
@ -156,10 +164,7 @@ class MastodonTimelineApiControllerTest {
whenever(
timelineApiService.homeTimeline(
eq(1234),
eq(123456),
eq(54321),
eq(1234567),
eq(20)
any()
)
).doReturn(statusList)
@ -183,10 +188,7 @@ class MastodonTimelineApiControllerTest {
whenever(
timelineApiService.homeTimeline(
eq(1234),
isNull(),
isNull(),
isNull(),
eq(20)
any()
)
).doReturn(statusList)
@ -213,10 +215,7 @@ class MastodonTimelineApiControllerTest {
localOnly = eq(false),
remoteOnly = eq(true),
mediaOnly = eq(false),
maxId = eq(1234),
minId = eq(4321),
sinceId = eq(12345),
limit = eq(20)
any()
)
).doAnswer {
println(it.arguments.joinToString())
@ -245,10 +244,7 @@ class MastodonTimelineApiControllerTest {
localOnly = eq(false),
remoteOnly = eq(false),
mediaOnly = eq(false),
maxId = isNull(),
minId = isNull(),
sinceId = isNull(),
limit = eq(20)
any()
)
).doAnswer {
println(it.arguments.joinToString())

View File

@ -1,6 +1,8 @@
package dev.usbharu.hideout.mastodon.service.account
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.relationship.RelationshipRepository
import dev.usbharu.hideout.core.query.FollowerQueryService
@ -55,7 +57,8 @@ class AccountApiServiceImplTest {
@InjectMocks
private lateinit var accountApiServiceImpl: AccountApiServiceImpl
private val statusList = listOf(
private val statusList = PaginationList<Status, Long>(
listOf(
Status(
id = "",
uri = "",
@ -105,6 +108,7 @@ class AccountApiServiceImplTest {
text = "Test",
editedAt = null
)
), null, null
)
@Test
@ -114,16 +118,13 @@ class AccountApiServiceImplTest {
whenever(
statusQueryService.accountsStatus(
accountId = eq(userId),
maxId = isNull(),
sinceId = isNull(),
minId = isNull(),
limit = eq(20),
onlyMedia = eq(false),
excludeReplies = eq(false),
excludeReblogs = eq(false),
pinned = eq(false),
tagged = isNull(),
includeFollowers = eq(false)
includeFollowers = eq(false),
page = any()
)
).doReturn(
statusList
@ -132,16 +133,13 @@ class AccountApiServiceImplTest {
val accountsStatuses = accountApiServiceImpl.accountsStatuses(
userid = userId,
maxId = null,
sinceId = null,
minId = null,
limit = 20,
onlyMedia = false,
excludeReplies = false,
excludeReblogs = false,
pinned = false,
tagged = null,
loginUser = null
loginUser = null,
Page.of()
)
assertThat(accountsStatuses).hasSize(1)
@ -156,31 +154,25 @@ class AccountApiServiceImplTest {
whenever(
statusQueryService.accountsStatus(
accountId = eq(userId),
maxId = isNull(),
sinceId = isNull(),
minId = isNull(),
limit = eq(20),
onlyMedia = eq(false),
excludeReplies = eq(false),
excludeReblogs = eq(false),
pinned = eq(false),
tagged = isNull(),
includeFollowers = eq(false)
includeFollowers = eq(false),
page = any()
)
).doReturn(statusList)
val accountsStatuses = accountApiServiceImpl.accountsStatuses(
userid = userId,
maxId = null,
sinceId = null,
minId = null,
limit = 20,
onlyMedia = false,
excludeReplies = false,
excludeReblogs = false,
pinned = false,
tagged = null,
loginUser = loginUser
loginUser = loginUser,
Page.of()
)
assertThat(accountsStatuses).hasSize(1)
@ -193,16 +185,13 @@ class AccountApiServiceImplTest {
whenever(
statusQueryService.accountsStatus(
accountId = eq(userId),
maxId = isNull(),
sinceId = isNull(),
minId = isNull(),
limit = eq(20),
onlyMedia = eq(false),
excludeReplies = eq(false),
excludeReblogs = eq(false),
pinned = eq(false),
tagged = isNull(),
includeFollowers = eq(true)
includeFollowers = eq(true),
page = any()
)
).doReturn(statusList)
@ -221,16 +210,13 @@ class AccountApiServiceImplTest {
val accountsStatuses = accountApiServiceImpl.accountsStatuses(
userid = userId,
maxId = null,
sinceId = null,
minId = null,
limit = 20,
onlyMedia = false,
excludeReplies = false,
excludeReblogs = false,
pinned = false,
tagged = null,
loginUser = loginUser
loginUser = loginUser,
Page.of()
)
assertThat(accountsStatuses).hasSize(1)