-
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.
feat: 가입된 유저라면 201 OK 반환, 가입되지 않은 유저라면 302 FOUND 반환
- Loading branch information
Showing
12 changed files
with
245 additions
and
21 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
26 changes: 26 additions & 0 deletions
26
backend/src/main/java/com/funeat/auth/dto/SignUserDto.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,26 @@ | ||
package com.funeat.auth.dto; | ||
|
||
import com.funeat.member.domain.Member; | ||
|
||
public class SignUserDto { | ||
|
||
private final boolean isSignIn; | ||
private final Member member; | ||
|
||
public SignUserDto(final boolean isSignIn, final Member member) { | ||
this.isSignIn = isSignIn; | ||
this.member = member; | ||
} | ||
|
||
public static SignUserDto of(final boolean isSignIn, final Member member) { | ||
return new SignUserDto(isSignIn, member); | ||
} | ||
|
||
public boolean isSignIn() { | ||
return isSignIn; | ||
} | ||
|
||
public Member getMember() { | ||
return member; | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
backend/src/test/java/com/funeat/acceptance/auth/AuthAcceptanceTest.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,40 @@ | ||
package com.funeat.acceptance.auth; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.funeat.acceptance.common.AcceptanceTest; | ||
import com.funeat.auth.application.AuthService; | ||
import io.restassured.response.ExtractableResponse; | ||
import io.restassured.response.Response; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
@SuppressWarnings("NonAsciiCharacters") | ||
public class AuthAcceptanceTest extends AcceptanceTest { | ||
|
||
@Autowired | ||
private AuthService authService; | ||
|
||
@Test | ||
void 유저가_카카오_로그인_버튼을_누르면_카카오_로그인_페이지로_리다이렉트할_수_있다() { | ||
// given | ||
final var response = 카카오_로그인_버튼_클릭(); | ||
final var expected = authService.getLoginRedirectUri(); | ||
|
||
// when | ||
final String actual = response.header("Location"); | ||
|
||
// then | ||
assertThat(actual).isEqualTo(expected); | ||
} | ||
|
||
private ExtractableResponse<Response> 카카오_로그인_버튼_클릭() { | ||
return given() | ||
.redirects().follow(false) | ||
.when() | ||
.get("/api/auth/kakao") | ||
.then() | ||
.extract(); | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
backend/src/test/java/com/funeat/auth/application/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,41 @@ | ||
package com.funeat.auth.application; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.funeat.auth.dto.SignUserDto; | ||
import com.funeat.common.DataClearExtension; | ||
import com.funeat.member.domain.Member; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Transactional | ||
@SpringBootTest | ||
@ExtendWith(DataClearExtension.class) | ||
@SuppressWarnings("NonAsciiCharacters") | ||
@DisplayNameGeneration(ReplaceUnderscores.class) | ||
public class AuthServiceTest { | ||
|
||
@Autowired | ||
private AuthService authService; | ||
|
||
@Test | ||
void 카카오_로그인을_하여_유저_정보를_가져온다() { | ||
// given | ||
final var code = "test"; | ||
final var member = new Member("test", "https://www.test.com", "1"); | ||
final var expected = SignUserDto.of(true, member); | ||
|
||
// when | ||
final var actual = authService.loginWithKakao(code); | ||
|
||
// then | ||
assertThat(actual).usingRecursiveComparison() | ||
.ignoringFields("member.id") | ||
.isEqualTo(expected); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
backend/src/test/java/com/funeat/auth/presentation/AuthControllerTest.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,65 @@ | ||
package com.funeat.auth.presentation; | ||
|
||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import com.funeat.auth.application.AuthService; | ||
import com.funeat.auth.dto.SignUserDto; | ||
import com.funeat.member.domain.Member; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
@WebMvcTest(AuthController.class) | ||
@SuppressWarnings("NonAsciiCharacters") | ||
public class AuthControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@MockBean | ||
private AuthService authService; | ||
|
||
@Nested | ||
class loginAuthorizeUser_테스트 { | ||
|
||
@Test | ||
void 이미_가입된_유저라면_홈_경로로_리다이렉트한다() throws Exception { | ||
// given | ||
final var code = "test"; | ||
final var member = new Member("test", "www.test.com", "1"); | ||
final var signUserDto = SignUserDto.of(true, member); | ||
|
||
// when | ||
when(authService.loginWithKakao(code)).thenReturn(signUserDto); | ||
|
||
// then | ||
mockMvc.perform(get("/login/oauth2/code/kakao") | ||
.param("code", code)) | ||
.andExpect(status().isFound()) | ||
.andExpect(redirectedUrl("/")); | ||
} | ||
|
||
@Test | ||
void 가입되지_않은_유저라면_프로필_경로로_리다이렉트한다() throws Exception { | ||
// given | ||
final var code = "test"; | ||
final var member = new Member("test", "www.test.com", "1"); | ||
final var signUserDto = SignUserDto.of(false, member); | ||
|
||
// when | ||
when(authService.loginWithKakao(code)).thenReturn(signUserDto); | ||
|
||
// then | ||
mockMvc.perform(get("/login/oauth2/code/kakao") | ||
.param("code", code)) | ||
.andExpect(status().isFound()) | ||
.andExpect(redirectedUrl("/profile")); | ||
} | ||
} | ||
} |
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