-
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.
Merge pull request #229 from PLADI-ALM/test/PDS-81-login-fail
[PDS-81/test] 로그인 실패 코드 작성
- Loading branch information
Showing
5 changed files
with
30 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package com.example.pladialmserver.user.service; | ||
|
||
import com.example.pladialmserver.global.exception.BaseException; | ||
import com.example.pladialmserver.global.exception.BaseResponseCode; | ||
import com.example.pladialmserver.global.utils.JwtUtil; | ||
import com.example.pladialmserver.user.dto.TokenDto; | ||
import com.example.pladialmserver.user.dto.request.EmailPWReq; | ||
|
@@ -23,6 +25,7 @@ | |
|
||
import static com.example.pladialmserver.user.service.model.TestUserInfo.*; | ||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
|
@@ -52,7 +55,7 @@ void tearDown() { | |
@DisplayName("[성공] 로그인") | ||
void login(){ | ||
// given | ||
User user = setUpUser(setUpDepartment(), setUpAffiliation(), passwordEncoder.encode(PASSWORD)); | ||
User user = setUpUser(1L, Role.ADMIN, setUpDepartment(), setUpAffiliation(), passwordEncoder.encode(PASSWORD)); | ||
EmailPWReq req = setUpEmailPWReq("[email protected]", "asdf1234!"); | ||
|
||
// when | ||
|
@@ -72,6 +75,21 @@ void login(){ | |
verify(jwtUtil, times(1)).createToken(any(Long.class), any(Role.class)); | ||
verify(passwordEncoder, times(1)).encode(any(String.class)); | ||
} | ||
@Test | ||
@DisplayName("[실패] 로그인") | ||
void loginFail(){ | ||
// given | ||
User user = setUpUser(1L, Role.ADMIN, setUpDepartment(), setUpAffiliation(), passwordEncoder.encode(PASSWORD)); | ||
EmailPWReq req = setUpEmailPWReq("[email protected]", "asdf1234!"); | ||
// when | ||
doThrow(new BaseException(BaseResponseCode.USER_NOT_FOUND)).when(userRepository).findByEmailAndIsEnable(req.getEmail(), true); | ||
// then | ||
BaseException exception = assertThrows(BaseException.class, () -> { | ||
userService.login(req); | ||
}); | ||
assertThat(exception.getBaseResponseCode()).isEqualTo(BaseResponseCode.USER_NOT_FOUND); | ||
} | ||
|
||
|
||
@Test | ||
void getUserName() { | ||
|
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 |
---|---|---|
|
@@ -19,48 +19,18 @@ public static EmailPWReq setUpEmailPWReq(String email, String pw){ | |
.build(); | ||
} | ||
|
||
public static User setUpUser(Department department, Affiliation affiliation, String password){ | ||
return User.builder() | ||
.userId(1L) | ||
.name("홍길동") | ||
.email("[email protected]") | ||
.password(password) | ||
.fcmToken("1234545") | ||
.phone("010-0000-0000") | ||
.department(department) | ||
.role(Role.ADMIN) | ||
.assets("A12345") | ||
.affiliation(affiliation) | ||
.build(); | ||
} | ||
|
||
public static User setUpUser(Long userId, Role role, Department department, Affiliation affiliation, String password){ | ||
return new User( | ||
userId, | ||
"홍길동", | ||
"[email protected]", | ||
password, | ||
department, | ||
"010-0000-0000", | ||
role, | ||
"1234545", | ||
"A12345", | ||
affiliation); | ||
} | ||
|
||
public static User setUpBasicUser(Department department, Affiliation affiliation, String password){ | ||
return User.builder() | ||
.userId(1L) | ||
.name("홍길동") | ||
.email("[email protected]") | ||
.password(password) | ||
.fcmToken("1234545") | ||
.phone("010-0000-0000") | ||
.department(department) | ||
.role(Role.BASIC) | ||
.assets("A12345") | ||
.affiliation(affiliation) | ||
.build(); | ||
department, | ||
role, | ||
affiliation, | ||
"1234545"); | ||
} | ||
|
||
public static Department setUpDepartment(){ | ||
|