From 08178eda132736f2b0fc2564d8bd8a1aa7145230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=83=EC=A7=B1?= <107979804+eunkeeee@users.noreply.github.com> Date: Wed, 1 Nov 2023 21:23:42 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=95=84=EC=9D=B4=EB=94=94,=20?= =?UTF-8?q?=ED=8C=A8=EC=8A=A4=EC=9B=8C=EB=93=9C=EB=A1=9C=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=EA=B0=80=EC=9E=85/=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20(#14)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: users 테이블에 일반 로그인 아이디 패스워드 방식의 칼럼 추가 * feat: 로그인 패스워드로 회원가입, 로그인 기능 추가 --- ...ontroller.java => UserAuthController.java} | 24 ++++++--- .../server/auth/api/request/AuthRequest.java | 12 +++++ .../auth/api/request/UserJoinRequest.java | 44 +++------------- .../auth/application/UserAuthService.java | 51 +++++++++++++++++++ .../auth/application/UserJoinService.java | 33 ------------ .../application/util/PasswordEncryptor.java | 21 ++++++++ .../sallange/server/config/WebMvcConfig.java | 5 +- .../java/sallange/server/entity/User.java | 26 +++++++++- .../sallange/server/http/auth-request.http | 33 +++++++++++- .../sallange/server/http/cycle-request.http | 24 ++++++++- .../server/http/health-check-request.http | 3 +- .../sallange/server/http/http-client.env.json | 5 -- .../server/repository/UserRepository.java | 2 + .../db/migration/V2__add_login_column.sql | 5 ++ server/src/main/resources/security | 2 +- .../acceptance/CycleRentAcceptanceTest.java | 28 +++------- .../acceptance/CycleReturnAcceptanceTest.java | 4 +- .../CycleStatusQueryAcceptanceTest.java | 6 +-- .../server/acceptance/step/UsersJoinStep.java | 5 +- 19 files changed, 216 insertions(+), 117 deletions(-) rename server/src/main/java/sallange/server/auth/api/{UserJoinController.java => UserAuthController.java} (55%) create mode 100644 server/src/main/java/sallange/server/auth/api/request/AuthRequest.java create mode 100644 server/src/main/java/sallange/server/auth/application/UserAuthService.java delete mode 100644 server/src/main/java/sallange/server/auth/application/UserJoinService.java create mode 100644 server/src/main/java/sallange/server/auth/application/util/PasswordEncryptor.java delete mode 100644 server/src/main/java/sallange/server/http/http-client.env.json create mode 100644 server/src/main/resources/db/migration/V2__add_login_column.sql diff --git a/server/src/main/java/sallange/server/auth/api/UserJoinController.java b/server/src/main/java/sallange/server/auth/api/UserAuthController.java similarity index 55% rename from server/src/main/java/sallange/server/auth/api/UserJoinController.java rename to server/src/main/java/sallange/server/auth/api/UserAuthController.java index 4399949..5dafb35 100644 --- a/server/src/main/java/sallange/server/auth/api/UserJoinController.java +++ b/server/src/main/java/sallange/server/auth/api/UserAuthController.java @@ -2,27 +2,35 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; -import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import sallange.server.auth.api.request.AuthRequest; import sallange.server.auth.api.request.UserJoinRequest; import sallange.server.auth.api.response.AuthTokensResponse; -import sallange.server.auth.application.UserJoinService; +import sallange.server.auth.application.UserAuthService; @RequiredArgsConstructor @RestController -@RequestMapping("/test/users") -public class UserJoinController { +@RequestMapping("/api") +public class UserAuthController { - private final UserJoinService userJoinService; + private final UserAuthService userAuthService; - @PostMapping - @Transactional + @PostMapping("/join") public ResponseEntity join(@RequestBody final UserJoinRequest request) { return ResponseEntity .ok() - .body(userJoinService.join(request)); + .body(userAuthService.join(request)); + } + + @PostMapping("/login") + public ResponseEntity login( + @RequestBody AuthRequest request + ) { + return ResponseEntity + .ok() + .body(userAuthService.login(request)); } } diff --git a/server/src/main/java/sallange/server/auth/api/request/AuthRequest.java b/server/src/main/java/sallange/server/auth/api/request/AuthRequest.java new file mode 100644 index 0000000..cf2f5ba --- /dev/null +++ b/server/src/main/java/sallange/server/auth/api/request/AuthRequest.java @@ -0,0 +1,12 @@ +package sallange.server.auth.api.request; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public class AuthRequest { + + private final String loginID; + private final String loginPassword; +} diff --git a/server/src/main/java/sallange/server/auth/api/request/UserJoinRequest.java b/server/src/main/java/sallange/server/auth/api/request/UserJoinRequest.java index 47f0811..1f19c41 100644 --- a/server/src/main/java/sallange/server/auth/api/request/UserJoinRequest.java +++ b/server/src/main/java/sallange/server/auth/api/request/UserJoinRequest.java @@ -1,42 +1,12 @@ package sallange.server.auth.api.request; -public class UserJoinRequest { - - private final String name; - private final String oAuthProvider; - private final Long oAuthId; - private final Integer leftRentCount; - - public UserJoinRequest(final String name, final String oAuthProvider, final Long oAuthId, final Integer leftRentCount) { - this.name = name; - this.oAuthProvider = oAuthProvider; - this.oAuthId = oAuthId; - this.leftRentCount = leftRentCount; - } - - public String getName() { - return name; - } +import lombok.Getter; +import lombok.RequiredArgsConstructor; - public String getoAuthProvider() { - return oAuthProvider; - } - - public Long getoAuthId() { - return oAuthId; - } - - public Integer getLeftRentCount() { - return leftRentCount; - } +@Getter +@RequiredArgsConstructor +public class UserJoinRequest { - @Override - public String toString() { - return "UserJoinRequest{" + - "name='" + name + '\'' + - ", oAuthProvider='" + oAuthProvider + '\'' + - ", oAuthId=" + oAuthId + - ", leftRentCount=" + leftRentCount + - '}'; - } + private final String loginID; + private final String loginPassword; } diff --git a/server/src/main/java/sallange/server/auth/application/UserAuthService.java b/server/src/main/java/sallange/server/auth/application/UserAuthService.java new file mode 100644 index 0000000..994a632 --- /dev/null +++ b/server/src/main/java/sallange/server/auth/application/UserAuthService.java @@ -0,0 +1,51 @@ +package sallange.server.auth.application; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import sallange.server.auth.api.request.AuthRequest; +import sallange.server.auth.api.request.UserJoinRequest; +import sallange.server.auth.api.response.AuthTokensResponse; +import sallange.server.auth.application.util.PasswordEncryptor; +import sallange.server.auth.util.AuthTokensGenerator; +import sallange.server.entity.User; +import sallange.server.repository.UserRepository; + +import java.util.NoSuchElementException; + +@RequiredArgsConstructor +@Service +@Transactional +public class UserAuthService { + + private final UserRepository userRepository; + private final AuthTokensGenerator authTokensGenerator; + + public AuthTokensResponse join(final UserJoinRequest request) { + final String loginId = request.getLoginID(); + final String loginPassword = request.getLoginPassword(); + if (userRepository.findByLoginId(loginId).isPresent()) { + throw new RuntimeException("[ERROR] 중복되는 아이디입니다."); + } + + final String encryptedPassword = PasswordEncryptor.encrypt(loginPassword); + + final User user = User.loginUserBuilder() + .loginId(loginId) + .encryptedPassword(encryptedPassword) + .build(); + + final Long id = userRepository.save(user).getId(); + return authTokensGenerator.generate(id); + } + + public AuthTokensResponse login(final AuthRequest request) { + final String loginId = request.getLoginID(); + final String loginPassword = request.getLoginPassword(); + final User user = userRepository.findByLoginId(loginId) + .orElseThrow(() -> new NoSuchElementException("[ERROR] 존재하지 않는 아이디입니다.")); + + user.checkPassword(PasswordEncryptor.encrypt(loginPassword)); + return authTokensGenerator.generate(user.getId()); + } +} diff --git a/server/src/main/java/sallange/server/auth/application/UserJoinService.java b/server/src/main/java/sallange/server/auth/application/UserJoinService.java deleted file mode 100644 index 5b40b9b..0000000 --- a/server/src/main/java/sallange/server/auth/application/UserJoinService.java +++ /dev/null @@ -1,33 +0,0 @@ -package sallange.server.auth.application; - -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import sallange.server.auth.OAuthProvider; -import sallange.server.auth.api.request.UserJoinRequest; -import sallange.server.auth.api.response.AuthTokensResponse; -import sallange.server.auth.util.AuthTokensGenerator; -import sallange.server.entity.User; -import sallange.server.repository.UserRepository; - -@RequiredArgsConstructor -@Service -@Transactional -public class UserJoinService { - - private final UserRepository userRepository; - private final AuthTokensGenerator authTokensGenerator; - - public AuthTokensResponse join(final UserJoinRequest request) { - final User user = userRepository.save( - new User( - request.getName(), - OAuthProvider.from(request.getoAuthProvider()), - request.getoAuthId(), - request.getLeftRentCount() - ) - ); - - return authTokensGenerator.generate(user.getId()); - } -} diff --git a/server/src/main/java/sallange/server/auth/application/util/PasswordEncryptor.java b/server/src/main/java/sallange/server/auth/application/util/PasswordEncryptor.java new file mode 100644 index 0000000..46ae51f --- /dev/null +++ b/server/src/main/java/sallange/server/auth/application/util/PasswordEncryptor.java @@ -0,0 +1,21 @@ +package sallange.server.auth.application.util; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Base64; + +public class PasswordEncryptor { + + private static final String ALGORITHM = "SHA-256"; + + public static String encrypt(String password) { + try { + MessageDigest digest = MessageDigest.getInstance(ALGORITHM); + digest.update(password.getBytes()); + return Base64.getEncoder().encodeToString(digest.digest()); + } catch (NoSuchAlgorithmException exception) { + throw new IllegalArgumentException("암호화 알고리즘이 존재하지 않습니다."); + } + } +} + diff --git a/server/src/main/java/sallange/server/config/WebMvcConfig.java b/server/src/main/java/sallange/server/config/WebMvcConfig.java index ed70015..bf9b63e 100644 --- a/server/src/main/java/sallange/server/config/WebMvcConfig.java +++ b/server/src/main/java/sallange/server/config/WebMvcConfig.java @@ -21,7 +21,10 @@ public class WebMvcConfig implements WebMvcConfigurer { public void addInterceptors(final InterceptorRegistry registry) { registry.addInterceptor(userAuthInterceptor) .addPathPatterns("/api/**") - .excludePathPatterns("/api/login/**"); + .excludePathPatterns( + "/api/login/**", + "/api/join/**" + ); } @Override diff --git a/server/src/main/java/sallange/server/entity/User.java b/server/src/main/java/sallange/server/entity/User.java index 8fa4cdd..5973920 100644 --- a/server/src/main/java/sallange/server/entity/User.java +++ b/server/src/main/java/sallange/server/entity/User.java @@ -6,7 +6,9 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.Table; +import lombok.Builder; import sallange.server.auth.OAuthProvider; +import sallange.server.exception.UnAuthorizationException; import static jakarta.persistence.EnumType.STRING; import static jakarta.persistence.GenerationType.IDENTITY; @@ -26,16 +28,24 @@ public class User extends BaseDate { @Column(name = "oauth_id") private Long oAuthId; + private String loginId; + private String encryptedPassword; private Integer leftRentCount; - public User(final Long id, final String name, final OAuthProvider oAuthProvider, final Long oAuthId, final Integer leftRentCount) { + public User(final Long id, final String name, final OAuthProvider oAuthProvider, final Long oAuthId, final String loginId, final String encryptedPassword, final Integer leftRentCount) { this.id = id; this.name = name; this.oAuthProvider = oAuthProvider; this.oAuthId = oAuthId; + this.loginId = loginId; + this.encryptedPassword = encryptedPassword; this.leftRentCount = leftRentCount; } + private User(final Long id, final String name, final OAuthProvider oAuthProvider, final Long oAuthId, final Integer leftRentCount) { + this(id, name, oAuthProvider, oAuthId, null, null, leftRentCount); + } + public User(final String name, final OAuthProvider oAuthProvider, final Long oAuthId, final Integer leftRentCount) { this(null, name, oAuthProvider, oAuthId, leftRentCount); } @@ -44,6 +54,14 @@ public User(final String name, final OAuthProvider oAuthProvider, final Long oAu this(null, name, oAuthProvider, oAuthId, 2); } + @Builder(builderMethodName = "loginUserBuilder") + public User( + final String loginId, + final String encryptedPassword + ) { + this(null, null, null, null, loginId, encryptedPassword, 2); + } + public User() { } @@ -74,4 +92,10 @@ public Long getoAuthId() { public Integer getLeftRentCount() { return leftRentCount; } + + public void checkPassword(final String encryptedPassword) { + if (!this.encryptedPassword.equals(encryptedPassword)) { + throw new UnAuthorizationException("[ERROR] 아이디와 패스워드가 올바르지 않습니다!"); + } + } } diff --git a/server/src/main/java/sallange/server/http/auth-request.http b/server/src/main/java/sallange/server/http/auth-request.http index d1c0be8..618ed80 100644 --- a/server/src/main/java/sallange/server/http/auth-request.http +++ b/server/src/main/java/sallange/server/http/auth-request.http @@ -1,4 +1,33 @@ -### 카카오로 로그인 버튼 클릭 -GET {{host}}/api/login/kakao +### 로그인 버튼 클릭 +GET http://15.165.231.19:8080/api/login/kakao Content-Type: application/json +### 살랑이 서버로부터 액세스 토큰 발급 +GET http://15.165.231.19:8080/api/login/kakao/token?code=aH2sHl41OKXXCtyIRyU0CfDW3dgwl-16jTilcTDAvZJBGynZ9VXfLaBbgqQKKcleAAABi4oG62no6jj-qNQmaA +Content-Type: application/json + +### 로컬 로그인 버튼 클릭 +GET http://localhost:8080/api/login/kakao +Content-Type: application/json + +### 로컬에서 액세스 토큰 발급 +GET http://localhost:8080/api/login/kakao/token?code=iBKjkBdHJDU3a57ZiPM_344lHvMTjmgtUwqFdVrx5TSE1llY1hEj6tIKJxoKPXSYAAABi4oZjRr7Ewsnpgvovw +Content-Type: application/json + +### 아이디, 패스워드로 회원가입 +POST http://localhost:8080/api/join +Content-Type: application/json + +{ + "loginID": "gitchan", + "loginPassword": "gitchan1234" +} + +### 아이디, 패스워드로 로그인 +POST http://localhost:8080/api/login +Content-Type: application/json + +{ + "loginID": "gitchan", + "loginPassword": "gitchan1234" +} diff --git a/server/src/main/java/sallange/server/http/cycle-request.http b/server/src/main/java/sallange/server/http/cycle-request.http index 3200dae..189c5f9 100644 --- a/server/src/main/java/sallange/server/http/cycle-request.http +++ b/server/src/main/java/sallange/server/http/cycle-request.http @@ -1,7 +1,29 @@ +### 유저 로그인 (테스트용) +POST http://15.165.231.19:8080/test/users +Content-Type: application/json + +{ + "name": "깃짱", + "oAuthProvider": "KAKAO", + "oAuthId": 123, + "leftRentCount": 2 +} + +### 살랑이 생성 요청 +POST http://15.165.231.19:8080/admin/cycles +Content-Type: application/json + ### 살랑이 대여 요청 -POST {{host}}/rent +POST http://15.165.231.19:8080/cycles/rent Content-Type: application/json +Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwiZXhwIjoxNjk4ODk4NjQyfQ.YfedMD0NFfKrFv7NdcfYUhhf90vGhk2Qd6hx1548Hs8099k9xlUdueD_VEddxr_H6vV11Q4gnE4cyOYHplxs-w { "cycleID": "1" } + +### 살랑이 반납 요청 +POST http://15.165.231.19:8080/cycles/return-cycle +Content-Type: application/json +Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwiZXhwIjoxNjk4ODk4NjQyfQ.YfedMD0NFfKrFv7NdcfYUhhf90vGhk2Qd6hx1548Hs8099k9xlUdueD_VEddxr_H6vV11Q4gnE4cyOYHplxs-w + diff --git a/server/src/main/java/sallange/server/http/health-check-request.http b/server/src/main/java/sallange/server/http/health-check-request.http index 87c5efd..8e5d8e4 100644 --- a/server/src/main/java/sallange/server/http/health-check-request.http +++ b/server/src/main/java/sallange/server/http/health-check-request.http @@ -1,4 +1,3 @@ ### 서버 헬스 체크 요청 -GET {{host}}/health-check +GET http://15.165.231.19:8080/admin/health-check Content-Type: application/json - diff --git a/server/src/main/java/sallange/server/http/http-client.env.json b/server/src/main/java/sallange/server/http/http-client.env.json deleted file mode 100644 index a23e983..0000000 --- a/server/src/main/java/sallange/server/http/http-client.env.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "dev": { - "host": "15.164.177.155:8080" - } -} diff --git a/server/src/main/java/sallange/server/repository/UserRepository.java b/server/src/main/java/sallange/server/repository/UserRepository.java index 258663d..4a83749 100644 --- a/server/src/main/java/sallange/server/repository/UserRepository.java +++ b/server/src/main/java/sallange/server/repository/UserRepository.java @@ -15,4 +15,6 @@ Optional findIdByOAuthProviderAndOAuthId( @Param("oAuthProvider") OAuthProvider oAuthProvider, @Param("oAuthId") Long oAuthId ); + + Optional findByLoginId(String loginId); } diff --git a/server/src/main/resources/db/migration/V2__add_login_column.sql b/server/src/main/resources/db/migration/V2__add_login_column.sql new file mode 100644 index 0000000..c716a19 --- /dev/null +++ b/server/src/main/resources/db/migration/V2__add_login_column.sql @@ -0,0 +1,5 @@ +alter table users + add `login_id` varchar(255); + +alter table users + add `encrypted_password` varchar(255); diff --git a/server/src/main/resources/security b/server/src/main/resources/security index ad74ab3..78ff6a2 160000 --- a/server/src/main/resources/security +++ b/server/src/main/resources/security @@ -1 +1 @@ -Subproject commit ad74ab3b14700ec634cb72ad939084697fb2fa7a +Subproject commit 78ff6a2f6447bf563cda8d93aafab1645e7782d5 diff --git a/server/src/test/java/sallange/server/acceptance/CycleRentAcceptanceTest.java b/server/src/test/java/sallange/server/acceptance/CycleRentAcceptanceTest.java index a5ac7b5..31e5dd1 100644 --- a/server/src/test/java/sallange/server/acceptance/CycleRentAcceptanceTest.java +++ b/server/src/test/java/sallange/server/acceptance/CycleRentAcceptanceTest.java @@ -5,7 +5,6 @@ import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; import sallange.server.api.request.RentRequest; -import sallange.server.auth.api.request.UserJoinRequest; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; @@ -13,13 +12,15 @@ import static sallange.server.acceptance.step.CycleCreateStep.살랑이_생성_요청하고_아이디_반환; import static sallange.server.acceptance.step.CycleRentStep.살랑이_대여_요청; import static sallange.server.acceptance.step.CycleReturnStep.살랑이_반납_요청; +import static sallange.server.acceptance.step.UsersJoinStep.USER_JOIN_REQUEST_GITCHAN; +import static sallange.server.acceptance.step.UsersJoinStep.USER_JOIN_REQUEST_HOONCHAN; import static sallange.server.acceptance.step.UsersJoinStep.회원_가입_요청하고_액세스_토큰_반환; class CycleRentAcceptanceTest extends AcceptanceTest { @Test void 살랑이를_대여한다() { - final String accessToken = 회원_가입_요청하고_액세스_토큰_반환(new UserJoinRequest("깃짱", "KAKAO", 123L, 2)); + final String accessToken = 회원_가입_요청하고_액세스_토큰_반환(USER_JOIN_REQUEST_GITCHAN); final Long cycleId = 살랑이_생성_요청하고_아이디_반환(); final ExtractableResponse response = 살랑이_대여_요청(accessToken, RentRequest.from(cycleId)); @@ -29,8 +30,8 @@ class CycleRentAcceptanceTest extends AcceptanceTest { @Test void 이미_다른_사람이_대여중인_살랑이를_대여하면_에러_코드_1을_반환한다() { - final String user1AccessToken = 회원_가입_요청하고_액세스_토큰_반환(new UserJoinRequest("깃짱", "KAKAO", 123L, 2)); - final String user2AccessToken = 회원_가입_요청하고_액세스_토큰_반환(new UserJoinRequest("훈짱", "KAKAO", 124L, 2)); + final String user1AccessToken = 회원_가입_요청하고_액세스_토큰_반환(USER_JOIN_REQUEST_GITCHAN); + final String user2AccessToken = 회원_가입_요청하고_액세스_토큰_반환(USER_JOIN_REQUEST_HOONCHAN); final Long cycleId = 살랑이_생성_요청하고_아이디_반환(); 살랑이_대여_요청(user1AccessToken, RentRequest.from(cycleId)); @@ -45,20 +46,7 @@ class CycleRentAcceptanceTest extends AcceptanceTest { @Test void 살랑이_사용_가능_회수가_없는_유저가_살랑이를_대여하면_에러_코드_3을_반환한다() { - final String accessToken = 회원_가입_요청하고_액세스_토큰_반환(new UserJoinRequest("깃짱", "KAKAO", 123L, 0)); - final Long cycleId = 살랑이_생성_요청하고_아이디_반환(); - - final ExtractableResponse response = 살랑이_대여_요청(accessToken, RentRequest.from(cycleId)); - - assertAll( - () -> assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.value()), - () -> assertThat(response.jsonPath().getInt("errorCode")).isEqualTo(3) - ); - } - - @Test - void 회원가입_후에_3번_빌리면_대여가_안된다() { - final String accessToken = 회원_가입_요청하고_액세스_토큰_반환(new UserJoinRequest("깃짱", "KAKAO", 123L, 2)); + final String accessToken = 회원_가입_요청하고_액세스_토큰_반환(USER_JOIN_REQUEST_GITCHAN); final Long cycleId = 살랑이_생성_요청하고_아이디_반환(); 살랑이_대여_요청(accessToken, RentRequest.from(cycleId)); @@ -76,7 +64,7 @@ class CycleRentAcceptanceTest extends AcceptanceTest { @Test void 이미_다른_살랑이를_대여하면서_또_다른_살랑이를_대여하면_에러_코드_4를_반환하다() { - final String accessToken = 회원_가입_요청하고_액세스_토큰_반환(new UserJoinRequest("깃짱", "KAKAO", 123L, 2)); + final String accessToken = 회원_가입_요청하고_액세스_토큰_반환(USER_JOIN_REQUEST_GITCHAN); final Long cycle1Id = 살랑이_생성_요청하고_아이디_반환(); final Long cycle2Id = 살랑이_생성_요청하고_아이디_반환(); @@ -93,7 +81,7 @@ class CycleRentAcceptanceTest extends AcceptanceTest { @Test void 이미_다른_살랑이를_대여하면서_또_해당_살랑이를_대여하면_에러_코드_4를_반환하다() { - final String accessToken = 회원_가입_요청하고_액세스_토큰_반환(new UserJoinRequest("깃짱", "KAKAO", 123L, 2)); + final String accessToken = 회원_가입_요청하고_액세스_토큰_반환(USER_JOIN_REQUEST_GITCHAN); final Long cycleId = 살랑이_생성_요청하고_아이디_반환(); 살랑이_대여_요청(accessToken, RentRequest.from(cycleId)); diff --git a/server/src/test/java/sallange/server/acceptance/CycleReturnAcceptanceTest.java b/server/src/test/java/sallange/server/acceptance/CycleReturnAcceptanceTest.java index 66de652..b717e3a 100644 --- a/server/src/test/java/sallange/server/acceptance/CycleReturnAcceptanceTest.java +++ b/server/src/test/java/sallange/server/acceptance/CycleReturnAcceptanceTest.java @@ -5,19 +5,19 @@ import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; import sallange.server.api.request.RentRequest; -import sallange.server.auth.api.request.UserJoinRequest; import static org.assertj.core.api.Assertions.assertThat; import static sallange.server.acceptance.step.CycleCreateStep.살랑이_생성_요청하고_아이디_반환; import static sallange.server.acceptance.step.CycleRentStep.살랑이_대여_요청; import static sallange.server.acceptance.step.CycleReturnStep.살랑이_반납_요청; +import static sallange.server.acceptance.step.UsersJoinStep.USER_JOIN_REQUEST_GITCHAN; import static sallange.server.acceptance.step.UsersJoinStep.회원_가입_요청하고_액세스_토큰_반환; class CycleReturnAcceptanceTest extends AcceptanceTest { @Test void 살랑이를_반납한다() { - final String accessToken = 회원_가입_요청하고_액세스_토큰_반환(new UserJoinRequest("깃짱", "KAKAO", 123L, 2)); + final String accessToken = 회원_가입_요청하고_액세스_토큰_반환(USER_JOIN_REQUEST_GITCHAN); final Long cycleId = 살랑이_생성_요청하고_아이디_반환(); 살랑이_대여_요청(accessToken, new RentRequest(String.valueOf(cycleId))); diff --git a/server/src/test/java/sallange/server/acceptance/CycleStatusQueryAcceptanceTest.java b/server/src/test/java/sallange/server/acceptance/CycleStatusQueryAcceptanceTest.java index b072672..6ee73ec 100644 --- a/server/src/test/java/sallange/server/acceptance/CycleStatusQueryAcceptanceTest.java +++ b/server/src/test/java/sallange/server/acceptance/CycleStatusQueryAcceptanceTest.java @@ -6,7 +6,6 @@ import sallange.server.api.request.CycleStatusQueryRequest; import sallange.server.api.request.CycleStatusUpdateRequest; import sallange.server.api.request.RentRequest; -import sallange.server.auth.api.request.UserJoinRequest; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; @@ -16,6 +15,7 @@ import static sallange.server.acceptance.step.CycleReturnStep.살랑이_반납_요청; import static sallange.server.acceptance.step.CycleStatusQueryStep.살랑이_상태_조회_요청; import static sallange.server.acceptance.step.CycleStatusUpdateStep.살랑이_상태_변경_요청; +import static sallange.server.acceptance.step.UsersJoinStep.USER_JOIN_REQUEST_GITCHAN; import static sallange.server.acceptance.step.UsersJoinStep.회원_가입_요청하고_액세스_토큰_반환; class CycleStatusQueryAcceptanceTest extends AcceptanceTest { @@ -33,7 +33,7 @@ class CycleStatusQueryAcceptanceTest extends AcceptanceTest { @Test void 생성_후_대여된_살랑이의_상태는_RENT_이다() { - final String accessToken = 회원_가입_요청하고_액세스_토큰_반환(new UserJoinRequest("깃짱", "KAKAO", 123L, 2)); + final String accessToken = 회원_가입_요청하고_액세스_토큰_반환(USER_JOIN_REQUEST_GITCHAN); final Long cycleId = 살랑이_생성_요청하고_아이디_반환(); 살랑이_대여_요청(accessToken, RentRequest.from(cycleId)); @@ -60,7 +60,7 @@ class CycleStatusQueryAcceptanceTest extends AcceptanceTest { @Test void 대여_후_반납된_살랑이의_상태는_AVAILABLE이다() { - final String accessToken = 회원_가입_요청하고_액세스_토큰_반환(new UserJoinRequest("깃짱", "KAKAO", 123L, 2)); + final String accessToken = 회원_가입_요청하고_액세스_토큰_반환(USER_JOIN_REQUEST_GITCHAN); final Long cycleId = 살랑이_생성_요청하고_아이디_반환(); 살랑이_대여_요청(accessToken, new RentRequest(String.valueOf(cycleId))); diff --git a/server/src/test/java/sallange/server/acceptance/step/UsersJoinStep.java b/server/src/test/java/sallange/server/acceptance/step/UsersJoinStep.java index 398623a..fc04dd1 100644 --- a/server/src/test/java/sallange/server/acceptance/step/UsersJoinStep.java +++ b/server/src/test/java/sallange/server/acceptance/step/UsersJoinStep.java @@ -9,6 +9,9 @@ public class UsersJoinStep { + public static final UserJoinRequest USER_JOIN_REQUEST_GITCHAN = new UserJoinRequest("gitchan", "gitchan1234"); + public static final UserJoinRequest USER_JOIN_REQUEST_HOONCHAN = new UserJoinRequest("hoonchan", "hoonchan5678"); + public static String 회원_가입_요청하고_액세스_토큰_반환(final UserJoinRequest request) { final ExtractableResponse response = 회원_가입_요청(request); return response.jsonPath().getString("accessToken"); @@ -21,7 +24,7 @@ public class UsersJoinStep { .body(request) .when() - .post("/test/users") + .post("/api/join") .then() .log().all()