mirror of https://github.com/usbharu/Hideout.git
test: フォローの結合テストを追加
This commit is contained in:
parent
6adba9894a
commit
5bef3be653
|
@ -1,8 +1,10 @@
|
|||
package mastodon.account
|
||||
|
||||
import dev.usbharu.hideout.SpringApplication
|
||||
import dev.usbharu.hideout.core.infrastructure.exposedquery.FollowerQueryServiceImpl
|
||||
import dev.usbharu.hideout.core.infrastructure.exposedquery.UserQueryServiceImpl
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.flywaydb.core.Flyway
|
||||
import org.junit.jupiter.api.AfterAll
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
|
@ -33,9 +35,13 @@ import org.springframework.web.context.WebApplicationContext
|
|||
@Sql("/sql/test-user2.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS)
|
||||
class AccountApiTest {
|
||||
|
||||
@Autowired
|
||||
private lateinit var followerQueryServiceImpl: FollowerQueryServiceImpl
|
||||
|
||||
@Autowired
|
||||
private lateinit var userQueryServiceImpl: UserQueryServiceImpl
|
||||
|
||||
|
||||
@Autowired
|
||||
private lateinit var context: WebApplicationContext
|
||||
|
||||
|
@ -259,6 +265,22 @@ class AccountApiTest {
|
|||
.andExpect { status { isForbidden() } }
|
||||
}
|
||||
|
||||
@Test
|
||||
@Sql("/sql/accounts/apiV1AccountsIdFollowPost フォローできる.sql")
|
||||
fun `apiV1AccountsIdFollowPost フォローできる`() = runTest {
|
||||
mockMvc
|
||||
.post("/api/v1/accounts/3733363/follow") {
|
||||
contentType = MediaType.APPLICATION_JSON
|
||||
with(jwt().jwt { it.claim("uid", "37335363") }.authorities(SimpleGrantedAuthority("SCOPE_write")))
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect { status { isOk() } }
|
||||
|
||||
val alreadyFollow = followerQueryServiceImpl.alreadyFollow(3733363, 37335363)
|
||||
|
||||
assertThat(alreadyFollow).isTrue()
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@AfterAll
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
hideout:
|
||||
url: "https://localhost:8080"
|
||||
url: "https://example.com"
|
||||
use-mongodb: true
|
||||
security:
|
||||
jwt:
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
insert into "USERS" (id, name, domain, screen_name, description, password, inbox, outbox, url, public_key, private_key,
|
||||
created_at, key_id, following, followers, instance)
|
||||
VALUES (3733363, 'follow-test-user-1', 'example.com', 'follow-test-user-1-name', '',
|
||||
'5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8',
|
||||
'https://example.com/users/follow-test-user-1/inbox',
|
||||
'https://example.com/users/follow-test-user-1/outbox', 'https://example.com/users/follow-test-user-1',
|
||||
'-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----',
|
||||
'-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----', 12345678,
|
||||
'https://example.com/users/follow-test-user-1#pubkey', 'https://example.com/users/follow-test-user-1/following',
|
||||
'https://example.com/users/follow-test-user-1/followers', null),
|
||||
(37335363, 'follow-test-user-2', 'example.com', 'follow-test-user-2-name', '',
|
||||
'5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8',
|
||||
'https://example.com/users/follow-test-user-2/inbox',
|
||||
'https://example.com/users/follow-test-user-2/outbox', 'https://example.com/users/follow-test-user-2',
|
||||
'-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----',
|
||||
'-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----', 12345678,
|
||||
'https://example.com/users/follow-test-user-2#pubkey', 'https://example.com/users/follow-test-user-2/following',
|
||||
'https://example.com/users/follow-test-user-2/followers', null);
|
|
@ -114,10 +114,13 @@ class UserServiceImpl(
|
|||
}
|
||||
|
||||
override suspend fun follow(id: Long, followerId: Long) {
|
||||
logger.debug("START Follow id: {} → target: {}", followerId, id)
|
||||
followerQueryService.appendFollower(id, followerId)
|
||||
if (userRepository.findFollowRequestsById(id, followerId)) {
|
||||
logger.debug("Follow request is accepted! ")
|
||||
userRepository.deleteFollowRequest(id, followerId)
|
||||
}
|
||||
logger.debug("SUCCESS Follow id: {} → target: {}", followerId, id)
|
||||
}
|
||||
|
||||
override suspend fun unfollow(id: Long, followerId: Long): Boolean {
|
||||
|
|
|
@ -31,7 +31,7 @@ create table if not exists users
|
|||
"following" varchar(1000) null,
|
||||
followers varchar(1000) null,
|
||||
"instance" bigint null,
|
||||
unique (name, domain),
|
||||
unique ("name", "domain"),
|
||||
constraint fk_users_instance__id foreign key ("instance") references instance (id) on delete restrict on update restrict
|
||||
);
|
||||
create table if not exists follow_requests
|
||||
|
|
Loading…
Reference in New Issue