Skip to content

Commit

Permalink
refactor: 피드 생성 api 문서화 업데이트
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonjerry committed Sep 21, 2023
1 parent a8663bc commit 67a2b2d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
8 changes: 6 additions & 2 deletions backend/emm-sale/src/documentTest/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ include::{snippets}/get-rooms-interlocutorId/http-request.adoc[]

.HTTP request 설명
senderId와 receiverId는 의미 없어서 참여자 ID들을 변수명에 상관없이 보내주시면 됩니다.

include::{snippets}/get-rooms-interlocutorId/request-parameters.adoc[]

.HTTP response
Expand Down Expand Up @@ -725,8 +726,11 @@ include::{snippets}/find-detail-feed/response-fields.adoc[]

=== `POST`: 피드 등록

.HTTP request
include::{snippets}/post-feed/http-request.adoc[]
```http
POST /feeds HTTP/1.1
Content-Type: multipart/form-data; boundary=6o2knFse3p53ty9dmcQvWAIx1zInP11uCfbm
Host: localhost:8080
```

.HTTP request 설명
include::{snippets}/post-feed/request-fields.adoc[]
Expand Down
47 changes: 24 additions & 23 deletions backend/emm-sale/src/documentTest/java/com/emmsale/FeedApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.restdocs.payload.RequestFieldsSnippet;
import org.springframework.restdocs.payload.ResponseFieldsSnippet;
import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder;

class FeedApiTest extends MockMvcTestHelper {

Expand Down Expand Up @@ -103,39 +104,39 @@ void findDetailFeedTest() throws Exception {
@DisplayName("이벤트의 피드를 성공적으로 저장하면 201 CREATED를 반환한다.")
void postFeedTest() throws Exception {
//given
final RequestFieldsSnippet requestFields = requestFields(
fieldWithPath("eventId").type(JsonFieldType.NUMBER).description("이벤트 id"),
fieldWithPath("title").type(JsonFieldType.STRING).description("피드 제목"),
fieldWithPath("content").type(JsonFieldType.STRING).description("피드 내용"),
fieldWithPath("parentComment.parentId").description("부모 댓글 ID").optional()
final List<MockMultipartFile> images = List.of(
new MockMultipartFile(
"picture",
"picture.jpg",
MediaType.TEXT_PLAIN_VALUE,
"test data".getBytes()
),
new MockMultipartFile(
"picture",
"picture.jpg",
MediaType.TEXT_PLAIN_VALUE,
"test data".getBytes()
)
);

final long eventId = 1L;
final long feedId = 3L;
final String 피드_제목 = "피드 제목";
final String 피드_내용 = "피드 내용";

final MockMultipartHttpServletRequestBuilder builder = multipart("/feeds")
.file("eventId", String.valueOf(eventId).getBytes())
.file("title", 피드_제목.getBytes())
.file("content", 피드_내용.getBytes())
.file("images", images.get(0).getBytes())
.file("images", images.get(1).getBytes());

when(feedCommandService.postFeed(any(), any(), any())).thenReturn(feedId);

//when & then
final MockMultipartFile eventid = new MockMultipartFile("eventId", "",
"application/json", "1".getBytes());
final MockMultipartFile title = new MockMultipartFile("title", "",
"application/json", "title".getBytes());
final MockMultipartFile content = new MockMultipartFile("content", "",
"application/json", "content".getBytes());

final MockMultipartFile images = new MockMultipartFile("images", "image.jpg",
"multipart/form-data", "image".getBytes());

mockMvc.perform(multipart("/feeds")
.file(eventid)
.file(title)
.file(content)
.file(images))
mockMvc.perform(builder)
.andExpect(status().isCreated())
.andDo(print())
.andExpect(status().isCreated());
//.andDo(document("post-feed", requestFields, responseFields));
.andDo(document("post-feed"));
}

@Test
Expand Down

0 comments on commit 67a2b2d

Please sign in to comment.