-
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.
* add : user login 컬럼 추가 * docs : 로그아웃 api 문서 * feat : 로그아웃 기능 추가 * feat : 로그인 시 user login 컬럼 변경 * test : 로그아웃 인수테스트 * rename : 클래스명 변경 * Test : 로그아웃 후 로그인시 isLogin 값 변경 인수테스트
- Loading branch information
Showing
11 changed files
with
230 additions
and
1 deletion.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
tht-apis/src/main/java/com/tht/thtapis/facade/LogoutFacade.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,18 @@ | ||
package com.tht.thtapis.facade; | ||
|
||
import com.tht.domain.entity.user.User; | ||
import com.tht.domain.entity.user.service.UserService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Facade | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class LogoutFacade { | ||
|
||
private final UserService userService; | ||
|
||
public void logout(final User user) { | ||
userService.logout(user); | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
tht-apis/src/main/java/com/tht/thtapis/ui/UserLogoutController.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,23 @@ | ||
package com.tht.thtapis.ui; | ||
|
||
import com.tht.domain.entity.user.User; | ||
import com.tht.thtapis.facade.LogoutFacade; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class UserLogoutController { | ||
|
||
private final LogoutFacade logoutFacade; | ||
|
||
@PostMapping("/user/logout") | ||
public ResponseEntity<Object> logout(@AuthenticationPrincipal User user) { | ||
|
||
logoutFacade.logout(user); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
tht-apis/src/test/java/com/tht/thtapis/acceptance/UserLogoutAcceptanceStep.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,17 @@ | ||
package com.tht.thtapis.acceptance; | ||
|
||
import io.restassured.RestAssured; | ||
import io.restassured.response.ExtractableResponse; | ||
import io.restassured.response.Response; | ||
|
||
class UserLogoutAcceptanceStep { | ||
|
||
public static ExtractableResponse<Response> 로그아웃_요청(String accessToken) { | ||
|
||
return RestAssured.given().log().all() | ||
.auth().oauth2(accessToken) | ||
.when().post("/user/logout") | ||
.then().log().all() | ||
.extract(); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
tht-apis/src/test/java/com/tht/thtapis/acceptance/UserLogoutAcceptanceTest.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,75 @@ | ||
package com.tht.thtapis.acceptance; | ||
|
||
import com.tht.domain.entity.user.User; | ||
import com.tht.enums.user.SNSType; | ||
import com.tht.thtapis.acceptance.config.AcceptanceTest; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static com.tht.thtapis.acceptance.UserLoginAcceptanceStep.일반로그인; | ||
import static com.tht.thtapis.acceptance.UserLogoutAcceptanceStep.로그아웃_요청; | ||
import static com.tht.thtapis.acceptance.UserSignUpAcceptanceStep.SNS_유저_생성; | ||
import static com.tht.thtapis.acceptance.UserSignUpAcceptanceStep.신규유저_생성_요청_후_토큰추출; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class UserLogoutAcceptanceTest extends AcceptanceTest { | ||
|
||
@Test | ||
@DisplayName("유저 로그아웃 성공 인수테스트") | ||
void userLogout() { | ||
|
||
String phoneNumber = "1113332222"; | ||
String username = "username"; | ||
String token = 신규유저_생성_요청_후_토큰추출(username, phoneNumber); | ||
|
||
//로그아웃 | ||
var response = 로그아웃_요청(token); | ||
assertThat(response.statusCode()).isEqualTo(200); | ||
|
||
User user = 유저정보조회(phoneNumber); | ||
assertThat(user.getIsLogin()).isFalse(); | ||
|
||
} | ||
|
||
@Test | ||
@DisplayName("로그아웃 후 일반 로그인 테스트") | ||
void normalLoginAfterLogout() { | ||
|
||
String phoneNumber = "1113332222"; | ||
String username = "username"; | ||
String token = 신규유저_생성_요청_후_토큰추출(username, phoneNumber); | ||
|
||
로그아웃_요청(token); | ||
|
||
//when | ||
일반로그인(phoneNumber, "dd"); | ||
|
||
//then | ||
User user = 유저정보조회(phoneNumber); | ||
assertThat(user.getIsLogin()).isTrue(); | ||
} | ||
|
||
@Test | ||
@DisplayName("로그아웃 후 sns 로그인 테스트") | ||
void snsLoginAfterLogout() { | ||
|
||
//sns 유저 생성 | ||
final String phoneNumber = "01012345678"; | ||
final String email = "[email protected]"; | ||
final SNSType snsType = SNSType.KAKAO; | ||
final String snsUniqueId = "snsUniqueId"; | ||
final String deviceKey = "deviceKey"; | ||
|
||
var response = SNS_유저_생성(phoneNumber, email, snsType, snsUniqueId, deviceKey); | ||
String token = response.jsonPath().getString("accessToken"); | ||
|
||
로그아웃_요청(token); | ||
|
||
//when | ||
일반로그인(phoneNumber, "ㅇㄹ"); | ||
|
||
//then | ||
User user = 유저정보조회(phoneNumber); | ||
assertThat(user.getIsLogin()).isTrue(); | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
tht-apis/src/test/java/com/tht/thtapis/documentation/UserLogoutDocumentation.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,49 @@ | ||
package com.tht.thtapis.documentation; | ||
|
||
import com.epages.restdocs.apispec.ResourceSnippetParameters; | ||
import com.tht.thtapis.controller.config.ControllerTestConfig; | ||
import com.tht.thtapis.controller.config.WithCustomMockUser; | ||
import com.tht.thtapis.facade.LogoutFacade; | ||
import com.tht.thtapis.security.SecurityConst; | ||
import com.tht.thtapis.ui.UserLogoutController; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
|
||
import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.document; | ||
import static com.epages.restdocs.apispec.ResourceDocumentation.resource; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@WebMvcTest(UserLogoutController.class) | ||
class UserLogoutDocumentation extends ControllerTestConfig { | ||
|
||
@MockBean | ||
private LogoutFacade logoutFacade; | ||
|
||
@Test | ||
@WithCustomMockUser | ||
@DisplayName("유저 로그아웃 api 문서생성") | ||
void userLogoutDocs() throws Exception { | ||
|
||
final ResultActions resultActions = mockMvc.perform(post("/user/logout") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.header(SecurityConst.AUTH_HEADER_NAME, "Bearer {ACCESS_TOKEN}") | ||
).andDo( | ||
document("로으가웃 api docs", | ||
resource( | ||
ResourceSnippetParameters.builder() | ||
.tag("유저 - 로그아웃") | ||
.description("유저 로그아웃 api") | ||
.build() | ||
)) | ||
); | ||
|
||
resultActions.andExpect(status().isOk()); | ||
} | ||
|
||
} |
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