1+ package com .somemore .volunteer .controller ;
2+
3+ import com .somemore .IntegrationTestSupport ;
4+ import org .junit .jupiter .api .DisplayName ;
5+ import org .junit .jupiter .api .Test ;
6+ import org .springframework .beans .factory .annotation .Autowired ;
7+ import org .springframework .boot .test .autoconfigure .web .servlet .AutoConfigureMockMvc ;
8+ import org .springframework .boot .test .context .SpringBootTest ;
9+ import org .springframework .mock .web .MockHttpServletResponse ;
10+ import org .springframework .test .web .servlet .MockMvc ;
11+
12+ import static org .assertj .core .api .Assertions .assertThat ;
13+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .post ;
14+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
15+
16+ @ SpringBootTest
17+ @ AutoConfigureMockMvc
18+ class VolunteerSignControllerTest extends IntegrationTestSupport {
19+
20+ @ Autowired
21+ private MockMvc mockMvc ;
22+
23+ @ Test
24+ @ DisplayName ("유효한 OAuth 제공자로 로그인 URL을 생성한다." )
25+ void signInWithValidProvider () throws Exception {
26+ // Given
27+ String oauthProvider = "naver" ;
28+
29+ // When
30+ // Then
31+ mockMvc .perform (post ("/api/volunteer/sign-in/oauth/{oauthProvider}" , oauthProvider ))
32+ .andExpect (status ().is3xxRedirection ())
33+ .andExpect (result -> {
34+ MockHttpServletResponse response = result .getResponse ();
35+ String redirectedUrl = response .getRedirectedUrl ();
36+ assertThat (redirectedUrl ).isNotNull ();
37+ assertThat (redirectedUrl ).contains ("oauth2/authorization/naver" );
38+ });
39+ }
40+
41+ @ Test
42+ @ DisplayName ("지원되지 않는 OAuth 제공자로 로그인 시 400 에러를 반환한다." )
43+ void signInWithInvalidProvider () throws Exception {
44+ // Given
45+ String invalidProvider = "unsupported-provider" ;
46+
47+ // When
48+ // Then
49+ mockMvc .perform (post ("/api/volunteer/sign-in/oauth/{oauthProvider}" , invalidProvider ))
50+ .andExpect (status ().isBadRequest ());
51+ }
52+
53+ @ Test
54+ @ DisplayName ("로그아웃 요청 시 성공 메시지를 반환한다." )
55+ void signOut () throws Exception {
56+ // When
57+ // Then
58+ mockMvc .perform (post ("/api/volunteer/sign-out" ))
59+ .andExpect (status ().isOk ())
60+ .andExpect (result -> {
61+ MockHttpServletResponse response = result .getResponse ();
62+ String responseBody = response .getContentAsString ();
63+ assertThat (responseBody ).contains ("로그아웃되었습니다" );
64+ });
65+ }
66+ }
0 commit comments