Skip to content

Commit

Permalink
test: 테스트 코드 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
peeerr committed Oct 22, 2024
1 parent 6893f49 commit a48ae77
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spring:
jdbc:
time_zone: Asia/Seoul
hibernate:
ddl-auto: update
ddl-auto: none

h2:
console:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@ActiveProfiles("dev")
@SpringBootTest
class EverymomentApplicationTests {

@Test
void contextLoads() {
}
@Test
void contextLoads() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.BDDMockito.willDoNothing;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

Expand All @@ -22,8 +24,7 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.security.test.context.support.WithMockUser;
Expand All @@ -32,8 +33,7 @@
import org.springframework.web.multipart.MultipartFile;

@WithMockUser
@AutoConfigureMockMvc
@SpringBootTest
@WebMvcTest(MemberController.class)
class MemberControllerTest {

@Autowired
Expand Down Expand Up @@ -146,13 +146,15 @@ void should_UpdateMemberInfo_When_ValidInput() throws Exception {
@DisplayName("프로필 이미지와 닉네임이 모두 누락되면 예외가 발생한다.")
void should_ThrowException_When_ProfileImageAndNicknameAreMissing() throws Exception {
// when
ResultActions result = mockMvc.perform(multipart("/api/members"));
ResultActions result = mockMvc.perform(multipart("/api/members")
.with(csrf()));

// then
result
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.code").value(INFO_REQUIRED.getStatus().value()))
.andExpect(jsonPath("$.message").value(INFO_REQUIRED.getMessage()));
.andExpect(jsonPath("$.message").value(INFO_REQUIRED.getMessage()))
.andDo(print());

then(memberService).shouldHaveNoInteractions();
}
Expand Down Expand Up @@ -180,7 +182,8 @@ private ResultActions performMultipart(String url, MockMultipartFile file, Strin
return mockMvc.perform(multipart(url)
.file(file)
.param("nickname", nickname)
.with(user(memberDetails)));
.with(user(memberDetails))
.with(csrf()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.ScrollPosition;
import org.springframework.data.domain.Window;
import org.springframework.test.context.ActiveProfiles;

@ActiveProfiles("dev")
@DataJpaTest
class MemberRepositoryTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.domain.ScrollPosition;
import org.springframework.data.domain.Window;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.web.multipart.MultipartFile;

@ActiveProfiles("dev")
@ExtendWith(MockitoExtension.class)
class MemberServiceTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.ScrollPosition;
import org.springframework.data.domain.Window;
import org.springframework.test.context.ActiveProfiles;

@ActiveProfiles("dev")
class PagingUtilTest {

private PagingUtil pagingUtil;
Expand Down

0 comments on commit a48ae77

Please sign in to comment.