From aa93eea9c8529799fd8dfae8f9ff43272c948dfc Mon Sep 17 00:00:00 2001 From: gundorit Date: Wed, 23 Aug 2023 21:51:36 +0900 Subject: [PATCH 01/13] =?UTF-8?q?feat=20:=20add=20UserTestREpository.java?= =?UTF-8?q?=20to=20avoid=20=EA=B3=BC=EB=8F=84=ED=95=9C=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../umc/yourweather/repository/test/UserTestRepository.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/test/java/com/umc/yourweather/repository/test/UserTestRepository.java diff --git a/src/test/java/com/umc/yourweather/repository/test/UserTestRepository.java b/src/test/java/com/umc/yourweather/repository/test/UserTestRepository.java new file mode 100644 index 0000000..ea7fb7a --- /dev/null +++ b/src/test/java/com/umc/yourweather/repository/test/UserTestRepository.java @@ -0,0 +1,5 @@ +package com.umc.yourweather.repository.test; + +public class UserTestRepository { + +} From fd838c5986d84786c4083285a4e023c6bc55f07a Mon Sep 17 00:00:00 2001 From: gundorit Date: Wed, 23 Aug 2023 22:02:00 +0900 Subject: [PATCH 02/13] =?UTF-8?q?feat=20:=20UserRepository=20=EB=82=B4=20?= =?UTF-8?q?=EC=B6=94=EC=83=81=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/test/UserTestRepository.java | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/umc/yourweather/repository/test/UserTestRepository.java b/src/test/java/com/umc/yourweather/repository/test/UserTestRepository.java index ea7fb7a..e2de8dc 100644 --- a/src/test/java/com/umc/yourweather/repository/test/UserTestRepository.java +++ b/src/test/java/com/umc/yourweather/repository/test/UserTestRepository.java @@ -1,5 +1,48 @@ package com.umc.yourweather.repository.test; -public class UserTestRepository { +import com.umc.yourweather.domain.entity.User; +import com.umc.yourweather.repository.UserRepository; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +public class UserTestRepository implements UserRepository { + + List repository = new ArrayList<>(); + + @Override + public Optional findByEmail(String email) { + for (User user : repository) { + if (user.getEmail().equals(email)) { + return Optional.of(user); + } + } + return Optional.empty(); + } + + @Override + public Optional findByRefreshToken(String refreshToken) { + for (User user : repository) { + if (user.getEmail().equals(refreshToken)) { + return Optional.of(user); + } + } + return Optional.empty(); + } + + @Override + public User save(User user) { + repository.add(user); + return user; + } + + @Override + public void deleteExpiredUser() { + for (User user : repository) { + if (!user.isActivate()) { + repository.remove(user); + } + } + return; + } } From b37d6cf89b83d30a8a36cfc27f7d5395e73c573d Mon Sep 17 00:00:00 2001 From: gundorit Date: Wed, 23 Aug 2023 22:02:43 +0900 Subject: [PATCH 03/13] =?UTF-8?q?feat=20:=20=EC=A3=BC=EC=84=9D=20=ED=95=B4?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yourweather/service/UserServiceTest.java | 243 ++++++++++-------- 1 file changed, 133 insertions(+), 110 deletions(-) diff --git a/src/test/java/com/umc/yourweather/service/UserServiceTest.java b/src/test/java/com/umc/yourweather/service/UserServiceTest.java index 2b9397c..cf64fca 100644 --- a/src/test/java/com/umc/yourweather/service/UserServiceTest.java +++ b/src/test/java/com/umc/yourweather/service/UserServiceTest.java @@ -1,110 +1,133 @@ -//package com.umc.yourweather.service; -// -//import static org.junit.jupiter.api.Assertions.*; -// -//import com.umc.yourweather.auth.CustomUserDetails; -//import com.umc.yourweather.domain.enums.Platform; -//import com.umc.yourweather.domain.enums.Role; -//import com.umc.yourweather.domain.entity.User; -//import com.umc.yourweather.repository.UserRepository; -//import com.umc.yourweather.request.ChangePasswordRequestDto; -//import com.umc.yourweather.request.SignupRequestDto; -//import com.umc.yourweather.response.UserResponseDto; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.DisplayName; -//import org.junit.jupiter.api.Test; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.context.SpringBootTest; -// -//@SpringBootTest -//class UserServiceTest { -// -// @Autowired -// private UserService userService; -// -// @Autowired -// private UserRepository userRepository; -// -// @BeforeEach -// void setup() { -// userRepository.save(User.builder() -// .email("test@test.com") -// .password("password") -// .nickname("nickname") -// .platform(Platform.YOURWEATHER) -// .role(Role.ROLE_USER) -// .isActivate(true) -// .build()); -// } -// -// @Test -// @DisplayName("mypage 조회") -// void mypage() { -// // given -// User user = User.builder() -// .email("test@test.com") -// .password("password") -// .nickname("nickname") -// .platform(Platform.YOURWEATHER) -// .role(Role.ROLE_USER) -// .isActivate(true) -// .build(); -// -// CustomUserDetails userDetails = new CustomUserDetails(user); -// -// // when -// UserResponseDto response = userService.mypage(userDetails); -// -// // then -// assertEquals(userDetails.getUser().getEmail(), response.getEmail()); -// assertEquals(userDetails.getUser().getNickname(), response.getNickname()); -// } -// -// @Test -// @DisplayName("비밀번호 변경") -// void changePassword(){ -// // given -// ChangePasswordRequestDto request = new ChangePasswordRequestDto("password2"); -// -// User user = User.builder() -// .email("test@test.com") -// .password("password") -// .nickname("nickname") -// .platform(Platform.YOURWEATHER) -// .role(Role.ROLE_USER) -// .isActivate(true) -// .build(); -// -// CustomUserDetails userDetails = new CustomUserDetails(user); -// -// // when -// userService.changePassword(request, userDetails); -// -// // then -// User findUser = userRepository.findByEmail("test@test.com").get(); -// assertEquals(findUser.getPassword(), "password2"); -// } -// -// @Test -// @DisplayName("회원 탈퇴") -// void withdraw(){ -// //given -// User user = User.builder() -// .email("test@test.com") -// .password("password") -// .nickname("nickname") -// .platform(Platform.YOURWEATHER) -// .role(Role.ROLE_USER) -// .isActivate(true) -// .build(); -// -// CustomUserDetails userDetails = new CustomUserDetails(user); -// -// // when -// userService.withdraw(userDetails); -// -// // then -// User findUser = userRepository.findByEmail("test@test.com").get(); -// assertEquals(findUser.isActivate(), false); -// } -//} \ No newline at end of file +package com.umc.yourweather.service; + +import static org.junit.jupiter.api.Assertions.*; + +import com.umc.yourweather.auth.CustomUserDetails; +import com.umc.yourweather.domain.enums.Platform; +import com.umc.yourweather.domain.enums.Role; +import com.umc.yourweather.domain.entity.User; +import com.umc.yourweather.jwt.JwtTokenManager; +import com.umc.yourweather.repository.UserRepository; +import com.umc.yourweather.repository.test.UserTestRepository; +import com.umc.yourweather.request.ChangePasswordRequestDto; +import com.umc.yourweather.request.SignupRequestDto; +import com.umc.yourweather.response.UserResponseDto; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +class UserServiceTest { + + // 의존성 주입 최소화 + private UserRepository userRepository = new UserTestRepository(); + private UserService userService = new UserService(userRepository, + new BCryptPasswordEncoder(), new JwtTokenManager()); + + private final String secretKey = "secretKey"; + + @BeforeEach + void setup() { + userRepository.save(User.builder() + .email("test@test.com") + .password("password") + .nickname("nickname") + .platform(Platform.YOURWEATHER) + .role(Role.ROLE_USER) + .isActivate(true) + .build()); + } + + @Test + void 회원_가입을_할_수_있다() { + + } + + @Test + void 중복_이메일은_회원_가입을_할_수_없다() { + // given + SignupRequestDto request = SignupRequestDto.builder() + .email("test@test.com") + .password("password") + .nickname("nickname") + .platform(Platform.YOURWEATHER) + .build(); + + // when + // then + assertThrows(RuntimeException.class, () -> { + userService.signup(request, secretKey); + }); + } + + @Test + @DisplayName("mypage 조회") + void mypage() { + // given + User user = User.builder() + .email("test@test.com") + .password("password") + .nickname("nickname") + .platform(Platform.YOURWEATHER) + .role(Role.ROLE_USER) + .isActivate(true) + .build(); + + CustomUserDetails userDetails = new CustomUserDetails(user); + + // when + UserResponseDto response = userService.mypage(userDetails); + + // then + assertEquals(userDetails.getUser().getEmail(), response.getEmail()); + assertEquals(userDetails.getUser().getNickname(), response.getNickname()); + } + + @Test + @DisplayName("비밀번호 변경") + void changePassword() { + // given + ChangePasswordRequestDto request = new ChangePasswordRequestDto("password2"); + + User user = User.builder() + .email("test@test.com") + .password("password") + .nickname("nickname") + .platform(Platform.YOURWEATHER) + .role(Role.ROLE_USER) + .isActivate(true) + .build(); + + CustomUserDetails userDetails = new CustomUserDetails(user); + + // when + userService.changePassword(request, userDetails); + + // then + User findUser = userRepository.findByEmail("test@test.com").get(); + assertEquals(findUser.getPassword(), "password2"); + } + + @Test + @DisplayName("회원 탈퇴") + void withdraw() { + //given + User user = User.builder() + .email("test@test.com") + .password("password") + .nickname("nickname") + .platform(Platform.YOURWEATHER) + .role(Role.ROLE_USER) + .isActivate(true) + .build(); + + CustomUserDetails userDetails = new CustomUserDetails(user); + + // when + userService.withdraw(userDetails); + + // then + User findUser = userRepository.findByEmail("test@test.com").get(); + assertEquals(findUser.isActivate(), false); + } +} From 5a91cd1c56ae13d3c0c0e0b05b24b6ceb3b8d95a Mon Sep 17 00:00:00 2001 From: gundorit Date: Wed, 23 Aug 2023 22:02:59 +0900 Subject: [PATCH 04/13] =?UTF-8?q?fix=20:=20=EA=B0=84=EB=8B=A8=ED=95=9C=20?= =?UTF-8?q?=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/umc/yourweather/controller/MemoController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/umc/yourweather/controller/MemoController.java b/src/main/java/com/umc/yourweather/controller/MemoController.java index bd29358..f24cf49 100644 --- a/src/main/java/com/umc/yourweather/controller/MemoController.java +++ b/src/main/java/com/umc/yourweather/controller/MemoController.java @@ -39,7 +39,7 @@ public ResponseDto write( } @GetMapping("/daily/{weatherId}") - @Operation(summary = "하루 치 메모 반환", description = "하루치 메모 리스트를 반환하기 위한 API입니다. weather-controller에 있는 monthly API의 반환 값에 있는 weatherIzzd를 이용해서 조회합니다. ") + @Operation(summary = "하루 치 메모 반환", description = "하루치 메모 리스트를 반환하기 위한 API입니다. weather-controller에 있는 monthly API의 반환 값에 있는 weatherId를 이용해서 조회합니다. ") public ResponseDto daily(@PathVariable Long weatherId, @AuthenticationPrincipal CustomUserDetails userDetails) { From cdc4b1d62c4c8b49cad7be8c65381ea2d4dcfd46 Mon Sep 17 00:00:00 2001 From: gundorit Date: Wed, 23 Aug 2023 22:36:44 +0900 Subject: [PATCH 05/13] =?UTF-8?q?feat=20:=20Test=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=EC=9D=84=20=EC=9C=84=ED=95=9C=20JwtTokenMana?= =?UTF-8?q?ger=20=EB=82=B4=20setValue()=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/umc/yourweather/jwt/JwtTokenManager.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/umc/yourweather/jwt/JwtTokenManager.java b/src/main/java/com/umc/yourweather/jwt/JwtTokenManager.java index a8354c1..1c24be2 100644 --- a/src/main/java/com/umc/yourweather/jwt/JwtTokenManager.java +++ b/src/main/java/com/umc/yourweather/jwt/JwtTokenManager.java @@ -147,6 +147,11 @@ public boolean isRefreshTokenValid(String token) { public void updateRefreshToken(User user, String refreshToken) { user.updateRefreshToken(refreshToken); } + + public void setValue(String secretKey, Long accessTokenExpiration) { + this.secretKey = secretKey; + this.accessTokenExpiration = accessTokenExpiration; + } } From 919c216714de17fb1b7420a390453c6a967aadd0 Mon Sep 17 00:00:00 2001 From: gundorit Date: Wed, 23 Aug 2023 22:43:47 +0900 Subject: [PATCH 06/13] =?UTF-8?q?fIx=20:=20setValue()=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/umc/yourweather/jwt/JwtTokenManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/umc/yourweather/jwt/JwtTokenManager.java b/src/main/java/com/umc/yourweather/jwt/JwtTokenManager.java index 1c24be2..71b80ec 100644 --- a/src/main/java/com/umc/yourweather/jwt/JwtTokenManager.java +++ b/src/main/java/com/umc/yourweather/jwt/JwtTokenManager.java @@ -148,9 +148,10 @@ public void updateRefreshToken(User user, String refreshToken) { user.updateRefreshToken(refreshToken); } - public void setValue(String secretKey, Long accessTokenExpiration) { + public void setValue(String secretKey, Long accessTokenExpiration, Long refreshTokenExpiration) { this.secretKey = secretKey; this.accessTokenExpiration = accessTokenExpiration; + this.refreshTokenExpiration = refreshTokenExpiration; } } From ab4fe9d9cb560c0ac8d19573e92b719e0369be5f Mon Sep 17 00:00:00 2001 From: gundorit Date: Wed, 23 Aug 2023 22:58:39 +0900 Subject: [PATCH 07/13] =?UTF-8?q?feat=20:=20test=EB=A5=BC=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20Builder=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../umc/yourweather/request/ChangePasswordRequestDto.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/umc/yourweather/request/ChangePasswordRequestDto.java b/src/main/java/com/umc/yourweather/request/ChangePasswordRequestDto.java index 9ad86a5..faf0c45 100644 --- a/src/main/java/com/umc/yourweather/request/ChangePasswordRequestDto.java +++ b/src/main/java/com/umc/yourweather/request/ChangePasswordRequestDto.java @@ -1,6 +1,7 @@ package com.umc.yourweather.request; import jakarta.validation.constraints.NotBlank; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -13,4 +14,11 @@ public class ChangePasswordRequestDto { @NotBlank String newPassword; + + @Builder + + public ChangePasswordRequestDto(String password, String newPassword) { + this.password = password; + this.newPassword = newPassword; + } } From b411bf054277f4651202170668f3c421ba9e298a Mon Sep 17 00:00:00 2001 From: gundorit Date: Wed, 23 Aug 2023 22:59:16 +0900 Subject: [PATCH 08/13] =?UTF-8?q?feat=20:=20=EA=B0=9D=EC=B2=B4=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=ED=9B=84=20=EC=A7=81=EC=A0=91=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=EB=A1=9C=20=EC=A3=BC=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/umc/yourweather/service/UserServiceTest.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/umc/yourweather/service/UserServiceTest.java b/src/test/java/com/umc/yourweather/service/UserServiceTest.java index cf64fca..3c1087f 100644 --- a/src/test/java/com/umc/yourweather/service/UserServiceTest.java +++ b/src/test/java/com/umc/yourweather/service/UserServiceTest.java @@ -11,18 +11,24 @@ import com.umc.yourweather.repository.test.UserTestRepository; import com.umc.yourweather.request.ChangePasswordRequestDto; import com.umc.yourweather.request.SignupRequestDto; +import com.umc.yourweather.response.AuthorizationResponseDto; +import com.umc.yourweather.response.ChangePasswordResponseDto; import com.umc.yourweather.response.UserResponseDto; +import java.util.Optional; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; class UserServiceTest { // 의존성 주입 최소화 + private final String secretKey = "secretKey"; private UserRepository userRepository = new UserTestRepository(); + private JwtTokenManager jwtTokenManager = new JwtTokenManager(); + private PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); private UserService userService = new UserService(userRepository, - new BCryptPasswordEncoder(), new JwtTokenManager()); + passwordEncoder, jwtTokenManager); private final String secretKey = "secretKey"; From 0c65c5599b8c14e10973e60dae262050329a41c6 Mon Sep 17 00:00:00 2001 From: gundorit Date: Wed, 23 Aug 2023 23:00:57 +0900 Subject: [PATCH 09/13] =?UTF-8?q?feat=20:=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B3=80=EA=B2=BD=EA=B3=BC=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=EB=90=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EB=B0=8F=20encode=20=ED=95=98=EC=A7=80=20=EC=95=8A=EC=9C=BC?= =?UTF-8?q?=EB=A9=B4=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EA=B0=80=20=EC=A0=9C?= =?UTF-8?q?=EB=8C=80=EB=A1=9C=20=EC=9E=91=EB=8F=99=EB=90=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EC=9D=80=20=ED=98=84=EC=83=81=EC=9D=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yourweather/service/UserServiceTest.java | 60 ++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/umc/yourweather/service/UserServiceTest.java b/src/test/java/com/umc/yourweather/service/UserServiceTest.java index 3c1087f..3000834 100644 --- a/src/test/java/com/umc/yourweather/service/UserServiceTest.java +++ b/src/test/java/com/umc/yourweather/service/UserServiceTest.java @@ -30,13 +30,12 @@ class UserServiceTest { private UserService userService = new UserService(userRepository, passwordEncoder, jwtTokenManager); - private final String secretKey = "secretKey"; @BeforeEach void setup() { userRepository.save(User.builder() .email("test@test.com") - .password("password") + .password(passwordEncoder.encode("password")) .nickname("nickname") .platform(Platform.YOURWEATHER) .role(Role.ROLE_USER) @@ -136,4 +135,61 @@ void withdraw() { User findUser = userRepository.findByEmail("test@test.com").get(); assertEquals(findUser.isActivate(), false); } + + @Test + void 비밀번호_변경이_가능하다() { + // given + User user = User.builder() + .email("test@test.com") + .password(passwordEncoder.encode("password")) + .nickname("nickname") + .platform(Platform.YOURWEATHER) + .role(Role.ROLE_USER) + .isActivate(true) + .build(); + + CustomUserDetails userDetails = new CustomUserDetails(user); + + ChangePasswordRequestDto request = ChangePasswordRequestDto.builder() + .password("password") + .newPassword("newPassword") + .build(); + + // when + ChangePasswordResponseDto changePasswordResponseDto = userService.changePassword(request, + userDetails); + + // then + assertEquals(true, changePasswordResponseDto.isSuccess()); + assertEquals("비밀번호 변경 완료", changePasswordResponseDto.getMessage()); + } + + @Test + void 기존_비밀번호를_틀릴_시_비밀번호_변경이_불가하다() { + // given + User user = User.builder() + .email("test@test.com") + .password(passwordEncoder.encode("password")) + .nickname("nickname") + .platform(Platform.YOURWEATHER) + .role(Role.ROLE_USER) + .isActivate(true) + .build(); + + CustomUserDetails userDetails = new CustomUserDetails(user); + + ChangePasswordRequestDto request = ChangePasswordRequestDto.builder() + .password("wrongPassword") + .newPassword("newPassword") + .build(); + + // when + ChangePasswordResponseDto changePasswordResponseDto = userService.changePassword(request, + userDetails); + + // then + assertEquals(changePasswordResponseDto.isSuccess(), false); + assertEquals(changePasswordResponseDto.getMessage(), + "요청으로 들어온 기존 비밀번호가 DB에 있는 정보와 일치하지 않습니다."); + } } From 8f27a136e88cec3c742d038b678099989beac7e3 Mon Sep 17 00:00:00 2001 From: gundorit Date: Wed, 23 Aug 2023 23:01:27 +0900 Subject: [PATCH 10/13] =?UTF-8?q?feat=20:=20=EC=A7=81=EC=A0=91=20=EC=A3=BC?= =?UTF-8?q?=EC=9E=85=ED=95=9C=20JwtTokenManager=EA=B0=80=20=EC=9E=98=20?= =?UTF-8?q?=EC=9E=91=EB=8F=99=EB=90=98=EB=8A=94=EC=A7=80=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yourweather/service/UserServiceTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/test/java/com/umc/yourweather/service/UserServiceTest.java b/src/test/java/com/umc/yourweather/service/UserServiceTest.java index 3000834..2a1ccf8 100644 --- a/src/test/java/com/umc/yourweather/service/UserServiceTest.java +++ b/src/test/java/com/umc/yourweather/service/UserServiceTest.java @@ -43,6 +43,28 @@ void setup() { .build()); } + @Test + void createAccessToken이_정상적으로_작동한다() { + // given + User user = User.builder() + .email("test@test.com") + .password("password") + .nickname("nickname") + .platform(Platform.YOURWEATHER) + .role(Role.ROLE_USER) + .isActivate(true) + .build(); + + // @Value 값을 채워주기 위한 임시 값 세팅 + jwtTokenManager.setValue(secretKey, 1L, 1L); + + // when + String accessToken = jwtTokenManager.createAccessToken(user); + + // then + assertNotNull(accessToken); + } + @Test void 회원_가입을_할_수_있다() { From 614f5985f2b806efd39159f8d62585bb1ec661f6 Mon Sep 17 00:00:00 2001 From: gundorit Date: Wed, 23 Aug 2023 23:01:57 +0900 Subject: [PATCH 11/13] =?UTF-8?q?test=20:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=EC=9D=B4=20=EC=A0=95=EC=83=81=EC=A0=81=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=A3=A8=EC=96=B4=EC=A7=80=EB=8A=94?= =?UTF-8?q?=EC=A7=80=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yourweather/service/UserServiceTest.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/umc/yourweather/service/UserServiceTest.java b/src/test/java/com/umc/yourweather/service/UserServiceTest.java index 2a1ccf8..e9c6d36 100644 --- a/src/test/java/com/umc/yourweather/service/UserServiceTest.java +++ b/src/test/java/com/umc/yourweather/service/UserServiceTest.java @@ -66,8 +66,24 @@ void setup() { } @Test - void 회원_가입을_할_수_있다() { + void 회원_가입이_정상적으로_작동한다() { + // given + SignupRequestDto request = SignupRequestDto.builder() + .email("user@test.com") + .password("password") + .nickname("nickname") + .platform(Platform.YOURWEATHER) + .build(); + // @Value 값을 채워주기 위한 임시 값 세팅 + jwtTokenManager.setValue(secretKey, 1L, 1L); + + // when + AuthorizationResponseDto authorizationResponseDto = userService.signup(request, secretKey); + + // then + assertNotNull(authorizationResponseDto.getAccessToken()); + assertNotNull(authorizationResponseDto.getRefreshToken()); } @Test From 4da6e3173871a1ad90cdc21c13384526a1d695ff Mon Sep 17 00:00:00 2001 From: gundorit Date: Wed, 23 Aug 2023 23:02:22 +0900 Subject: [PATCH 12/13] =?UTF-8?q?test=20:=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=EB=B2=A0=EC=9D=B4=EC=8A=A4=EC=97=90=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=ED=95=9C=20=EC=9C=A0=EC=A0=80=20=EA=B0=92=EC=9D=B4=20=EC=A0=9C?= =?UTF-8?q?=EB=8C=80=EB=A1=9C=20=EB=93=A4=EC=96=B4=EA=B0=80=EB=8A=94?= =?UTF-8?q?=EC=A7=80=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yourweather/service/UserServiceTest.java | 44 ++++--------------- 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/src/test/java/com/umc/yourweather/service/UserServiceTest.java b/src/test/java/com/umc/yourweather/service/UserServiceTest.java index e9c6d36..3a26e2f 100644 --- a/src/test/java/com/umc/yourweather/service/UserServiceTest.java +++ b/src/test/java/com/umc/yourweather/service/UserServiceTest.java @@ -104,51 +104,23 @@ void setup() { } @Test - @DisplayName("mypage 조회") - void mypage() { + void 데이터베이스에_정상적으로_저장된다() { // given - User user = User.builder() - .email("test@test.com") - .password("password") - .nickname("nickname") - .platform(Platform.YOURWEATHER) - .role(Role.ROLE_USER) - .isActivate(true) - .build(); - - CustomUserDetails userDetails = new CustomUserDetails(user); - - // when - UserResponseDto response = userService.mypage(userDetails); - - // then - assertEquals(userDetails.getUser().getEmail(), response.getEmail()); - assertEquals(userDetails.getUser().getNickname(), response.getNickname()); - } - - @Test - @DisplayName("비밀번호 변경") - void changePassword() { - // given - ChangePasswordRequestDto request = new ChangePasswordRequestDto("password2"); - - User user = User.builder() - .email("test@test.com") + SignupRequestDto request = SignupRequestDto.builder() + .email("user@test.com") .password("password") .nickname("nickname") .platform(Platform.YOURWEATHER) - .role(Role.ROLE_USER) - .isActivate(true) .build(); - - CustomUserDetails userDetails = new CustomUserDetails(user); + jwtTokenManager.setValue(secretKey, 1L, 1L); // when - userService.changePassword(request, userDetails); + userService.signup(request, secretKey); // then - User findUser = userRepository.findByEmail("test@test.com").get(); - assertEquals(findUser.getPassword(), "password2"); + Optional optionalUser = userRepository.findByEmail("user@test.com"); + assertTrue(optionalUser.isPresent()); + assertEquals("nickname", optionalUser.get().getNickname()); } @Test From cbbcff52d14d410ee8e3f557ea8ed29819f06f08 Mon Sep 17 00:00:00 2001 From: gundorit Date: Wed, 23 Aug 2023 23:02:43 +0900 Subject: [PATCH 13/13] =?UTF-8?q?test=20:=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=EA=B0=80=20=EB=8F=99=EC=9D=BC=ED=95=9C=EC=A7=80=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/umc/yourweather/service/UserServiceTest.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/umc/yourweather/service/UserServiceTest.java b/src/test/java/com/umc/yourweather/service/UserServiceTest.java index 3a26e2f..db4f5ae 100644 --- a/src/test/java/com/umc/yourweather/service/UserServiceTest.java +++ b/src/test/java/com/umc/yourweather/service/UserServiceTest.java @@ -124,9 +124,8 @@ void setup() { } @Test - @DisplayName("회원 탈퇴") - void withdraw() { - //given + void 마이_페이지_조회가_가능하다() { + // given User user = User.builder() .email("test@test.com") .password("password") @@ -139,11 +138,11 @@ void withdraw() { CustomUserDetails userDetails = new CustomUserDetails(user); // when - userService.withdraw(userDetails); + UserResponseDto response = userService.mypage(userDetails); // then - User findUser = userRepository.findByEmail("test@test.com").get(); - assertEquals(findUser.isActivate(), false); + assertEquals(userDetails.getUser().getEmail(), response.getEmail()); + assertEquals(userDetails.getUser().getNickname(), response.getNickname()); } @Test