-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/13 user #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feature/13 user #27
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
97 changes: 97 additions & 0 deletions
97
src/test/java/ita/tinybite/domain/user/service/UserServiceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package ita.tinybite.domain.user.service; | ||
|
|
||
| import ita.tinybite.domain.user.constant.LoginType; | ||
| import ita.tinybite.domain.user.constant.UserStatus; | ||
| import ita.tinybite.domain.user.dto.req.UpdateUserReqDto; | ||
| import ita.tinybite.domain.user.dto.res.UserResDto; | ||
| import ita.tinybite.domain.user.entity.User; | ||
| import ita.tinybite.domain.user.repository.UserRepository; | ||
| import ita.tinybite.domain.user.service.fake.FakeLocationService; | ||
| import ita.tinybite.domain.user.service.fake.FakeSecurityProvider; | ||
| import ita.tinybite.global.exception.BusinessException; | ||
| 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.orm.jpa.DataJpaTest; | ||
|
|
||
| import static org.assertj.core.api.Assertions.*; | ||
|
|
||
| @DataJpaTest | ||
| class UserServiceTest { | ||
|
|
||
| @Autowired | ||
| private UserRepository userRepository; | ||
|
|
||
| // Fake 객체 | ||
| private FakeSecurityProvider securityProvider; | ||
| private FakeLocationService locationService; | ||
|
|
||
| // 테스트 객체 | ||
| private UserService userService; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| securityProvider = new FakeSecurityProvider(userRepository); | ||
| locationService = new FakeLocationService(); | ||
| userService = new UserService(securityProvider, userRepository, locationService); | ||
|
|
||
| User user = User.builder() | ||
| .email("yyytir777@gmail.com") | ||
| .nickname("임원재") | ||
| .location("분당구 정자동") | ||
| .status(UserStatus.ACTIVE) | ||
| .type(LoginType.KAKAO) | ||
| .build(); | ||
|
|
||
| userRepository.save(user); | ||
| securityProvider.setCurrentUser(user); | ||
| } | ||
|
|
||
| @Test | ||
| void getUser() { | ||
| UserResDto user = userService.getUser(); | ||
| assertThat(user).isNotNull(); | ||
| } | ||
|
|
||
| @Test | ||
| void updateUser() { | ||
| // given | ||
| UpdateUserReqDto req = new UpdateUserReqDto("updated_nickname"); | ||
|
|
||
| // when | ||
| userService.updateUser(req); | ||
|
|
||
| // then | ||
| assertThat(securityProvider.getCurrentUser().getNickname()).isEqualTo("updated_nickname"); | ||
| } | ||
|
|
||
| @Test | ||
| void updateLocation() { | ||
| // given | ||
| String latitude = "12.123145"; String longitude = "123.123123"; | ||
|
|
||
| // when | ||
| userService.updateLocation(latitude, longitude); | ||
|
|
||
| // then | ||
| assertThat(securityProvider.getCurrentUser().getLocation()).isEqualTo(locationService.getLocation(latitude, longitude)); | ||
| } | ||
|
|
||
| @Test | ||
| void deleteUser() { | ||
| // when | ||
| User currentUser = securityProvider.getCurrentUser(); | ||
| userService.deleteUser(); | ||
|
|
||
| // then | ||
| assertThat(userRepository.findById(currentUser.getUserId())).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void validateNickname() { | ||
| assertThatThrownBy(() -> userService.validateNickname("임원재")) | ||
| .isInstanceOf(BusinessException.class); | ||
|
|
||
| assertThatNoException().isThrownBy(() -> userService.validateNickname("임원재1")); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/test/java/ita/tinybite/domain/user/service/fake/FakeLocationService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package ita.tinybite.domain.user.service.fake; | ||
|
|
||
| import ita.tinybite.global.location.LocationService; | ||
|
|
||
| public class FakeLocationService extends LocationService { | ||
|
|
||
| @Override | ||
| public String getLocation(String latitude, String longitude) { | ||
| return latitude + " " + longitude; | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/test/java/ita/tinybite/domain/user/service/fake/FakeSecurityProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package ita.tinybite.domain.user.service.fake; | ||
|
|
||
| import ita.tinybite.domain.auth.service.SecurityProvider; | ||
| import ita.tinybite.domain.user.entity.User; | ||
| import ita.tinybite.domain.user.repository.UserRepository; | ||
|
|
||
| public class FakeSecurityProvider extends SecurityProvider { | ||
|
|
||
| private User currentUser; | ||
|
|
||
| public FakeSecurityProvider(UserRepository userRepository) { | ||
| super(userRepository); | ||
| } | ||
|
|
||
| public void setCurrentUser(User user) { | ||
| currentUser = user; | ||
| } | ||
|
|
||
| @Override | ||
| public User getCurrentUser() { | ||
| return currentUser; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getUser()메서드에 HTTP 매핑 어노테이션 누락 - 엔드포인트 비활성화됨.getUser()메서드에@GetMapping어노테이션이 없어서 이 엔드포인트가 HTTP 요청을 받을 수 없습니다. 의도적인 변경인지 확인이 필요합니다. 엔드포인트가 필요하다면 어노테이션을 추가해야 합니다.+ @GetMapping("/me") public APIResponse<?> getUser() { return success(userService.getUser()); }🤖 Prompt for AI Agents