Skip to content

Commit

Permalink
[#16] feat: user response json 내에 null값 들어가도록 변경
Browse files Browse the repository at this point in the history
- rest docs 생성 시 null이 들어가는 것을 금지하므로 optional()을 통해 이를 허용
  • Loading branch information
jinyoungchoi95 committed Aug 21, 2021
1 parent e97bff4 commit b2b4397
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -96,8 +97,8 @@ void joinTest() throws Exception {

.andExpect(jsonPath("$.user.username", is("username")))
.andExpect(jsonPath("$.user.email", is("[email protected]")))
.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(),
Expand All @@ -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()
)
))
;
Expand Down Expand Up @@ -155,8 +158,8 @@ void loginTest() throws Exception {

.andExpect(jsonPath("$.user.username", is("username")))
.andExpect(jsonPath("$.user.email", is("[email protected]")))
.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(),
Expand All @@ -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()
)
))
;
Expand Down Expand Up @@ -203,8 +208,8 @@ void getCurrentUserTest() throws Exception {

.andExpect(jsonPath("$.user.username", is("username")))
.andExpect(jsonPath("$.user.email", is("[email protected]")))
.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(),
Expand All @@ -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()
)
))
;
Expand Down Expand Up @@ -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()
)
))
;
Expand Down

0 comments on commit b2b4397

Please sign in to comment.