Skip to content

Commit

Permalink
test: 테스트 위치 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Arachneee committed Nov 15, 2024
1 parent 1fba37e commit 14e4090
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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")
)
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 14e4090

Please sign in to comment.