Skip to content

Commit

Permalink
PET-300 fix : 요청을 보낸 사용자 정보 조회시 static 메소드로 호출하지 않도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
tlarbals824 committed Feb 8, 2024
1 parent 607e913 commit 4d0f9f0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
public class UserAuthorityGetUseCase {

private final UserAuthorityQueryService userAuthorityQueryService;
private final UserUtils userUtils;

public UserAuthorityInfoResponse getUserAuthority() {
final Long userId = UserUtils.getIdFromAccessUser();
final Long userId = userUtils.getIdFromAccessUser();
final UserAuthority userAuthority = userAuthorityQueryService.findByUserId(userId);
return new UserAuthorityInfoResponse(userAuthority.getAuthority());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.pawith.userapplication.dto.response.UserAuthorityInfoResponse;
import com.pawith.userdomain.entity.UserAuthority;
import com.pawith.userdomain.service.UserAuthorityQueryService;
import com.pawith.userdomain.utils.UserUtils;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -20,13 +21,14 @@
class UserAuthorityGetUseCaseTest {

@Mock
UserAuthorityQueryService userAuthorityQueryService;
private UserAuthorityQueryService userAuthorityQueryService;
@Mock
private UserUtils userUtils;

UserAuthorityGetUseCase userAuthorityGetUseCase;

@BeforeEach
void init() {
userAuthorityGetUseCase = new UserAuthorityGetUseCase(userAuthorityQueryService);
userAuthorityGetUseCase = new UserAuthorityGetUseCase(userAuthorityQueryService, userUtils);
}

@Test
Expand All @@ -37,6 +39,7 @@ void getUserAuthority() {
final UserAuthority userAuthority = FixtureMonkeyUtils.getReflectionbasedFixtureMonkey()
.giveMeBuilder(UserAuthority.class)
.sample();
given(userUtils.getIdFromAccessUser()).willReturn(userAuthority.getUser().getId());
given(userAuthorityQueryService.findByUserId(anyLong())).willReturn(userAuthority);
//when
UserAuthorityInfoResponse result = userAuthorityGetUseCase.getUserAuthority();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public User getAccessUser(){
return userQueryService.findById(userId);
}

public static Long getIdFromAccessUser(){
public Long getIdFromAccessUser(){
return SecurityUtils.getAuthenticationPrincipal();
}
}

0 comments on commit 4d0f9f0

Please sign in to comment.