Skip to content

Commit

Permalink
KL-100/test: revise test code
Browse files Browse the repository at this point in the history
- 엔드포인트를 controller와 동일하게 수정
- 입력한 dummy data에 맞게 예상 속성값 수정
  • Loading branch information
ohhamma committed Jul 22, 2024
1 parent 7ce8105 commit f112700
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import taco.klkl.domain.user.dao.UserRepository;
import taco.klkl.domain.user.domain.User;
import taco.klkl.domain.user.service.UserService;
import taco.klkl.global.common.enums.Gender;

@SpringBootTest
@AutoConfigureMockMvc
Expand All @@ -29,19 +28,13 @@ public class UserIntegrationTest {
@Autowired
UserRepository userRepository;

User user;

@Test
public void testUserMe() throws Exception {
// given
User user = new User(null, "testUser", Gender.MALE, 20, "테스트 유저입니다.");

// when
userRepository.save(user);
user = userService.me();
// given, when
User user = userService.me();

// then
mockMvc.perform(get("/api/v1/users/me"))
mockMvc.perform(get("/v1/users/me"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.isSuccess", is(true)))
.andExpect(jsonPath("$.code", is("C000")))
Expand All @@ -50,7 +43,7 @@ public void testUserMe() throws Exception {
.andExpect(jsonPath("$.data.gender", is(user.getGender().toString())))
.andExpect(jsonPath("$.data.age", is(user.getAge())))
.andExpect(jsonPath("$.data.description", is(user.getDescription())))
.andExpect(jsonPath("$.data.profile", is("image/default.jpg")))
.andExpect(jsonPath("$.data.profile", is("image/test.jpg")))
.andExpect(jsonPath("$.data.createdAt", notNullValue()))
.andExpect(jsonPath("$.timestamp", notNullValue()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void getMe() throws Exception {
Mockito.when(userService.me()).thenReturn(user);

// when & then
mockMvc.perform(get("/api/v1/users/me")
mockMvc.perform(get("/v1/users/me")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.isSuccess", is(true)))
Expand Down

0 comments on commit f112700

Please sign in to comment.