Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RestDocs 적용 #25

Merged
merged 7 commits into from
Jul 13, 2023
Merged

RestDocs 적용 #25

merged 7 commits into from
Jul 13, 2023

Conversation

LJW25
Copy link
Collaborator

@LJW25 LJW25 commented Jul 12, 2023

📄 Summary

#15
RestDocs 기본 셋팅 완료하고, TripControllerTestcreateTrip()에 시험 적용하였습니다.

🙋🏻 More

동작을 테스트해보고 싶으시면 터미널에서

 ./gradlew clean build

명령어를 사용하여 실행 후, 생성되는 main/resources/static/docs/docs.html 파일을 열어보시면 됩니다.

구체적인 사용법은 금주 내로 노션에 정리 후 공유하겠습니다.

@LJW25 LJW25 linked an issue Jul 12, 2023 that may be closed by this pull request
3 tasks
@LJW25 LJW25 added this to the 2차 스프린트 milestone Jul 12, 2023
@LJW25 LJW25 self-assigned this Jul 12, 2023
Comment on lines 3 to 32
import com.fasterxml.jackson.databind.ObjectMapper;
import hanglog.trip.presentation.dto.request.TripRequest;
import hanglog.trip.restdocs.RestDocsConfiguration;
import hanglog.trip.restdocs.RestDocsTest;
import hanglog.trip.service.TripService;
import java.time.LocalDate;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
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.restdocs.AutoConfigureRestDocs;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.data.jpa.mapping.JpaMetamodelMappingContext;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.restdocs.payload.JsonFieldType;

import java.time.LocalDate;
import java.util.Collections;
import java.util.List;

import static hanglog.trip.restdocs.RestDocsConfiguration.field;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.springframework.http.HttpHeaders.LOCATION;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
import static org.springframework.restdocs.headers.HeaderDocumentation.responseHeaders;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

teco-style이 적용되어 있지 않은 것 같아요.! option+cmd+L 로 정렬하면 static import가 최상단으로 와야 합니다..!

Comment on lines 65 to 67
fieldWithPath("startDate").type(JsonFieldType.STRING).description("여행 시작 날짜").attributes(field("constraint", "yyyy-MM-dd")),
fieldWithPath("endDate").type(JsonFieldType.STRING).description("여행 종료 날짜").attributes(field("constraint", "yyyy-MM-dd")),
fieldWithPath("cityIds").type(JsonFieldType.ARRAY).description("도시 ID 목록").attributes(field("constraint", "1개 이상의 양의 정수"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fieldWithPath("startDate").type(JsonFieldType.STRING).description("여행 시작 날짜").attributes(field("constraint", "yyyy-MM-dd")),
fieldWithPath("endDate").type(JsonFieldType.STRING).description("여행 종료 날짜").attributes(field("constraint", "yyyy-MM-dd")),
fieldWithPath("cityIds").type(JsonFieldType.ARRAY).description("도시 ID 목록").attributes(field("constraint", "1개 이상의 양의 정수"))
requestFields(
fieldWithPath("startDate").type(JsonFieldType.STRING).description("여행 시작 날짜")
.attributes(field("constraint", "yyyy-MM-dd")),
fieldWithPath("endDate").type(JsonFieldType.STRING).description("여행 종료 날짜")
.attributes(field("constraint", "yyyy-MM-dd")),
fieldWithPath("cityIds").type(JsonFieldType.ARRAY).description("도시 ID 목록")
.attributes(field("constraint", "1개 이상의 양의 정수"))
),

여기도 가로줄 제한을 넘겨서 정렬하면 이렇게 바뀌는데 type과 description도 줄바꿈 하는 방법도 좋아 보입니다.!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

적용하였습니다 :)

Comment on lines 14 to 16
public static final Attribute field(final String key, final String value) {
return new Attribute(key, value);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
Suggested change
public static final Attribute field(final String key, final String value) {
return new Attribute(key, value);
}
public static Attribute field(final String key, final String value) {
return new Attribute(key, value);
}

Comment on lines 21 to 24
@Autowired
protected RestDocumentationResultHandler restDocs;
@Autowired
protected MockMvc mockMvc;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

필드 사이에 띄우나요 안띄우나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일반 필드 사이에는 띄우지 않고, 어노테이션이 붙은 필드는 띄우는 것으로 결정되었습니다 🔨

Copy link
Collaborator

@mcodnjs mcodnjs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굿굿굿굿 🏊‍♂️👍

@LJW25 LJW25 merged commit 69b50da into develop Jul 13, 2023
@LJW25 LJW25 deleted the feature/#15 branch July 13, 2023 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RestDocs 세팅
5 participants