Skip to content

Commit 003b24c

Browse files
committed
test(VolunteerQueryController): 타인 프로필 조회 컨트롤러 테스트 추가
1 parent 0b2cce9 commit 003b24c

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.somemore.volunteer.controller;
2+
3+
import com.somemore.ControllerTestSupport;
4+
import com.somemore.volunteer.dto.response.VolunteerResponseDto;
5+
import com.somemore.volunteer.usecase.VolunteerQueryUseCase;
6+
import org.junit.jupiter.api.DisplayName;
7+
import org.junit.jupiter.api.Test;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.boot.test.mock.mockito.MockBean;
10+
import org.springframework.http.MediaType;
11+
import org.springframework.test.web.servlet.MockMvc;
12+
13+
import java.util.UUID;
14+
15+
import static org.mockito.BDDMockito.given;
16+
import static org.mockito.Mockito.times;
17+
import static org.mockito.Mockito.verify;
18+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
19+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
20+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
21+
22+
class VolunteerQueryControllerTest extends ControllerTestSupport {
23+
24+
@Autowired
25+
private MockMvc mockMvc;
26+
27+
@MockBean
28+
private VolunteerQueryUseCase volunteerQueryUseCase;
29+
30+
@Test
31+
@DisplayName("타인의 프로필을 조회할 수 있다.")
32+
void getVolunteerProfile() throws Exception {
33+
// given
34+
UUID volunteerId = UUID.randomUUID();
35+
VolunteerResponseDto responseDto = createMockVolunteerResponse();
36+
37+
given(volunteerQueryUseCase.getVolunteerProfile(volunteerId)).willReturn(responseDto);
38+
39+
// when & then
40+
mockMvc.perform(get("/profile/{volunteerId}", volunteerId)
41+
.accept(MediaType.APPLICATION_JSON))
42+
.andExpect(status().isOk())
43+
.andExpect(jsonPath("$.code").value(200))
44+
.andExpect(jsonPath("$.data").exists())
45+
.andExpect(jsonPath("$.message").value("프로필 조회 성공"));
46+
47+
verify(volunteerQueryUseCase, times(1)).getVolunteerProfile(volunteerId);
48+
}
49+
50+
private VolunteerResponseDto createMockVolunteerResponse() {
51+
return new VolunteerResponseDto(
52+
UUID.randomUUID().toString(),
53+
"Test",
54+
"http://example.com/image.jpg",
55+
"Ima volunteer!",
56+
"Red",
57+
100,
58+
10,
59+
null
60+
);
61+
}
62+
}

0 commit comments

Comments
 (0)