-
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.
Merge pull request #30 from SWM-WeLike2Coding/test/userWithdraw
test: 회원 탈퇴 시, 상태 처리 확인 위한 테스트 코드 작성
- Loading branch information
Showing
8 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/java/com/wl2c/elswhereuserservice/domain/batch/UserWithdrawScheduler.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,29 @@ | ||
package com.wl2c.elswhereuserservice.domain.batch; | ||
|
||
import com.wl2c.elswhereuserservice.domain.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@EnableScheduling | ||
@Slf4j | ||
public class UserWithdrawScheduler { | ||
|
||
private final UserRepository userRepository; | ||
|
||
@Value("${app.user.delete-period}") | ||
private Long deletePeriod; | ||
|
||
@Scheduled(cron = "0 0 * * * *") | ||
@Transactional | ||
public void deleteInactiveUser() { | ||
userRepository.deleteAllByWithdrawnUser(deletePeriod); | ||
} | ||
|
||
} |
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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/wl2c/elswhereuserservice/domain/user/service/UserWithdrawService.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,29 @@ | ||
package com.wl2c.elswhereuserservice.domain.user.service; | ||
|
||
import com.wl2c.elswhereuserservice.domain.user.exception.UserNotFoundException; | ||
import com.wl2c.elswhereuserservice.domain.user.model.entity.User; | ||
import com.wl2c.elswhereuserservice.domain.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import static com.wl2c.elswhereuserservice.domain.user.model.UserStatus.INACTIVE; | ||
|
||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class UserWithdrawService { | ||
|
||
private final UserRepository userRepository; | ||
private final UserInfoService cacheService; | ||
|
||
@Transactional | ||
public void withdraw(Long userId) { | ||
User user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); | ||
user.changeStatus(INACTIVE); | ||
cacheService.invalidateUserInfo(userId); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
src/test/java/com/wl2c/elswhereuserservice/domain/user/service/UserWithdrawServiceTest.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,47 @@ | ||
package com.wl2c.elswhereuserservice.domain.user.service; | ||
|
||
import com.wl2c.elswhereuserservice.domain.user.model.SocialType; | ||
import com.wl2c.elswhereuserservice.domain.user.model.UserStatus; | ||
import com.wl2c.elswhereuserservice.domain.user.model.entity.User; | ||
import com.wl2c.elswhereuserservice.domain.user.repository.UserRepository; | ||
import com.wl2c.elswhereuserservice.mock.UserMock; | ||
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 java.util.Optional; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class UserWithdrawServiceTest { | ||
|
||
@Mock | ||
private UserRepository userRepository; | ||
|
||
@Mock | ||
private UserInfoService cacheService; | ||
|
||
@InjectMocks | ||
private UserWithdrawService userWithdrawService; | ||
|
||
@Test | ||
@DisplayName("회원 탈퇴 - INACTIVE로 상태 변경이 잘 되는지 확인") | ||
void withdraw() { | ||
// given | ||
User user = UserMock.create(SocialType.GOOGLE, "[email protected]"); | ||
when(userRepository.findById(user.getId())).thenReturn(Optional.of(user)); | ||
|
||
// when | ||
userWithdrawService.withdraw(user.getId()); | ||
|
||
// then | ||
assertThat(user.getUserStatus()).isEqualTo(UserStatus.INACTIVE); | ||
verify(cacheService).invalidateUserInfo(user.getId()); | ||
} | ||
} |