diff --git a/server/src/test/java/server/haengdong/docs/AdminEventControllerDocsTest.java b/server/src/test/java/server/haengdong/docs/AdminEventControllerDocsTest.java index bfdac698..71f18fe5 100644 --- a/server/src/test/java/server/haengdong/docs/AdminEventControllerDocsTest.java +++ b/server/src/test/java/server/haengdong/docs/AdminEventControllerDocsTest.java @@ -1,5 +1,7 @@ package server.haengdong.docs; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; import static org.springframework.restdocs.cookies.CookieDocumentation.cookieWithName; import static org.springframework.restdocs.cookies.CookieDocumentation.requestCookies; @@ -13,6 +15,7 @@ import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; import static org.springframework.restdocs.request.RequestDocumentation.partWithName; import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; @@ -28,8 +31,12 @@ import org.springframework.restdocs.payload.JsonFieldType; import server.haengdong.application.EventImageFacadeService; import server.haengdong.application.EventService; +import server.haengdong.application.request.EventAppRequest; +import server.haengdong.application.response.EventAppResponse; import server.haengdong.presentation.admin.AdminEventController; +import server.haengdong.presentation.request.EventSaveRequest; import server.haengdong.presentation.request.EventUpdateRequest; +import server.haengdong.support.fixture.Fixture; class AdminEventControllerDocsTest extends RestDocsSupport { @@ -154,4 +161,37 @@ void deleteImage() throws Exception { ) ); } + + @DisplayName("이벤트를 생성한다.") + @Test + void saveEvent() throws Exception { + EventSaveRequest eventSaveRequest = new EventSaveRequest("토다리"); + String requestBody = objectMapper.writeValueAsString(eventSaveRequest); + String eventId = "쿠키 토큰"; + EventAppResponse eventAppResponse = new EventAppResponse(eventId, 1L); + given(eventService.saveEvent(any(EventAppRequest.class))).willReturn(eventAppResponse); + + mockMvc.perform(post("/api/admin/events") + .contentType(MediaType.APPLICATION_JSON) + .content(requestBody) + .cookie(Fixture.EVENT_COOKIE)) + .andDo(print()) + .andExpect(status().isOk()) + .andDo( + document("createEvent", + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + requestFields( + fieldWithPath("eventName").type(JsonFieldType.STRING).description("행사 이름") + ), + requestCookies( + cookieWithName("accessToken").description("행사 관리자 토큰") + ), + responseFields( + fieldWithPath("eventId").type(JsonFieldType.STRING) + .description("행사 ID") + ) + ) + ); + } } diff --git a/server/src/test/java/server/haengdong/docs/EventControllerDocsTest.java b/server/src/test/java/server/haengdong/docs/EventControllerDocsTest.java index bc8a7049..461756a4 100644 --- a/server/src/test/java/server/haengdong/docs/EventControllerDocsTest.java +++ b/server/src/test/java/server/haengdong/docs/EventControllerDocsTest.java @@ -31,7 +31,6 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import server.haengdong.application.AuthService; import server.haengdong.application.EventService; -import server.haengdong.application.request.EventAppRequest; import server.haengdong.application.request.EventGuestAppRequest; import server.haengdong.application.response.EventAppResponse; import server.haengdong.application.response.EventDetailAppResponse; @@ -41,8 +40,6 @@ import server.haengdong.presentation.EventController; import server.haengdong.presentation.request.EventGuestSaveRequest; import server.haengdong.presentation.request.EventLoginRequest; -import server.haengdong.presentation.request.EventSaveRequest; -import server.haengdong.support.fixture.Fixture; class EventControllerDocsTest extends RestDocsSupport { @@ -127,39 +124,6 @@ void getMemberBillReports() throws Exception { ); } - @DisplayName("이벤트를 생성한다.") - @Test - void saveEvent() throws Exception { - EventSaveRequest eventSaveRequest = new EventSaveRequest("토다리"); - String requestBody = objectMapper.writeValueAsString(eventSaveRequest); - String eventId = "쿠키 토큰"; - EventAppResponse eventAppResponse = new EventAppResponse(eventId, 1L); - given(eventService.saveEvent(any(EventAppRequest.class))).willReturn(eventAppResponse); - given(authService.createGuestToken(1L)).willReturn("jwtToken"); - given(authService.getTokenName()).willReturn("accessToken"); - - mockMvc.perform(post("/api/events") - .contentType(MediaType.APPLICATION_JSON) - .content(requestBody) - .cookie(Fixture.EVENT_COOKIE)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.eventId").value("쿠키 토큰")) - .andDo( - document("createEvent", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint()), - requestFields( - fieldWithPath("eventName").type(JsonFieldType.STRING).description("행사 이름") - ), - responseFields( - fieldWithPath("eventId").type(JsonFieldType.STRING) - .description("행사 ID") - ) - ) - ); - } - @DisplayName("비회원으로 이벤트를 생성한다.") @Test void saveEventGuest() throws Exception {