diff --git a/src/intTest/kotlin/mastodon/account/AccountApiPaginationTest.kt b/src/intTest/kotlin/mastodon/account/AccountApiPaginationTest.kt new file mode 100644 index 00000000..e5cede90 --- /dev/null +++ b/src/intTest/kotlin/mastodon/account/AccountApiPaginationTest.kt @@ -0,0 +1,78 @@ +package mastodon.account + +import com.fasterxml.jackson.core.type.TypeReference +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import dev.usbharu.hideout.SpringApplication +import dev.usbharu.hideout.domain.mastodon.model.generated.Notification +import dev.usbharu.hideout.domain.mastodon.model.generated.Status +import org.assertj.core.api.Assertions +import org.assertj.core.api.Assertions.assertThat +import org.flywaydb.core.Flyway +import org.junit.jupiter.api.AfterAll +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.security.core.authority.SimpleGrantedAuthority +import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors +import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers +import org.springframework.test.context.jdbc.Sql +import org.springframework.test.web.servlet.MockMvc +import org.springframework.test.web.servlet.get +import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder +import org.springframework.test.web.servlet.setup.MockMvcBuilders +import org.springframework.transaction.annotation.Transactional +import org.springframework.web.context.WebApplicationContext + +@SpringBootTest(classes = [SpringApplication::class]) +@AutoConfigureMockMvc +@Transactional +@Sql("/sql/test-user.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS) +@Sql("/sql/test-user2.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS) +@Sql("/sql/accounts/test-accounts-statuses.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS) +class AccountApiPaginationTest { + @Autowired + private lateinit var context: WebApplicationContext + + private lateinit var mockMvc: MockMvc + + @Test + fun `apiV1AccountsIdStatusesGet 投稿を取得できる`() { + val content = mockMvc + .get("/api/v1/accounts/1/statuses"){ + with( + SecurityMockMvcRequestPostProcessors.jwt() + .jwt { it.claim("uid", "1") }.authorities(SimpleGrantedAuthority("SCOPE_read")) + ) + } + .asyncDispatch() + .andExpect { status { isOk() } } + .andExpect { header { string("Link","; rel=\"next\", ; rel=\"prev\"") } } + .andReturn() + .response + .contentAsString + + val value = jacksonObjectMapper().readValue(content, object : TypeReference>() {}) + + Assertions.assertThat(value.first().id).isEqualTo("100") + Assertions.assertThat(value.last().id).isEqualTo("81") + assertThat(value).size().isEqualTo(20) + } + + @BeforeEach + fun setUp() { + mockMvc = MockMvcBuilders.webAppContextSetup(context) + .apply(SecurityMockMvcConfigurers.springSecurity()) + .build() + } + + companion object { + @JvmStatic + @AfterAll + fun dropDatabase(@Autowired flyway: Flyway) { + flyway.clean() + flyway.migrate() + } + } +} \ No newline at end of file diff --git a/src/intTest/resources/sql/accounts/test-accounts-statuses.sql b/src/intTest/resources/sql/accounts/test-accounts-statuses.sql new file mode 100644 index 00000000..10352e07 --- /dev/null +++ b/src/intTest/resources/sql/accounts/test-accounts-statuses.sql @@ -0,0 +1,202 @@ +insert into posts (id, actor_id, overview, content, text, created_at, visibility, url, repost_id, reply_id, sensitive, + ap_id, deleted) +VALUES (1, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/1', + null, null, false, 'https://example.com/users/1/posts/1', false), + (2, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/2', + null, 1, false, 'https://example.com/users/1/posts/2', false), + (3, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/3', + null, null, false, 'https://example.com/users/1/posts/3', false), + (4, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/4', + null, 3, false, 'https://example.com/users/1/posts/4', false), + (5, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/5', + null, null, false, 'https://example.com/users/1/posts/5', false), + (6, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/6', + null, null, false, 'https://example.com/users/1/posts/6', false), + (7, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/7', + null, null, false, 'https://example.com/users/1/posts/7', false), + (8, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/8', + null, 7, false, 'https://example.com/users/1/posts/8', false), + (9, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/9', + null, null, false, 'https://example.com/users/1/posts/9', false), + (10, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/10', + null, 9, false, 'https://example.com/users/1/posts/10', false), + (11, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/11', + null, null, false, 'https://example.com/users/1/posts/11', false), + (12, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/12', + null, null, false, 'https://example.com/users/1/posts/12', false), + (13, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/13', + null, null, false, 'https://example.com/users/1/posts/13', false), + (14, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/14', + null, 13, false, 'https://example.com/users/1/posts/14', false), + (15, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/15', + null, null, false, 'https://example.com/users/1/posts/15', false), + (16, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/16', + null, 15, false, 'https://example.com/users/1/posts/16', false), + (17, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/17', + null, null, false, 'https://example.com/users/1/posts/17', false), + (18, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/18', + null, null, false, 'https://example.com/users/1/posts/18', false), + (19, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/19', + null, null, false, 'https://example.com/users/1/posts/19', false), + (20, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/20', + null, 19, false, 'https://example.com/users/1/posts/20', false), + (21, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/21', + null, null, false, 'https://example.com/users/1/posts/21', false), + (22, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/22', + null, 21, false, 'https://example.com/users/1/posts/22', false), + (23, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/23', + null, null, false, 'https://example.com/users/1/posts/23', false), + (24, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/24', + null, null, false, 'https://example.com/users/1/posts/24', false), + (25, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/25', + null, null, false, 'https://example.com/users/1/posts/25', false), + (26, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/26', + null, 25, false, 'https://example.com/users/1/posts/26', false), + (27, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/27', + null, null, false, 'https://example.com/users/1/posts/27', false), + (28, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/28', + null, 27, false, 'https://example.com/users/1/posts/28', false), + (29, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/29', + null, null, false, 'https://example.com/users/1/posts/29', false), + (30, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/30', + null, null, false, 'https://example.com/users/1/posts/30', false), + (31, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/31', + null, null, false, 'https://example.com/users/1/posts/31', false), + (32, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/32', + null, 31, false, 'https://example.com/users/1/posts/32', false), + (33, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/33', + null, null, false, 'https://example.com/users/1/posts/33', false), + (34, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/34', + null, 33, false, 'https://example.com/users/1/posts/34', false), + (35, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/35', + null, null, false, 'https://example.com/users/1/posts/35', false), + (36, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/36', + null, null, false, 'https://example.com/users/1/posts/36', false), + (37, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/37', + null, null, false, 'https://example.com/users/1/posts/37', false), + (38, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/38', + null, 37, false, 'https://example.com/users/1/posts/38', false), + (39, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/39', + null, null, false, 'https://example.com/users/1/posts/39', false), + (40, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/40', + null, 39, false, 'https://example.com/users/1/posts/40', false), + (41, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/41', + null, null, false, 'https://example.com/users/1/posts/41', false), + (42, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/42', + null, null, false, 'https://example.com/users/1/posts/42', false), + (43, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/43', + null, null, false, 'https://example.com/users/1/posts/43', false), + (44, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/44', + null, 43, false, 'https://example.com/users/1/posts/44', false), + (45, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/45', + null, null, false, 'https://example.com/users/1/posts/45', false), + (46, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/46', + null, 45, false, 'https://example.com/users/1/posts/46', false), + (47, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/47', + null, null, false, 'https://example.com/users/1/posts/47', false), + (48, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/48', + null, null, false, 'https://example.com/users/1/posts/48', false), + (49, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/49', + null, null, false, 'https://example.com/users/1/posts/49', false), + (50, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/50', + null, 49, false, 'https://example.com/users/1/posts/50', false), + (51, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/51', + null, null, false, 'https://example.com/users/1/posts/51', false), + (52, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/52', + null, 51, false, 'https://example.com/users/1/posts/52', false), + (53, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/53', + null, null, false, 'https://example.com/users/1/posts/53', false), + (54, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/54', + null, null, false, 'https://example.com/users/1/posts/54', false), + (55, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/55', + null, null, false, 'https://example.com/users/1/posts/55', false), + (56, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/56', + null, 55, false, 'https://example.com/users/1/posts/56', false), + (57, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/57', + null, null, false, 'https://example.com/users/1/posts/57', false), + (58, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/58', + null, 57, false, 'https://example.com/users/1/posts/58', false), + (59, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/59', + null, null, false, 'https://example.com/users/1/posts/59', false), + (60, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/60', + null, null, false, 'https://example.com/users/1/posts/60', false), + (61, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/61', + null, null, false, 'https://example.com/users/1/posts/61', false), + (62, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/62', + null, 61, false, 'https://example.com/users/1/posts/62', false), + (63, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/63', + null, null, false, 'https://example.com/users/1/posts/63', false), + (64, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/64', + null, 63, false, 'https://example.com/users/1/posts/64', false), + (65, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/65', + null, null, false, 'https://example.com/users/1/posts/65', false), + (66, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/66', + null, null, false, 'https://example.com/users/1/posts/66', false), + (67, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/67', + null, null, false, 'https://example.com/users/1/posts/67', false), + (68, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/68', + null, 67, false, 'https://example.com/users/1/posts/68', false), + (69, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/69', + null, null, false, 'https://example.com/users/1/posts/69', false), + (70, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/70', + null, 69, false, 'https://example.com/users/1/posts/70', false), + (71, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/71', + null, null, false, 'https://example.com/users/1/posts/71', false), + (72, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/72', + null, null, false, 'https://example.com/users/1/posts/72', false), + (73, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/73', + null, null, false, 'https://example.com/users/1/posts/73', false), + (74, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/74', + null, 73, false, 'https://example.com/users/1/posts/74', false), + (75, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/75', + null, null, false, 'https://example.com/users/1/posts/75', false), + (76, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/76', + null, 75, false, 'https://example.com/users/1/posts/76', false), + (77, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/77', + null, null, false, 'https://example.com/users/1/posts/77', false), + (78, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/78', + null, null, false, 'https://example.com/users/1/posts/78', false), + (79, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/79', + null, null, false, 'https://example.com/users/1/posts/79', false), + (80, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/80', + null, 79, false, 'https://example.com/users/1/posts/80', false), + (81, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/81', + null, null, false, 'https://example.com/users/1/posts/81', false), + (82, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/82', + null, 81, false, 'https://example.com/users/1/posts/82', false), + (83, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/83', + null, null, false, 'https://example.com/users/1/posts/83', false), + (84, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/84', + null, null, false, 'https://example.com/users/1/posts/84', false), + (85, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/85', + null, null, false, 'https://example.com/users/1/posts/85', false), + (86, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/86', + null, 85, false, 'https://example.com/users/1/posts/86', false), + (87, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/87', + null, null, false, 'https://example.com/users/1/posts/87', false), + (88, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/88', + null, 87, false, 'https://example.com/users/1/posts/88', false), + (89, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/89', + null, null, false, 'https://example.com/users/1/posts/89', false), + (90, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/90', + null, null, false, 'https://example.com/users/1/posts/90', false), + (91, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/91', + null, null, false, 'https://example.com/users/1/posts/91', false), + (92, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/92', + null, 91, false, 'https://example.com/users/1/posts/92', false), + (93, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/93', + null, null, false, 'https://example.com/users/1/posts/93', false), + (94, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/94', + null, 93, false, 'https://example.com/users/1/posts/94', false), + (95, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/95', + null, null, false, 'https://example.com/users/1/posts/95', false), + (96, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/96', + null, null, false, 'https://example.com/users/1/posts/96', false), + (97, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/97', + null, null, false, 'https://example.com/users/1/posts/97', false), + (98, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/98', + null, 97, false, 'https://example.com/users/1/posts/98', false), + (99, 1, null, '

this is test

', 'this is test', 1706684146436, 2, 'https://example.com/users/1/posts/99', + null, null, false, 'https://example.com/users/1/posts/99', false), + (100, 1, null, '

this is test

', 'this is test', 1706684146436, 0, 'https://example.com/users/1/posts/100', + null, 99, false, 'https://example.com/users/1/posts/100', false); \ No newline at end of file