From b2b4397a98c5ec78e56168a931ad61533a2627e7 Mon Sep 17 00:00:00 2001 From: jinyoungchoi95 Date: Sun, 22 Aug 2021 01:03:57 +0900 Subject: [PATCH] =?UTF-8?q?[#16]=20feat:=20user=20response=20json=20?= =?UTF-8?q?=EB=82=B4=EC=97=90=20null=EA=B0=92=20=EB=93=A4=EC=96=B4?= =?UTF-8?q?=EA=B0=80=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - rest docs 생성 시 null이 들어가는 것을 금지하므로 optional()을 통해 이를 허용 --- .../controller/response/UserResponse.java | 4 +-- .../user/controller/UserControllerTest.java | 29 ++++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/study/realworld/user/controller/response/UserResponse.java b/src/main/java/com/study/realworld/user/controller/response/UserResponse.java index fcde34f7..05123e44 100644 --- a/src/main/java/com/study/realworld/user/controller/response/UserResponse.java +++ b/src/main/java/com/study/realworld/user/controller/response/UserResponse.java @@ -61,8 +61,8 @@ public static UserResponse fromUserAndToken(User user, String accessToken) { return new UserResponse( valueOf(user.getUsername()), valueOf(user.getEmail()), - valueOf(user.getBio()), - valueOf(user.getImage()), + user.getBio(), + user.getImage(), valueOf(accessToken) ); } diff --git a/src/test/java/com/study/realworld/user/controller/UserControllerTest.java b/src/test/java/com/study/realworld/user/controller/UserControllerTest.java index a55428b5..2025cd5b 100644 --- a/src/test/java/com/study/realworld/user/controller/UserControllerTest.java +++ b/src/test/java/com/study/realworld/user/controller/UserControllerTest.java @@ -3,6 +3,7 @@ import static com.study.realworld.user.controller.ApiDocumentUtils.getDocumentRequest; import static com.study.realworld.user.controller.ApiDocumentUtils.getDocumentResponse; import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; @@ -96,8 +97,8 @@ void joinTest() throws Exception { .andExpect(jsonPath("$.user.username", is("username"))) .andExpect(jsonPath("$.user.email", is("test@test.com"))) - .andExpect(jsonPath("$.user.bio", is("null"))) - .andExpect(jsonPath("$.user.image", is("null"))) + .andExpect(jsonPath("$.user.bio", is(nullValue()))) + .andExpect(jsonPath("$.user.image", is(nullValue()))) .andExpect(jsonPath("$.user.token", is("token"))) .andDo(document("user-join", getDocumentRequest(), @@ -115,8 +116,10 @@ void joinTest() throws Exception { fieldWithPath("user.email").type(JsonFieldType.STRING).description("이메일"), fieldWithPath("user.token").type(JsonFieldType.STRING).description("로그인 토큰"), fieldWithPath("user.username").type(JsonFieldType.STRING).description("유저이름"), - fieldWithPath("user.bio").type(JsonFieldType.STRING).description("bio"), + fieldWithPath("user.bio").type(JsonFieldType.STRING).description("bio") + .optional(), fieldWithPath("user.image").type(JsonFieldType.STRING).description("이미지") + .optional() ) )) ; @@ -155,8 +158,8 @@ void loginTest() throws Exception { .andExpect(jsonPath("$.user.username", is("username"))) .andExpect(jsonPath("$.user.email", is("test@test.com"))) - .andExpect(jsonPath("$.user.bio", is("null"))) - .andExpect(jsonPath("$.user.image", is("null"))) + .andExpect(jsonPath("$.user.bio", is(nullValue()))) + .andExpect(jsonPath("$.user.image", is(nullValue()))) .andExpect(jsonPath("$.user.token", is("token"))) .andDo(document("user-login", getDocumentRequest(), @@ -169,8 +172,10 @@ void loginTest() throws Exception { fieldWithPath("user.email").type(JsonFieldType.STRING).description("이메일"), fieldWithPath("user.token").type(JsonFieldType.STRING).description("로그인 토큰"), fieldWithPath("user.username").type(JsonFieldType.STRING).description("유저이름"), - fieldWithPath("user.bio").type(JsonFieldType.STRING).description("bio"), + fieldWithPath("user.bio").type(JsonFieldType.STRING).description("bio") + .optional(), fieldWithPath("user.image").type(JsonFieldType.STRING).description("이미지") + .optional() ) )) ; @@ -203,8 +208,8 @@ void getCurrentUserTest() throws Exception { .andExpect(jsonPath("$.user.username", is("username"))) .andExpect(jsonPath("$.user.email", is("test@test.com"))) - .andExpect(jsonPath("$.user.bio", is("null"))) - .andExpect(jsonPath("$.user.image", is("null"))) + .andExpect(jsonPath("$.user.bio", is(nullValue()))) + .andExpect(jsonPath("$.user.image", is(nullValue()))) .andExpect(jsonPath("$.user.token", is("token"))) .andDo(document("user-get-current", getDocumentRequest(), @@ -213,8 +218,10 @@ void getCurrentUserTest() throws Exception { fieldWithPath("user.email").type(JsonFieldType.STRING).description("이메일"), fieldWithPath("user.token").type(JsonFieldType.STRING).description("로그인 토큰"), fieldWithPath("user.username").type(JsonFieldType.STRING).description("유저이름"), - fieldWithPath("user.bio").type(JsonFieldType.STRING).description("bio"), + fieldWithPath("user.bio").type(JsonFieldType.STRING).description("bio") + .optional(), fieldWithPath("user.image").type(JsonFieldType.STRING).description("이미지") + .optional() ) )) ; @@ -276,8 +283,10 @@ void updateTest() throws Exception { fieldWithPath("user.email").type(JsonFieldType.STRING).description("이메일"), fieldWithPath("user.token").type(JsonFieldType.STRING).description("로그인 토큰"), fieldWithPath("user.username").type(JsonFieldType.STRING).description("유저이름"), - fieldWithPath("user.bio").type(JsonFieldType.STRING).description("bio"), + fieldWithPath("user.bio").type(JsonFieldType.STRING).description("bio") + .optional(), fieldWithPath("user.image").type(JsonFieldType.STRING).description("이미지") + .optional() ) )) ;