Skip to content

Commit

Permalink
test: 방 수정 통합 테스트 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
ymkim97 committed Oct 31, 2023
1 parent 2dd7c1a commit 7b8ff99
Showing 1 changed file with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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());
}
}

0 comments on commit 7b8ff99

Please sign in to comment.