Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: 회원가입 및 로그인 구현 #16

Merged
merged 9 commits into from
May 10, 2024
Merged

Feature: 회원가입 및 로그인 구현 #16

merged 9 commits into from
May 10, 2024

Conversation

lcomment
Copy link
Collaborator

@lcomment lcomment commented May 9, 2024

Issue Number

#4

Description

이전 PR에서 구현했던 것들을 활용하여 회원가입과 로그인 API를 구현했습니다. 모두 Provider와 외부 API를 활용하는 로직들이라 특별한 도메인 모델은 없습니다. 통합 테스트 관련하여 Testcontainer를 활용하기로 했는데, 외부 API에 의존하는 로직이다보니 모킹이 필수라 생각이 들었고, 일단 모킹을 활용하여 단위테스트만 작성해두었습니다. Query의 경우, Jpa 메서드를 통한 자동완성만을 활용했기에 크게 이상이 있을 것 같진 않습니다.

추후에 환경변수를 세팅하여 배포할텐데, 아마 git의 submodule을 활용할 예정입니다.

또 Testcontainer 관련하여 간략하게 적자면, 일단 세팅은 모두 되어있고, 로컬에서 SpringBootTest나 Build 시, docker를 실행시켜놓아야 Testcontainer가 올리갑니다. 추가적으로 궁금하신점은 리뷰와 함께 남겨주세요.

ps. 초기 설정 파일이 좀 있다보니 PR이 커져버렸는데, 설정까지만 양해 부탁드립니다 .

Core Code

. . .
	@Transactional
	public JwtResponse signUp(UserSignUpRequest dto) {
		final String providerId = oidcProviderFactory.getProviderId(dto.provider(), dto.idToken());
		final User user = userWriter.create(UserMapper.supplyUserBy(dto, providerId));

		return JwtResponse.from(jwtProvider.generateToken(user));
	}
. . .

etc

@lcomment lcomment added chore 빌드 매니저 및 환경 설정 feature 새로운 기능 개발 labels May 9, 2024
@lcomment lcomment requested a review from YongsHub May 9, 2024 14:22
@lcomment lcomment self-assigned this May 9, 2024
Copy link

github-actions bot commented May 9, 2024

Test Results

11 tests  +4   10 ✅ +4   1s ⏱️ ±0s
 3 suites +1    1 💤 ±0 
 3 files   +1    0 ❌ ±0 

Results for commit 9d30bd4. ± Comparison against base commit 840501c.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@YongsHub YongsHub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다


@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 api/v1 앞에 붙는건 환경 변수로 컨트롤하는건 어떤가요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정하겠습니다

Comment on lines +59 to +61
doReturn(user.getProviderId()).when(oidcProviderFactory).getProviderId(dto.provider(), dto.idToken());
doReturn(user).when(userWriter).create(any(User.class));
doReturn(jwt).when(jwtProvider).generateToken(user);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

random value 만들어주는 테스트는 좋네요 :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다만, 저번에 말씀해주셨듯이 통합테스트에서는 정확한 범위 내에서 랜덤을 돌려야겠어요. 이상한 문자도 들어가서 특수한 경우(ex. Base64 decoding)에는 에러 발생 가능성이 있습니다.

Comment on lines 21 to 24
@AutoConfigureMockMvc
@ActiveProfiles("test")
@SpringBootTest
@SpringBootTest(properties = "spring.profiles.active: test")
public abstract class ControllerTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Controller Test에서는 MockMvc로 테스트하고 통합테스트는 따로 Test Container로 설정된 DB까지 접근될 수 있게 작성하면 되는걸로 이해하면 되나요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어.. 그런건 아니고, 의식의 흐름이었습니다 ㅋㅋ 수정하고 리뷰 요청 다시 보내겠습니다.

@lcomment
Copy link
Collaborator Author

lcomment commented May 10, 2024

@YongsHub

  1. 말씀해주신대로 api prefix는 application.yml에 담았습니다.

  2. MockMvc 대신 TestRestTemplate을 추가하여, 통합 테스트 시 서블릿 컨테이너가 띄어집니다. RestTemplate이 아닌 TestRestTemplate을 활용한 이유는 TestRestTemplate은 SpringBootTest의 환경에 맞추어 알아서 초기화되기 때문입니다. 관련 가이드 라인은 Notion의 서버 문서에 정리해두겠습니다.

MockMvc를 활용해도 SpringBootTest이기에 Testcontainer를 활용할 수 있습니다. TestRestTemplate으로 변경한 이유는 서블릿 컨테이너를 활용하기 위해서입니다.

@lcomment lcomment requested a review from YongsHub May 10, 2024 01:13
@YongsHub
Copy link
Contributor

@YongsHub

  1. 말씀해주신대로 api prefix는 application.yml에 담았습니다.
  2. MockMvc 대신 TestRestTemplate을 추가하여, 통합 테스트 시 서블릿 컨테이너가 띄어집니다. RestTemplate이 아닌 TestRestTemplate을 활용한 이유는 TestRestTemplate은 SpringBootTest의 환경에 맞추어 알아서 초기화되기 때문입니다. 관련 가이드 라인은 Notion의 서버 문서에 정리해두겠습니다.

MockMvc를 활용해도 SpringBootTest이기에 Testcontainer를 활용할 수 있습니다. TestRestTemplate으로 변경한 이유는 서블릿 컨테이너를 활용하기 위해서입니다.

확인했습니다

@lcomment lcomment merged commit 098fd1e into master May 10, 2024
2 checks passed
@lcomment lcomment deleted the feature/#4 branch May 10, 2024 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore 빌드 매니저 및 환경 설정 feature 새로운 기능 개발
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants