Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static life.mosu.mosuserver.global.util.EncodeUtil.passwordEncode;

import life.mosu.mosuserver.domain.user.entity.AuthProvider;
import life.mosu.mosuserver.domain.user.entity.UserJpaEntity;
import life.mosu.mosuserver.domain.user.repository.UserJpaRepository;
import life.mosu.mosuserver.global.exception.CustomRuntimeException;
Expand Down Expand Up @@ -42,11 +43,13 @@ public ChangePasswordResponse changePassword(ChangePasswordRequest request,
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public FindLoginIdResponse findLoginId(FindLoginIdRequest request) {
UserJpaEntity user = userJpaRepository.findByNameAndPhoneNumber(request.name(),
request.phoneNumber())
PhoneNumberUtil.formatPhoneNumber(request.phoneNumber()))
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.NOT_FOUND_LOGIN_ID));
Comment on lines 45 to 47

Choose a reason for hiding this comment

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

high

휴대폰 번호 형식(하이픈 포함/미포함)에 관계없이 일관된 조회를 위해, 조회 전 휴대폰 번호를 정규화하는 것이 좋습니다. 예를 들어, request.phoneNumber()에서 하이픈을 제거한 후 formatPhoneNumber를 호출하면 사용자가 어떤 형식으로 번호를 입력하더라도 동일한 결과로 조회할 수 있습니다.

UserJpaEntitygetPhoneNumberWithoutHyphen() 메서드가 있는 것으로 보아, 데이터베이스에 하이픈이 포함된 휴대폰 번호가 저장될 수 있는 것 같습니다. 이 제안은 데이터베이스에 저장된 번호가 하이픈이 없는 숫자 형식으로 통일되어 있다는 가정 하에 유효합니다. 만약 하이픈이 포함된 형식으로 저장된다면, 정규화 방식에 대한 추가적인 논의가 필요해 보입니다.

Suggested change
UserJpaEntity user = userJpaRepository.findByNameAndPhoneNumber(request.name(),
request.phoneNumber())
PhoneNumberUtil.formatPhoneNumber(request.phoneNumber()))
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.NOT_FOUND_LOGIN_ID));
UserJpaEntity user = userJpaRepository.findByNameAndPhoneNumber(request.name(),
PhoneNumberUtil.formatPhoneNumber(request.phoneNumber().replaceAll("-", "")))
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.NOT_FOUND_LOGIN_ID));


if (user.getProvider() == AuthProvider.KAKAO) {
throw new CustomRuntimeException(ErrorCode.KAKAO_ACCOUNT_DUPLICATED);
}
return FindLoginIdResponse.from(user.getLoginId());

}

@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public enum ErrorCode {

// ID 찾기 관련
NOT_FOUND_LOGIN_ID(HttpStatus.NOT_FOUND, "해당 아이디를 찾을 수 없습니다.", CriticalLevel.LOW),
KAKAO_ACCOUNT_DUPLICATED(HttpStatus.CONFLICT, "카카오로 가입한 사용자입니다", CriticalLevel.LOW),
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Add test coverage for FindLoginId Kakao-joined path

Since this code is used in the Find ID flow, add a service-layer test that:

  • Given a user with provider=KAKAO returned by the repository (after phone formatting),
  • When FindLoginId runs,
  • Then it throws CustomRuntimeException with ErrorCode.KAKAO_ACCOUNT_DUPLICATED.

Also add a negative test asserting non-Kakao users return loginId, and a “not found” path still throws NOT_FOUND_LOGIN_ID.

You can locate usages and missing tests with:


🏁 Script executed:

#!/bin/bash
# Find new error usage sites
rg -n "KAKAO_ACCOUNT_DUPLICATED"

# Sanity-check FindLoginId flow and phone formatting
rg -n -C3 "find(Login)?Id|findByNameAndPhoneNumber|formatPhoneNumber"

# Locate exception mapping to HTTP responses (ControllerAdvice)
rg -n -C2 "CustomRuntimeException|@ExceptionHandler|ErrorCode\."

Length of output: 154354


🏁 Script executed:

#!/bin/bash
# Search for service-layer tests covering the FindLoginId flow in MyUserService
rg -n 'findLoginId' -g 'src/test/java/**'
rg -n 'MyUserService' -g 'src/test/java/**'
rg -n 'ErrorCode.KAKAO_ACCOUNT_DUPLICATED' -g 'src/test/java/**'

Length of output: 150


Add missing unit tests for MyUserService.findLoginId

The service-layer behavior for findLoginId currently lacks explicit test coverage. Please add a new test class (e.g. MyUserServiceTest) under src/test/java/life/mosu/mosuserver/application/user with the following mandatory test cases:

  • Given a user returned by userJpaRepository.findByNameAndPhoneNumber whose provider == AuthProvider.KAKAO, invoking findLoginId should throw CustomRuntimeException with ErrorCode.KAKAO_ACCOUNT_DUPLICATED.
  • Given a non-Kakao user (e.g. AuthProvider.MOSU), invoking findLoginId should return a successful FindLoginIdResponse containing the user’s loginId.
  • Given no matching user (repository returns empty), invoking findLoginId should throw CustomRuntimeException with ErrorCode.NOT_FOUND_LOGIN_ID.

Use Mockito (or your preferred mocking framework) to stub UserJpaRepository, and assert exception types and error codes, or response payloads, accordingly.

🤖 Prompt for AI Agents
In src/test/java/life/mosu/mosuserver/application/user/MyUserServiceTest
(covering behavior invoked from
src/main/java/life/mosu/mosuserver/global/exception/ErrorCode.java line 171),
add a test class that mocks UserJpaRepository and exercises
MyUserService.findLoginId with three cases: 1) stub findByNameAndPhoneNumber to
return a User whose provider == AuthProvider.KAKAO and assert it throws
CustomRuntimeException with ErrorCode.KAKAO_ACCOUNT_DUPLICATED; 2) stub to
return a non-KAKAO user (e.g. AuthProvider.MOSU) and assert the returned
FindLoginIdResponse contains the expected loginId; 3) stub to return
Optional.empty() and assert it throws CustomRuntimeException with
ErrorCode.NOT_FOUND_LOGIN_ID; use Mockito for stubbing and assertions on
exception type and embedded ErrorCode, and construct the service with the mocked
repository.


//결제 API 실패
PAYMENT_API_ERROR(HttpStatus.BAD_REQUEST, "결제 API 호출에 실패하였습니다.", CriticalLevel.CRITICAL),
Expand Down