From 87bf74a797c08c4b9057545793c1e2dc3ad115da Mon Sep 17 00:00:00 2001 From: Donghun Won Date: Wed, 16 Oct 2024 18:10:03 +0900 Subject: [PATCH] =?UTF-8?q?Test=20:=20=ED=9A=8C=EC=9B=90=ED=83=88=ED=87=B4?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oauth/controller/OauthControllerTest.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/test/java/solitour_backend/solitour/oauth/controller/OauthControllerTest.java b/src/test/java/solitour_backend/solitour/oauth/controller/OauthControllerTest.java index 171bbc5..d1ab98b 100644 --- a/src/test/java/solitour_backend/solitour/oauth/controller/OauthControllerTest.java +++ b/src/test/java/solitour_backend/solitour/oauth/controller/OauthControllerTest.java @@ -170,6 +170,36 @@ void reissueRefreshToken() throws Exception { ); } + @DisplayName("회원탈퇴") + @Test + void deleteUser() throws Exception { + Cookie accessCookie = new MockCookie("access_token", "accessToken"); + Cookie refreshCookie = new MockCookie("refresh_token", "refreshToken"); + passLogin(); + BDDMockito.given(kakaoConnector.refreshToken(any())) + .willReturn("refreshToken"); + + doNothing().when(oauthService).revokeToken("kakao", "refreshToken"); + doNothing().when(oauthService).logout(any(), any()); + doNothing().when(oauthService).deleteUser(1L); + + mockMvc.perform(delete("/api/auth/oauth2") + .queryParam("type", "kakao") + .cookie(accessCookie) + .cookie(refreshCookie) + ) + .andExpectAll( + status().isNoContent() + ) + .andDo( + document("oauthDelete", + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()) + ) + ); + } + + @DisplayName("Oauth 타입이 존재하지 않는경우 404코드가 반환된다") @Test void unsupportedLoginType() throws Exception { @@ -246,4 +276,18 @@ private void passRefreshLogin(Cookie accessCookie) { .willReturn(Optional.of(token)); } + private void passLogin() { + User user = User.builder() + .oauthId("oauthId") + .build(); + Token token = new Token(user, "accessToken"); + + BDDMockito.given(jwtTokenProvider.validateTokenNotUsable(any())) + .willReturn(false); + BDDMockito.given(jwtTokenProvider.getPayload(any())) + .willReturn(1L); + BDDMockito.given(tokenRepository.findByUserId(1L)) + .willReturn(Optional.of(token)); + } + } \ No newline at end of file