-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat, hotfix : 회원탈퇴 api 추가 및 redisTemplate 수정 (#170)
* feat, hotfix : 회원탈퇴 api 추가 및 redisTemplate 수정 * feat : 경로 추가
- Loading branch information
Showing
4 changed files
with
55 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
package com.example.sinitto.auth.service; | ||
|
||
import com.example.sinitto.common.exception.InvalidJwtException; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.mockito.junit.jupiter.MockitoSettings; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.data.redis.core.HashOperations; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.core.ValueOperations; | ||
|
||
import javax.crypto.spec.SecretKeySpec; | ||
import java.security.Key; | ||
import java.util.Base64; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
@@ -22,10 +17,10 @@ | |
@MockitoSettings | ||
public class TokenServiceTest { | ||
@Mock | ||
private RedisTemplate<String, String> redisTemplate; | ||
private RedisTemplate<String, Object> redisTemplate; | ||
|
||
@Mock | ||
private ValueOperations<String, String> valueOperations; | ||
private HashOperations<String, Object, Object> hashOperations; | ||
|
||
private TokenService tokenService; | ||
|
||
|
@@ -60,7 +55,7 @@ void generateRefreshTokenTest() { | |
//given | ||
String email = "[email protected]"; | ||
|
||
when(redisTemplate.opsForValue()).thenReturn(valueOperations); | ||
when(redisTemplate.opsForHash()).thenReturn(hashOperations); | ||
|
||
//when | ||
String token = tokenService.generateRefreshToken(email); | ||
|
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 |
---|---|---|
|
@@ -13,8 +13,8 @@ | |
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoSettings; | ||
import org.springframework.data.redis.core.HashOperations; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.core.ValueOperations; | ||
|
||
import java.util.Optional; | ||
|
||
|
@@ -31,9 +31,9 @@ public class MemberServiceTest { | |
@Mock | ||
TokenService tokenService; | ||
@Mock | ||
RedisTemplate<String, String> redisTemplate; | ||
RedisTemplate<String, Object> redisTemplate; | ||
@Mock | ||
private ValueOperations<String, String> valueOperations; | ||
private HashOperations<String, Object, Object> hashOperations; | ||
@InjectMocks | ||
MemberService memberService; | ||
|
||
|
@@ -61,7 +61,6 @@ void getMemberIdByTokenTestWhenNotInMemberRepository() { | |
//given | ||
String token = "testtoken"; | ||
String email = "[email protected]"; | ||
Member member = mock(Member.class); | ||
|
||
when(tokenService.extractEmailFromAccessToken(token)).thenReturn(email); | ||
when(memberRepository.findByEmail(email)).thenReturn(Optional.empty()); | ||
|
@@ -110,12 +109,14 @@ void registerNewMemberTestWhenExists() { | |
void memberLogoutTest() { | ||
//given | ||
Long memberId = 1L; | ||
String email = "[email protected]"; | ||
Member member = mock(Member.class); | ||
String storedRefreshToken = "testRefreshToken"; | ||
|
||
when(memberRepository.findById(memberId)).thenReturn(Optional.of(member)); | ||
when(redisTemplate.opsForValue()).thenReturn(valueOperations); | ||
when(redisTemplate.opsForValue().get(member.getEmail())).thenReturn(storedRefreshToken); | ||
when(member.getEmail()).thenReturn(email); | ||
when(redisTemplate.opsForHash()).thenReturn(hashOperations); | ||
when(redisTemplate.opsForHash().get(member.getEmail(), "refreshToken")).thenReturn(storedRefreshToken); | ||
//when | ||
memberService.memberLogout(memberId); | ||
|
||
|
@@ -136,4 +137,25 @@ void memberLogoutTestWhenMemberIsNull() { | |
//when, then | ||
assertThrows(NotFoundException.class, () -> memberService.memberLogout(memberId)); | ||
} | ||
|
||
@Test | ||
@DisplayName("deleteMember 메소드 테스트") | ||
void deleteMemberTest(){ | ||
//given | ||
Long memberId = 1L; | ||
String email = "[email protected]"; | ||
Member member = mock(Member.class); | ||
String storedRefreshToken = "testRefreshToken"; | ||
|
||
when(memberRepository.findById(memberId)).thenReturn(Optional.of(member)); | ||
when(member.getEmail()).thenReturn(email); | ||
when(redisTemplate.opsForHash()).thenReturn(hashOperations); | ||
when(redisTemplate.opsForHash().get(member.getEmail(), "refreshToken")).thenReturn(storedRefreshToken); | ||
|
||
//when | ||
memberService.deleteMember(memberId); | ||
|
||
//when | ||
verify(memberRepository, times(1)).deleteById(memberId); | ||
} | ||
} |