-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: 인증 서비스 단위 테스트 추가 * fix: 테스트 커버리지 향상 * fix: 차량 테스트 커버리지 향상 * fix: 멤버 테스트 커버리지 향상 * test: 주유소 테스트 커버리지 향상 * fix: 시험장 테스트 커버리지 향상 * test: 테스트 커버리지 향상
- Loading branch information
Showing
22 changed files
with
530 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ private Constant() {} | |
LocalDateTime.now().withHour(12).withMinute(0).withSecond(0).withNano(0); | ||
|
||
public static final LocalDateTime TOMORROW = NOW.plusDays(1L); | ||
public static final LocalDateTime DAY_AFTER_TOMORROW = NOW.plusDays(2L); | ||
public static final LocalDateTime YESTERDAY = NOW.minusDays(1L); | ||
|
||
/** Member */ | ||
|
@@ -23,6 +24,7 @@ private Constant() {} | |
public static final String MEMBER_EMAIL = "[email protected]"; | ||
public static final String ANOTHER_MEMBER_EMAIL = "[email protected]"; | ||
public static final String MEMBER_PASSWORD = "1234abcd@"; | ||
public static final String ANOTHER_MEMBER_PASSWORD = "dcba4321@"; | ||
public static final Role MEMBER_ROLE = Role.ADMIN; | ||
public static final String DEPARTMENT_NAME = "모비스시스템팀"; | ||
|
||
|
@@ -47,7 +49,11 @@ private Constant() {} | |
public static final double TRACK_LENGTH = 1230.6; | ||
public static final LocalDate TRACK_RESERVATION_DATE = TOMORROW.toLocalDate(); | ||
public static final LocalDateTime TRACK_RESERVATION_SLOT_STARTED_AT = TOMORROW.withHour(11); | ||
public static final LocalDateTime ANOTHER_TRACK_RESERVATION_SLOT_STARTED_AT = | ||
TOMORROW.withHour(12); | ||
public static final LocalDateTime TRACK_RESERVATION_SLOT_EXPIRED_AT = TOMORROW.withHour(12); | ||
public static final LocalDateTime ANOTHER_TRACK_RESERVATION_SLOT_EXPIRED_AT = | ||
TOMORROW.withHour(13); | ||
|
||
/** Gas Station */ | ||
public static final String GAS_STATION_NAME = "서산주유소A"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/test/java/com/testcar/car/domains/auth/AuthServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.testcar.car.domains.auth; | ||
|
||
import static com.testcar.car.common.Constant.MEMBER_PASSWORD; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.testcar.car.common.MemberEntityFactory; | ||
import com.testcar.car.common.auth.JwtService; | ||
import com.testcar.car.common.exception.NotFoundException; | ||
import com.testcar.car.common.exception.UnauthorizedException; | ||
import com.testcar.car.domains.auth.model.LoginRequest; | ||
import com.testcar.car.domains.auth.request.AuthRequestFactory; | ||
import com.testcar.car.domains.auth.util.PasswordEncoder; | ||
import com.testcar.car.domains.member.entity.Member; | ||
import com.testcar.car.domains.member.repository.MemberRepository; | ||
import java.util.Optional; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class AuthServiceTest { | ||
@Mock private JwtService jwtService; | ||
@Mock private MemberRepository memberRepository; | ||
@InjectMocks private AuthService authService; | ||
|
||
private static Member member; | ||
private static final String encodedPassword = PasswordEncoder.encode(MEMBER_PASSWORD); | ||
private static final String token = "generatedToken"; | ||
|
||
@BeforeAll | ||
public static void setUp() { | ||
member = MemberEntityFactory.createMemberBuilder().password(encodedPassword).build(); | ||
} | ||
|
||
@Test | ||
public void 로그인_성공_테스트() { | ||
// given | ||
final LoginRequest request = AuthRequestFactory.createLoginRequest(); | ||
when(memberRepository.findByEmailAndDeletedFalse(request.getEmail())) | ||
.thenReturn(Optional.of(member)); | ||
when(jwtService.generateAccessToken(member.getId())).thenReturn(token); | ||
|
||
// when | ||
String result = authService.login(request); | ||
|
||
// then | ||
assertNotNull(result); | ||
assertEquals(token, result); | ||
} | ||
|
||
@Test | ||
public void 해당_아이디의_사용자가_DB에_존재하지_않으면_예외가_발생한다() { | ||
// given | ||
final LoginRequest request = AuthRequestFactory.createLoginRequest(); | ||
when(memberRepository.findByEmailAndDeletedFalse(request.getEmail())) | ||
.thenReturn(Optional.empty()); | ||
|
||
// when, then | ||
assertThrows( | ||
NotFoundException.class, | ||
() -> { | ||
authService.login(request); | ||
}); | ||
} | ||
|
||
@Test | ||
public void 잘못된_비밀번호를_입력하면_예외가_발생한다() { | ||
// given | ||
final LoginRequest invaildRequest = AuthRequestFactory.createInvalidLoginRequest(); | ||
when(memberRepository.findByEmailAndDeletedFalse(invaildRequest.getEmail())) | ||
.thenReturn(Optional.of(member)); | ||
|
||
// when, then | ||
assertThrows( | ||
UnauthorizedException.class, | ||
() -> { | ||
authService.login(invaildRequest); | ||
}); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/java/com/testcar/car/domains/auth/request/AuthRequestFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.testcar.car.domains.auth.request; | ||
|
||
import static com.testcar.car.common.Constant.ANOTHER_MEMBER_PASSWORD; | ||
import static com.testcar.car.common.Constant.MEMBER_EMAIL; | ||
import static com.testcar.car.common.Constant.MEMBER_PASSWORD; | ||
|
||
import com.testcar.car.domains.auth.model.LoginRequest; | ||
|
||
public class AuthRequestFactory { | ||
private AuthRequestFactory() {} | ||
|
||
public static LoginRequest createLoginRequest() { | ||
return LoginRequest.builder().email(MEMBER_EMAIL).password(MEMBER_PASSWORD).build(); | ||
} | ||
|
||
public static LoginRequest createInvalidLoginRequest() { | ||
return LoginRequest.builder().email(MEMBER_EMAIL).password(ANOTHER_MEMBER_PASSWORD).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.