From 7b8ff993f70725f5f87db400c7056c161437f42d Mon Sep 17 00:00:00 2001 From: ymkim97 Date: Tue, 31 Oct 2023 17:18:56 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=EB=B0=A9=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=ED=86=B5=ED=95=A9=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/presentation/RoomControllerTest.java | 70 ++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/moabam/api/presentation/RoomControllerTest.java b/src/test/java/com/moabam/api/presentation/RoomControllerTest.java index 164b192a..55668783 100644 --- a/src/test/java/com/moabam/api/presentation/RoomControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/RoomControllerTest.java @@ -22,10 +22,13 @@ import org.springframework.transaction.annotation.Transactional; import com.fasterxml.jackson.databind.ObjectMapper; +import com.moabam.api.domain.entity.Participant; +import com.moabam.api.domain.entity.Room; import com.moabam.api.domain.repository.ParticipantRepository; import com.moabam.api.domain.repository.RoomRepository; import com.moabam.api.domain.repository.RoutineRepository; import com.moabam.api.dto.CreateRoomRequest; +import com.moabam.api.dto.ModifyRoomRequest; @Transactional @SpringBootTest @@ -193,7 +196,7 @@ void create_morning_room_wrong_certify_time_fail(int certifyTime) throws Excepti .andDo(print()); } - @DisplayName("올바르지 못한 시간으로 저녁 방 생성") + @DisplayName("올바르지 못한 시간으로 저녁 방 생성시 에외 발생") @ParameterizedTest @CsvSource({ "19", "3", "6", "9" @@ -216,4 +219,69 @@ void create_night_room_wrong_certify_time_fail(int certifyTime) throws Exception .andExpect(status().isBadRequest()) .andDo(print()); } + + @DisplayName("방 수정 성공 - 방장일 경우") + @Test + void modify_room_success() throws Exception { + // given + Room room = Room.builder() + .title("처음 제목") + .password("1234") + .roomType(MORNING) + .certifyTime(9) + .maxUserCount(5) + .build(); + + Participant participant = Participant.builder() + .room(room) + .memberId(1L) + .build(); + participant.enableManager(); + + Room savedRoom = roomRepository.save(room); + participantRepository.save(participant); + + ModifyRoomRequest modifyRoomRequest = new ModifyRoomRequest("수정할 방임!", "1234", 10, 7); + + String json = objectMapper.writeValueAsString(modifyRoomRequest); + + // expected + mockMvc.perform(put("/rooms/" + savedRoom.getId()) + .contentType(APPLICATION_JSON) + .content(json)) + .andExpect(status().isOk()) + .andDo(print()); + } + + @DisplayName("방 수정 실패 - 방장 아닐 경우") + @Test + void unauthorized_modify_room_fail() throws Exception { + // given + Room room = Room.builder() + .title("처음 제목") + .password("1234") + .roomType(MORNING) + .certifyTime(9) + .maxUserCount(5) + .build(); + + Participant participant = Participant.builder() + .room(room) + .memberId(1L) + .build(); + + Room savedRoom = roomRepository.save(room); + participantRepository.save(participant); + + ModifyRoomRequest modifyRoomRequest = new ModifyRoomRequest("수정할 방임!", "1234", 10, 7); + + String json = objectMapper.writeValueAsString(modifyRoomRequest); + + // expected + mockMvc.perform(put("/rooms/" + savedRoom.getId()) + .contentType(APPLICATION_JSON) + .content(json)) + .andExpect(status().isNotFound()) + .andDo(print()); + } }