Skip to content

Commit

Permalink
fix: 실패하는 테스트 케이스 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingyum-Kim committed Oct 18, 2024
1 parent 2d7ee8c commit ec54e73
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import mouda.backend.auth.Infrastructure.AppleOauthClient;
import mouda.backend.auth.business.result.LoginProcessResult;
import mouda.backend.auth.exception.AuthErrorMessage;
import mouda.backend.auth.exception.AuthException;
import mouda.backend.auth.implement.AppleOauthManager;
import mouda.backend.auth.implement.LoginManager;
import mouda.backend.auth.implement.jwt.AccessTokenProvider;
import mouda.backend.auth.presentation.controller.AppleUserInfoRequest;
import mouda.backend.auth.presentation.request.AppleOauthRequest;
import mouda.backend.auth.presentation.response.LoginResponse;
import mouda.backend.member.domain.LoginDetail;
import mouda.backend.member.domain.Member;
import mouda.backend.member.domain.OauthType;
Expand All @@ -37,17 +34,17 @@ public class AppleAuthService {
private final ObjectMapper objectMapper;
private final AppleOauthClient appleOauthClient;

public LoginResponse oauthLogin(AppleOauthRequest oauthRequest) {
Member member = memberFinder.findByNonce(oauthRequest.nonce());
// TODO: 사용자 전환 로직 실행 이전부터 애플 소셜 회원가입이 진행되어있음. 현재 카카오 사용자가 전환을 시도하여 애플 로그인하면 같은 애플 로그인 사용자가 두 명이 되면서 에러가 터질 것.
if (oauthRequest.memberId() != null) {
String accessToken = loginManager.updateOauth(oauthRequest.memberId(), OauthType.APPLE,
member.getSocialLoginId());
return new LoginResponse(accessToken);
}
LoginProcessResult result = loginManager.processAppleLogin(member);
return new LoginResponse(result.accessToken());
}
// TODO: 더 이상 사용하지 않는 로직. 로그인 프로세스 정착 후 제거할 것
// public LoginResponse oauthLogin(AppleOauthRequest oauthRequest) {
// TODO: 사용자 전환 로직 실행 이전부터 애플 소셜 회원가입이 진행되어있음. 현재 카카오 사용자가 전환을 시도하여 애플 로그인하면 같은 애플 로그인 사용자가 두 명이 되면서 에러가 터질 것.
// if (oauthRequest.memberId() != null) {
// String accessToken = loginManager.updateOauth(oauthRequest.memberId(), OauthType.APPLE,
// member.getSocialLoginId());
// return new LoginResponse(accessToken);
// }
// LoginProcessResult result = loginManager.processAppleLogin(member);
// return new LoginResponse(result.accessToken());ap
// }

public String getAccessToken(String idToken) {
String socialLoginId = appleOauthManager.getSocialLoginId(idToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public ResponseEntity<Void> test(
@RequestParam("id_token") String id_token,
@RequestParam(name = "user", required = false) String user
) throws IOException {
// TODO: 이전에 가입한 적 있지만 DB를 갈아엎어서 user가 들어오지 않는 경우 save에 실패한다.
if (user != null) {
appleAuthService.save(code, id_token, user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import mouda.backend.auth.business.KakaoAuthService;
import mouda.backend.auth.presentation.business.CommonAuthService;
import mouda.backend.auth.presentation.controller.swagger.AuthSwagger;
import mouda.backend.auth.presentation.request.AppleOauthRequest;
import mouda.backend.auth.presentation.request.GoogleOauthRequest;
import mouda.backend.auth.presentation.request.OauthRequest;
import mouda.backend.auth.presentation.response.KakaoLoginResponse;
Expand Down Expand Up @@ -71,13 +70,13 @@ public ResponseEntity<RestResponse<LoginResponse>> loginGoogleOauth(
return ResponseEntity.ok().body(new RestResponse<>(response));
}

@Override
@PostMapping("/apple/oauth")
public ResponseEntity<RestResponse<LoginResponse>> loginAppleOauth(@RequestBody AppleOauthRequest oauthRequest) {
LoginResponse response = appleAuthService.oauthLogin(oauthRequest);

return ResponseEntity.ok().body(new RestResponse<>(response));
}
// @Override
// @PostMapping("/apple/oauth")
// public ResponseEntity<RestResponse<LoginResponse>> loginAppleOauth(@RequestBody AppleOauthRequest oauthRequest) {
// LoginResponse response = appleAuthService.oauthLogin(oauthRequest);
//
// return ResponseEntity.ok().body(new RestResponse<>(response));
// }

@Override
@DeleteMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import mouda.backend.auth.presentation.request.AppleOauthRequest;
import mouda.backend.auth.presentation.request.GoogleOauthRequest;
import mouda.backend.auth.presentation.request.OauthRequest;
import mouda.backend.auth.presentation.response.KakaoLoginResponse;
Expand Down Expand Up @@ -35,11 +34,11 @@ public interface AuthSwagger {
})
ResponseEntity<RestResponse<LoginResponse>> loginBasicOauthHogee();

@Operation(summary = "애플 로그인", description = "애플 Oauth Code를 사용하여 로그인한다(accessToken 발급).")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "로그인 성공!"),
})
ResponseEntity<RestResponse<LoginResponse>> loginAppleOauth(@RequestBody AppleOauthRequest oauthRequest);
// @Operation(summary = "애플 로그인", description = "애플 Oauth Code를 사용하여 로그인한다(accessToken 발급).")
// @ApiResponses({
// @ApiResponse(responseCode = "200", description = "로그인 성공!"),
// })
// ResponseEntity<RestResponse<LoginResponse>> loginAppleOauth(@RequestBody AppleOauthRequest oauthRequest);

@Operation(summary = "구글 oauth 로그인", description = "구글 Oauth Code 를 사용하여 로그인한다(accessToken 발급).")
@ApiResponses({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mouda.backend.auth.presentation.request;

public record AppleOauthRequest(
Long memberId,
String nonce
Long memberId
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,4 @@ public Member findByMemberId(long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new AuthException(HttpStatus.NOT_FOUND, AuthErrorMessage.MEMBER_NOT_FOUND));
}

public Member findByNonce(String nonce) {
return memberRepository.findByLoginDetail_Nonce(nonce)
.orElseThrow(() -> new AuthException(HttpStatus.NOT_FOUND, AuthErrorMessage.MEMBER_NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public interface MemberRepository extends JpaRepository<Member, Long> {

Optional<Member> findByLoginDetail_SocialLoginId(String socialLoginId);

Optional<Member> findByLoginDetail_Nonce(String nonce);

@Query("""
UPDATE Member m
SET m.loginDetail.oauthType = :oauthType, m.loginDetail.socialLoginId = :socialLoginId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
package mouda.backend.auth.business;

import static org.assertj.core.api.Assertions.*;

import org.junit.jupiter.api.Disabled;
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;
import org.springframework.boot.test.mock.mockito.MockBean;

import mouda.backend.auth.implement.AppleOauthManager;
import mouda.backend.auth.presentation.request.AppleOauthRequest;
import mouda.backend.auth.presentation.response.LoginResponse;
import mouda.backend.member.implement.MemberFinder;
import mouda.backend.member.infrastructure.MemberRepository;

Expand All @@ -30,17 +23,17 @@ class AppleAuthServiceTest {
@Autowired
private MemberRepository memberRepository;

@DisplayName("애플 로그인 요청을 보내면 access token을 반환한다.")
@Test
@Disabled("실제 Resource Server에게 요청을 보내는 테스트이다. 프론트 서버를 켜서 코드르 발급 받아 필요할 때만 테스트한다.")
void oauthLogin() {
String code = "";
AppleOauthRequest oauthRequest = new AppleOauthRequest(1L, "nonce");

LoginResponse loginResponse = appleAuthService.oauthLogin(oauthRequest);

assertThat(loginResponse).isNotNull();
}
// @DisplayName("애플 로그인 요청을 보내면 access token을 반환한다.")
// @Test
// @Disabled("실제 Resource Server에게 요청을 보내는 테스트이다. 프론트 서버를 켜서 코드르 발급 받아 필요할 때만 테스트한다.")
// void oauthLogin() {
// String code = "";
// AppleOauthRequest oauthRequest = new AppleOauthRequest(1L, "nonce");
//
// LoginResponse loginResponse = appleAuthService.oauthLogin(oauthRequest);
//
// assertThat(loginResponse).isNotNull();
// }

/*
@DisplayName("사용자 전환을 시도하면 새로운 회원을 추가하지 않고 기존 회원의 정보를 수정한다.")
Expand Down

0 comments on commit ec54e73

Please sign in to comment.