Skip to content

Commit 10cd790

Browse files
committed
test(VolunteerSignController): OAuth 로그인 및 로그아웃 통합 테스트 추가
- 유효한 OAuth 제공자로 로그인 URL 생성 테스트 추가 - 지원되지 않는 OAuth 제공자에 대해 400 에러 반환 테스트 추가 - 로그아웃 요청 시 성공 메시지 반환 테스트 추가
1 parent 300c301 commit 10cd790

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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

Comments
 (0)