diff --git a/src/main/java/net/teumteum/user/service/UserService.java b/src/main/java/net/teumteum/user/service/UserService.java index 55ccc3ed..90849cf2 100644 --- a/src/main/java/net/teumteum/user/service/UserService.java +++ b/src/main/java/net/teumteum/user/service/UserService.java @@ -14,6 +14,7 @@ import net.teumteum.user.domain.response.FriendsResponse; import net.teumteum.user.domain.response.InterestQuestionResponse; import net.teumteum.user.domain.response.UserGetResponse; +import net.teumteum.user.domain.response.UserMeGetResponse; import net.teumteum.user.domain.response.UserRegisterResponse; import net.teumteum.user.domain.response.UsersGetByIdResponse; import org.springframework.stereotype.Service; @@ -35,6 +36,10 @@ public UserGetResponse getUserById(Long userId) { return UserGetResponse.of(existUser); } + public UserMeGetResponse getMe(Long userId) { + return UserMeGetResponse.of(getUser(userId)); + } + public UsersGetByIdResponse getUsersById(List userIds) { var existUsers = userRepository.findAllById(userIds); diff --git a/src/test/java/net/teumteum/integration/UserIntegrationTest.java b/src/test/java/net/teumteum/integration/UserIntegrationTest.java index 638f3712..502f133f 100644 --- a/src/test/java/net/teumteum/integration/UserIntegrationTest.java +++ b/src/test/java/net/teumteum/integration/UserIntegrationTest.java @@ -2,18 +2,17 @@ import static org.assertj.core.api.Assertions.assertThatCode; -import java.util.List; import net.teumteum.core.error.ErrorResponse; import net.teumteum.user.domain.User; -import net.teumteum.user.domain.response.FriendsResponse; -import net.teumteum.user.domain.response.UserGetResponse; -import net.teumteum.user.domain.response.UserRegisterResponse; -import net.teumteum.user.domain.response.UsersGetByIdResponse; +import net.teumteum.user.domain.response.UserMeGetResponse; +import net.teumteum.user.domain.response.*; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import java.util.List; + @DisplayName("유저 통합테스트의") class UserIntegrationTest extends IntegrationTest { @@ -108,6 +107,32 @@ void Return_400_bad_request_if_empty_user_ids_input() { } } + @Nested + @DisplayName("내 정보 조회 API는") + class Find_my_info_api { + + @Test + @DisplayName("유효한 토큰이 주어지면, 내 정보를 응답한다.") + void Return_my_info_if_valid_token_received() { + // given + var me = repository.saveAndGetUser(); + loginContext.setUserId(me.getId()); + + var expected = UserMeGetResponse.of(me); + + // when + var result = api.getUser(VALID_TOKEN, me.getId()); + + // then + Assertions.assertThat(result.expectStatus().isOk() + .expectBody(UserMeGetResponse.class) + .returnResult() + .getResponseBody()) + .usingRecursiveComparison().isEqualTo(expected); + } + + } + @Nested @DisplayName("유저 수정 API는") class Update_user_api {