-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into NO-JIRA--junhyuk--test--card-service-test
- Loading branch information
Showing
25 changed files
with
395 additions
and
363 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
14 changes: 14 additions & 0 deletions
14
nabimarket-application/src/test/java/setup/jwt/TokenResponseDTOBuilder.java
This file contains 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,14 @@ | ||
package setup.jwt; | ||
|
||
import org.prgrms.nabimarketbe.jwt.dto.TokenResponseDTO; | ||
|
||
public class TokenResponseDTOBuilder { | ||
public static TokenResponseDTO createTestDTO() { | ||
return TokenResponseDTO.builder() | ||
.grantType("Bearer") | ||
.accessToken("testAccessToken") | ||
.refreshToken("testRefreshToken") | ||
.accessTokenExpireDate(60 * 60 * 1000L) | ||
.build(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
nabimarket-application/src/test/java/setup/user/UserBuilder.java
This file contains 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,16 @@ | ||
package setup.user; | ||
|
||
import org.prgrms.nabimarketbe.user.entity.Role; | ||
import org.prgrms.nabimarketbe.user.entity.User; | ||
|
||
public class UserBuilder { | ||
public static User createTestEntity() { | ||
return User.builder() | ||
.accountId("testAccountId") | ||
.nickname("testNickname") | ||
.role(Role.USER.getKey()) | ||
.imageUrl("testImageUrl") | ||
.provider("KAKAO") | ||
.build(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
nabimarket-application/src/test/java/setup/user/request/SocialUserInfoDTOBuilder.java
This file contains 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,12 @@ | ||
package setup.user.request; | ||
|
||
import org.prgrms.nabimarketbe.user.dto.request.SocialUserInfoDTO; | ||
|
||
public class SocialUserInfoDTOBuilder { | ||
public static SocialUserInfoDTO createTestDTO() { | ||
return SocialUserInfoDTO.builder() | ||
.accountId("testAccount") | ||
.provider("KAKAO") | ||
.build(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ket-application/src/test/java/setup/user/request/UserNicknameUpdateRequestDTOBuilder.java
This file contains 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,9 @@ | ||
package setup.user.request; | ||
|
||
import org.prgrms.nabimarketbe.user.dto.request.UserNicknameUpdateRequestDTO; | ||
|
||
public class UserNicknameUpdateRequestDTOBuilder { | ||
public static UserNicknameUpdateRequestDTO createTestDTO() { | ||
return new UserNicknameUpdateRequestDTO("testUpdateNickname"); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...rket-application/src/test/java/setup/user/request/UserProfileUpdateRequestDTOBuilder.java
This file contains 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,9 @@ | ||
package setup.user.request; | ||
|
||
import org.prgrms.nabimarketbe.user.dto.request.UserProfileUpdateRequestDTO; | ||
|
||
public class UserProfileUpdateRequestDTOBuilder { | ||
public static UserProfileUpdateRequestDTO createTestDTO() { | ||
return new UserProfileUpdateRequestDTO("testImageUrl"); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
nabimarket-application/src/test/java/user/CheckServiceTest.java
This file contains 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,71 @@ | ||
package user; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.BDDMockito.given; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.prgrms.nabimarketbe.jwt.provider.JwtProvider; | ||
import org.prgrms.nabimarketbe.user.service.CheckService; | ||
|
||
import io.jsonwebtoken.Claims; | ||
import io.jsonwebtoken.impl.DefaultClaims; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class CheckServiceTest { | ||
@InjectMocks | ||
CheckService checkService; | ||
|
||
@Mock | ||
JwtProvider jwtProvider; | ||
|
||
@DisplayName("parseToken 메소드를 호출하면 유저의 Id가 파싱된다.") | ||
@Test | ||
void parseToken_test() { | ||
// given | ||
Long expectedUserId = 1L; | ||
String token = "1L"; | ||
Claims claims = new DefaultClaims(); | ||
claims.put("sub", expectedUserId); | ||
|
||
given(jwtProvider.parseClaims(any())).willReturn(claims); | ||
|
||
// when | ||
Long userId = checkService.parseToken(token); | ||
|
||
// then | ||
assertThat(userId).isEqualTo(expectedUserId); | ||
} | ||
|
||
@DisplayName("String(유저토큰)과 Long(유저Id)이 같은지 비교한다.") | ||
@Test | ||
void isEqual_String_Long_test() { | ||
// given | ||
Long expectedUserId = 1L; | ||
String token = "1L"; | ||
Claims claims = new DefaultClaims(); | ||
claims.put("sub", expectedUserId); | ||
|
||
given(jwtProvider.parseClaims(any())).willReturn(claims); | ||
|
||
// when & then | ||
assertThat(checkService.isEqual(token, expectedUserId)).isTrue(); | ||
} | ||
|
||
@DisplayName("Long(유저1 Id)과 Long(유저2 Id)이 같은지 비교한다.") | ||
@Test | ||
void isEqual_Long_Long_test() { | ||
// given | ||
Long userOneId = 1L; | ||
Long userOneId2 = 1L; | ||
|
||
// when & then | ||
assertThat(checkService.isEqual(userOneId, userOneId2)).isTrue(); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
nabimarket-application/src/test/java/user/RandomNicknameGeneratorTest.java
This file contains 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,46 @@ | ||
package user; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.doThrow; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.prgrms.nabimarketbe.user.service.RandomNicknameGenerator; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.retry.annotation.EnableRetry; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@Import({RandomNicknameGenerator.class, ObjectMapper.class}) | ||
@EnableRetry | ||
class RandomNicknameGeneratorTest { | ||
@Autowired | ||
RandomNicknameGenerator randomNicknameGenerator; | ||
|
||
@MockBean | ||
RestTemplate restTemplate; | ||
|
||
@DisplayName("랜덤닉네임 생성 시에 RuntimeException 발생시 2번까지 재시도한다.") | ||
@Test | ||
void generateRandomNickname_with_retry() { | ||
// given | ||
doThrow(new RuntimeException("Intended Retry Error")).when(restTemplate) | ||
.getForObject(anyString(), eq(String.class)); | ||
|
||
// then | ||
assertThrows(RuntimeException.class, () -> { | ||
randomNicknameGenerator.generateRandomNickname(); | ||
}); | ||
verify(restTemplate, times(2)).getForObject(anyString(), eq(String.class)); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
nabimarket-application/src/test/java/user/SignServiceTest.java
This file contains 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,59 @@ | ||
package user; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.BDDMockito.given; | ||
|
||
import java.util.Optional; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.prgrms.nabimarketbe.jwt.dto.TokenResponseDTO; | ||
import org.prgrms.nabimarketbe.jwt.provider.JwtProvider; | ||
import org.prgrms.nabimarketbe.user.dto.request.SocialUserInfoDTO; | ||
import org.prgrms.nabimarketbe.user.dto.response.UserGetResponseDTO; | ||
import org.prgrms.nabimarketbe.user.dto.response.UserLoginResponseDTO; | ||
import org.prgrms.nabimarketbe.user.entity.User; | ||
import org.prgrms.nabimarketbe.user.repository.UserRepository; | ||
import org.prgrms.nabimarketbe.user.service.SignService; | ||
|
||
import setup.jwt.TokenResponseDTOBuilder; | ||
import setup.user.UserBuilder; | ||
import setup.user.request.SocialUserInfoDTOBuilder; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class SignServiceTest { | ||
@InjectMocks | ||
SignService signService; | ||
|
||
@Mock | ||
UserRepository userRepository; | ||
|
||
@Mock | ||
JwtProvider jwtProvider; | ||
|
||
@DisplayName("사용자는 소셜로그인 이후 받아온 정보로 나비장터에 로그인을 할 수 있다.") | ||
@Test | ||
void signIn_test() { | ||
// given | ||
SocialUserInfoDTO socialUserInfoDTO = SocialUserInfoDTOBuilder.createTestDTO(); | ||
User user = UserBuilder.createTestEntity(); | ||
TokenResponseDTO tokenResponseDTO = TokenResponseDTOBuilder.createTestDTO(); | ||
UserGetResponseDTO userGetResponseDTO = UserGetResponseDTO.from(user); | ||
|
||
given(userRepository.findByAccountId(any())).willReturn(Optional.ofNullable(user)); | ||
given(jwtProvider.createTokenDTO(any(), anyString())).willReturn(tokenResponseDTO); | ||
|
||
// when | ||
UserLoginResponseDTO loginResponseDTO = signService.signIn(socialUserInfoDTO); | ||
|
||
// then | ||
assertThat(loginResponseDTO.userInfo()).usingRecursiveComparison().isEqualTo(userGetResponseDTO); | ||
assertThat(loginResponseDTO.token()).usingRecursiveComparison().isEqualTo(tokenResponseDTO); | ||
} | ||
} |
Oops, something went wrong.