diff --git a/src/main/java/com/moabam/api/application/bug/BugService.java b/src/main/java/com/moabam/api/application/bug/BugService.java index eea27cf9..76b10a9f 100644 --- a/src/main/java/com/moabam/api/application/bug/BugService.java +++ b/src/main/java/com/moabam/api/application/bug/BugService.java @@ -11,8 +11,8 @@ import com.moabam.api.application.member.MemberService; import com.moabam.api.domain.bug.BugHistory; import com.moabam.api.domain.bug.BugType; +import com.moabam.api.domain.bug.repository.BugHistorySearchRepository; import com.moabam.api.domain.member.Member; -import com.moabam.api.domain.repository.BugHistorySearchRepository; import com.moabam.api.dto.TodayBugResponse; import com.moabam.api.dto.bug.BugResponse; import com.moabam.global.common.util.ClockHolder; diff --git a/src/main/java/com/moabam/api/application/room/RoomSearchService.java b/src/main/java/com/moabam/api/application/room/RoomSearchService.java index ff6fb40e..7b063005 100644 --- a/src/main/java/com/moabam/api/application/room/RoomSearchService.java +++ b/src/main/java/com/moabam/api/application/room/RoomSearchService.java @@ -64,7 +64,7 @@ public RoomDetailsResponse getRoomDetails(Long memberId, Long roomId) { } private List getRoutineResponses(Long roomId) { - List roomRoutines = routineSearchRepository.findByRoomId(roomId); + List roomRoutines = routineSearchRepository.findAllByRoomId(roomId); return RoutineMapper.toRoutineResponses(roomRoutines); } diff --git a/src/main/java/com/moabam/api/application/room/RoomService.java b/src/main/java/com/moabam/api/application/room/RoomService.java index 7a575ddc..01ec189c 100644 --- a/src/main/java/com/moabam/api/application/room/RoomService.java +++ b/src/main/java/com/moabam/api/application/room/RoomService.java @@ -78,7 +78,7 @@ public void modifyRoom(Long memberId, Long roomId, ModifyRoomRequest modifyRoomR room.changeCertifyTime(modifyRoomRequest.certifyTime()); room.changeMaxCount(modifyRoomRequest.maxUserCount()); - List routines = routineSearchRepository.findByRoomId(roomId); + List routines = routineSearchRepository.findAllByRoomId(roomId); routineRepository.deleteAll(routines); List newRoutines = RoutineMapper.toRoutineEntities(room, modifyRoomRequest.routines()); diff --git a/src/main/java/com/moabam/api/domain/repository/BugHistorySearchRepository.java b/src/main/java/com/moabam/api/domain/bug/repository/BugHistorySearchRepository.java similarity index 96% rename from src/main/java/com/moabam/api/domain/repository/BugHistorySearchRepository.java rename to src/main/java/com/moabam/api/domain/bug/repository/BugHistorySearchRepository.java index 724289af..26a8f9ff 100644 --- a/src/main/java/com/moabam/api/domain/repository/BugHistorySearchRepository.java +++ b/src/main/java/com/moabam/api/domain/bug/repository/BugHistorySearchRepository.java @@ -1,4 +1,4 @@ -package com.moabam.api.domain.repository; +package com.moabam.api.domain.bug.repository; import static com.moabam.api.domain.bug.QBugHistory.*; diff --git a/src/main/java/com/moabam/api/domain/room/repository/RoutineSearchRepository.java b/src/main/java/com/moabam/api/domain/room/repository/RoutineSearchRepository.java index f2f11bb6..827e1b0d 100644 --- a/src/main/java/com/moabam/api/domain/room/repository/RoutineSearchRepository.java +++ b/src/main/java/com/moabam/api/domain/room/repository/RoutineSearchRepository.java @@ -17,7 +17,7 @@ public class RoutineSearchRepository { private final JPAQueryFactory jpaQueryFactory; - public List findByRoomId(Long roomId) { + public List findAllByRoomId(Long roomId) { return jpaQueryFactory .selectFrom(routine) .where( diff --git a/src/main/java/com/moabam/api/presentation/RoomController.java b/src/main/java/com/moabam/api/presentation/RoomController.java index 8439dfc6..314ac697 100644 --- a/src/main/java/com/moabam/api/presentation/RoomController.java +++ b/src/main/java/com/moabam/api/presentation/RoomController.java @@ -22,6 +22,8 @@ import com.moabam.api.dto.room.EnterRoomRequest; import com.moabam.api.dto.room.ModifyRoomRequest; import com.moabam.api.dto.room.RoomDetailsResponse; +import com.moabam.global.auth.annotation.CurrentMember; +import com.moabam.global.auth.model.AuthorizationMember; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -37,50 +39,63 @@ public class RoomController { @PostMapping @ResponseStatus(HttpStatus.CREATED) - public Long createRoom(@Valid @RequestBody CreateRoomRequest createRoomRequest) { - return roomService.createRoom(1L, createRoomRequest); + public Long createRoom(@CurrentMember AuthorizationMember authorizationMember, + @Valid @RequestBody CreateRoomRequest createRoomRequest) { + + return roomService.createRoom(authorizationMember.id(), createRoomRequest); } @PutMapping("/{roomId}") @ResponseStatus(HttpStatus.OK) - public void modifyRoom(@Valid @RequestBody ModifyRoomRequest modifyRoomRequest, - @PathVariable("roomId") Long roomId) { - roomService.modifyRoom(1L, roomId, modifyRoomRequest); + public void modifyRoom(@CurrentMember AuthorizationMember authorizationMember, + @Valid @RequestBody ModifyRoomRequest modifyRoomRequest, @PathVariable("roomId") Long roomId) { + + roomService.modifyRoom(authorizationMember.id(), roomId, modifyRoomRequest); } @PostMapping("/{roomId}") @ResponseStatus(HttpStatus.OK) - public void enterRoom(@PathVariable("roomId") Long roomId, @Valid @RequestBody EnterRoomRequest enterRoomRequest) { - roomService.enterRoom(1L, roomId, enterRoomRequest); + public void enterRoom(@CurrentMember AuthorizationMember authorizationMember, @PathVariable("roomId") Long roomId, + @Valid @RequestBody EnterRoomRequest enterRoomRequest) { + + roomService.enterRoom(authorizationMember.id(), roomId, enterRoomRequest); } @DeleteMapping("/{roomId}") @ResponseStatus(HttpStatus.OK) - public void exitRoom(@PathVariable("roomId") Long roomId) { - roomService.exitRoom(1L, roomId); + public void exitRoom(@CurrentMember AuthorizationMember authorizationMember, @PathVariable("roomId") Long roomId) { + roomService.exitRoom(authorizationMember.id(), roomId); } @GetMapping("/{roomId}") @ResponseStatus(HttpStatus.OK) - public RoomDetailsResponse getRoomDetails(@PathVariable("roomId") Long roomId) { - return roomSearchService.getRoomDetails(1L, roomId); + public RoomDetailsResponse getRoomDetails(@CurrentMember AuthorizationMember authorizationMember, + @PathVariable("roomId") Long roomId) { + + return roomSearchService.getRoomDetails(authorizationMember.id(), roomId); } @PostMapping("/{roomId}/certification") @ResponseStatus(HttpStatus.CREATED) - public void certifyRoom(@PathVariable("roomId") Long roomId, @RequestPart List multipartFiles) { - roomCertificationService.certifyRoom(1L, roomId, multipartFiles); + public void certifyRoom(@CurrentMember AuthorizationMember authorizationMember, @PathVariable("roomId") Long roomId, + @RequestPart List multipartFiles) { + + roomCertificationService.certifyRoom(authorizationMember.id(), roomId, multipartFiles); } @PutMapping("/{roomId}/members/{memberId}/mandate") @ResponseStatus(HttpStatus.OK) - public void mandateManager(@PathVariable("roomId") Long roomId, @PathVariable("memberId") Long memberId) { - roomService.mandateRoomManager(1L, roomId, memberId); + public void mandateManager(@CurrentMember AuthorizationMember authorizationMember, + @PathVariable("roomId") Long roomId, @PathVariable("memberId") Long memberId) { + + roomService.mandateRoomManager(authorizationMember.id(), roomId, memberId); } @DeleteMapping("/{roomId}/members/{memberId}") @ResponseStatus(HttpStatus.OK) - public void deportParticipant(@PathVariable("roomId") Long roomId, @PathVariable("memberId") Long memberId) { - roomService.deportParticipant(1L, roomId, memberId); + public void deportParticipant(@CurrentMember AuthorizationMember authorizationMember, + @PathVariable("roomId") Long roomId, @PathVariable("memberId") Long memberId) { + + roomService.deportParticipant(authorizationMember.id(), roomId, memberId); } } diff --git a/src/main/resources/static/docs/coupon.html b/src/main/resources/static/docs/coupon.html index dc7b0eb3..406bcda8 100644 --- a/src/main/resources/static/docs/coupon.html +++ b/src/main/resources/static/docs/coupon.html @@ -627,7 +627,7 @@

쿠폰 사용 (진행 중)

diff --git a/src/main/resources/static/docs/index.html b/src/main/resources/static/docs/index.html index 3b245d88..8f28a0c8 100644 --- a/src/main/resources/static/docs/index.html +++ b/src/main/resources/static/docs/index.html @@ -616,7 +616,7 @@

diff --git a/src/main/resources/static/docs/notification.html b/src/main/resources/static/docs/notification.html index 0e9f868c..0673186a 100644 --- a/src/main/resources/static/docs/notification.html +++ b/src/main/resources/static/docs/notification.html @@ -487,7 +487,7 @@

응답

diff --git a/src/test/java/com/moabam/api/application/RoomCertificationServiceTest.java b/src/test/java/com/moabam/api/application/room/RoomCertificationServiceTest.java similarity index 97% rename from src/test/java/com/moabam/api/application/RoomCertificationServiceTest.java rename to src/test/java/com/moabam/api/application/room/RoomCertificationServiceTest.java index 67a5daa3..0e8fb114 100644 --- a/src/test/java/com/moabam/api/application/RoomCertificationServiceTest.java +++ b/src/test/java/com/moabam/api/application/room/RoomCertificationServiceTest.java @@ -1,7 +1,7 @@ -package com.moabam.api.application; +package com.moabam.api.application.room; import static org.assertj.core.api.Assertions.*; -import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.BDDMockito.*; import java.time.LocalDate; @@ -23,7 +23,6 @@ import com.moabam.api.application.image.ImageService; import com.moabam.api.application.member.MemberService; -import com.moabam.api.application.room.RoomCertificationService; import com.moabam.api.domain.image.ImageType; import com.moabam.api.domain.member.Member; import com.moabam.api.domain.room.DailyMemberCertification; diff --git a/src/test/java/com/moabam/api/application/RoomServiceTest.java b/src/test/java/com/moabam/api/application/room/RoomServiceTest.java similarity index 98% rename from src/test/java/com/moabam/api/application/RoomServiceTest.java rename to src/test/java/com/moabam/api/application/room/RoomServiceTest.java index 8b7112f5..d6f8089b 100644 --- a/src/test/java/com/moabam/api/application/RoomServiceTest.java +++ b/src/test/java/com/moabam/api/application/room/RoomServiceTest.java @@ -1,4 +1,4 @@ -package com.moabam.api.application; +package com.moabam.api.application.room; import static com.moabam.api.domain.room.RoomType.*; import static org.assertj.core.api.Assertions.*; @@ -17,7 +17,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import com.moabam.api.application.member.MemberService; -import com.moabam.api.application.room.RoomService; import com.moabam.api.application.room.mapper.RoomMapper; import com.moabam.api.domain.member.Member; import com.moabam.api.domain.room.Participant; diff --git a/src/test/java/com/moabam/api/domain/entity/CertificationTest.java b/src/test/java/com/moabam/api/domain/room/CertificationTest.java similarity index 80% rename from src/test/java/com/moabam/api/domain/entity/CertificationTest.java rename to src/test/java/com/moabam/api/domain/room/CertificationTest.java index 1a7ac251..338bbc23 100644 --- a/src/test/java/com/moabam/api/domain/entity/CertificationTest.java +++ b/src/test/java/com/moabam/api/domain/room/CertificationTest.java @@ -1,15 +1,10 @@ -package com.moabam.api.domain.entity; +package com.moabam.api.domain.room; import static org.assertj.core.api.Assertions.*; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import com.moabam.api.domain.room.Certification; -import com.moabam.api.domain.room.Room; -import com.moabam.api.domain.room.RoomType; -import com.moabam.api.domain.room.Routine; - class CertificationTest { String content = "물 마시기"; diff --git a/src/test/java/com/moabam/api/domain/entity/RoomTest.java b/src/test/java/com/moabam/api/domain/room/RoomTest.java similarity index 95% rename from src/test/java/com/moabam/api/domain/entity/RoomTest.java rename to src/test/java/com/moabam/api/domain/room/RoomTest.java index 236db83f..21889ac3 100644 --- a/src/test/java/com/moabam/api/domain/entity/RoomTest.java +++ b/src/test/java/com/moabam/api/domain/room/RoomTest.java @@ -1,4 +1,4 @@ -package com.moabam.api.domain.entity; +package com.moabam.api.domain.room; import static org.assertj.core.api.Assertions.*; @@ -7,8 +7,6 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; -import com.moabam.api.domain.room.Room; -import com.moabam.api.domain.room.RoomType; import com.moabam.global.error.exception.BadRequestException; import com.moabam.global.error.model.ErrorMessage; diff --git a/src/test/java/com/moabam/api/domain/repository/CertificationsSearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/room/repository/CertificationsSearchRepositoryTest.java similarity index 86% rename from src/test/java/com/moabam/api/domain/repository/CertificationsSearchRepositoryTest.java rename to src/test/java/com/moabam/api/domain/room/repository/CertificationsSearchRepositoryTest.java index 361780be..27ca807a 100644 --- a/src/test/java/com/moabam/api/domain/repository/CertificationsSearchRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/room/repository/CertificationsSearchRepositoryTest.java @@ -1,4 +1,4 @@ -package com.moabam.api.domain.repository; +package com.moabam.api.domain.room.repository; import static org.assertj.core.api.Assertions.*; @@ -16,13 +16,6 @@ import com.moabam.api.domain.room.Participant; import com.moabam.api.domain.room.Room; import com.moabam.api.domain.room.Routine; -import com.moabam.api.domain.room.repository.CertificationRepository; -import com.moabam.api.domain.room.repository.CertificationsSearchRepository; -import com.moabam.api.domain.room.repository.DailyMemberCertificationRepository; -import com.moabam.api.domain.room.repository.DailyRoomCertificationRepository; -import com.moabam.api.domain.room.repository.ParticipantRepository; -import com.moabam.api.domain.room.repository.RoomRepository; -import com.moabam.api.domain.room.repository.RoutineRepository; import com.moabam.support.annotation.QuerydslRepositoryTest; import com.moabam.support.fixture.RoomFixture; diff --git a/src/test/java/com/moabam/api/domain/repository/ParticipantSearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/room/repository/ParticipantSearchRepositoryTest.java similarity index 89% rename from src/test/java/com/moabam/api/domain/repository/ParticipantSearchRepositoryTest.java rename to src/test/java/com/moabam/api/domain/room/repository/ParticipantSearchRepositoryTest.java index 2f703ca2..7df838fe 100644 --- a/src/test/java/com/moabam/api/domain/repository/ParticipantSearchRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/room/repository/ParticipantSearchRepositoryTest.java @@ -1,4 +1,4 @@ -package com.moabam.api.domain.repository; +package com.moabam.api.domain.room.repository; import static org.assertj.core.api.Assertions.*; @@ -13,9 +13,6 @@ import com.moabam.api.domain.room.Participant; import com.moabam.api.domain.room.Room; -import com.moabam.api.domain.room.repository.ParticipantRepository; -import com.moabam.api.domain.room.repository.ParticipantSearchRepository; -import com.moabam.api.domain.room.repository.RoomRepository; import com.moabam.global.config.JpaConfig; @DataJpaTest diff --git a/src/test/java/com/moabam/api/presentation/BugControllerTest.java b/src/test/java/com/moabam/api/presentation/BugControllerTest.java index a27c9af6..6431727b 100644 --- a/src/test/java/com/moabam/api/presentation/BugControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/BugControllerTest.java @@ -27,7 +27,7 @@ import com.moabam.api.application.bug.BugMapper; import com.moabam.api.application.member.MemberService; import com.moabam.api.domain.bug.repository.BugHistoryRepository; -import com.moabam.api.domain.repository.BugHistorySearchRepository; +import com.moabam.api.domain.bug.repository.BugHistorySearchRepository; import com.moabam.api.dto.TodayBugResponse; import com.moabam.api.dto.bug.BugResponse; import com.moabam.support.annotation.WithMember; diff --git a/src/test/java/com/moabam/api/presentation/RoomControllerTest.java b/src/test/java/com/moabam/api/presentation/RoomControllerTest.java index 18013047..7ba6206a 100644 --- a/src/test/java/com/moabam/api/presentation/RoomControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/RoomControllerTest.java @@ -40,6 +40,7 @@ import com.moabam.api.domain.room.repository.ParticipantSearchRepository; import com.moabam.api.domain.room.repository.RoomRepository; import com.moabam.api.domain.room.repository.RoutineRepository; +import com.moabam.api.domain.room.repository.RoutineSearchRepository; import com.moabam.api.dto.room.CreateRoomRequest; import com.moabam.api.dto.room.EnterRoomRequest; import com.moabam.api.dto.room.ModifyRoomRequest; @@ -67,6 +68,9 @@ class RoomControllerTest extends WithoutFilterSupporter { @Autowired private RoutineRepository routineRepository; + @Autowired + private RoutineSearchRepository routineSearchRepository; + @Autowired private ParticipantRepository participantRepository; @@ -112,6 +116,7 @@ void create_room_no_password_success() throws Exception { List routines = new ArrayList<>(); routines.add("물 마시기"); routines.add("코테 풀기"); + CreateRoomRequest createRoomRequest = new CreateRoomRequest( "재윤과 앵맹이의 방임", null, routines, MORNING, 10, 4); String json = objectMapper.writeValueAsString(createRoomRequest); @@ -129,6 +134,7 @@ void create_room_no_password_success() throws Exception { } @DisplayName("비밀번호 있는 방 생성 성공") + @WithMember @ParameterizedTest @CsvSource({ "1234", "12345678", "98765" @@ -138,6 +144,7 @@ void create_room_with_password_success(String password) throws Exception { List routines = new ArrayList<>(); routines.add("물 마시기"); routines.add("코테 풀기"); + CreateRoomRequest createRoomRequest = new CreateRoomRequest( "비번 있는 재맹의 방임", password, routines, MORNING, 10, 4); String json = objectMapper.writeValueAsString(createRoomRequest); @@ -164,6 +171,7 @@ void create_room_with_wrong_password_fail(String password) throws Exception { List routines = new ArrayList<>(); routines.add("물 마시기"); routines.add("코테 풀기"); + CreateRoomRequest createRoomRequest = new CreateRoomRequest( "비번 있는 재윤과 앵맹이의 방임", password, routines, MORNING, 10, 4); String json = objectMapper.writeValueAsString(createRoomRequest); @@ -187,6 +195,7 @@ void create_room_with_too_many_routine_fail() throws Exception { routines.add("코드 리뷰 달기"); routines.add("책 읽기"); routines.add("산책 하기"); + CreateRoomRequest createRoomRequest = new CreateRoomRequest( "비번 없는 재윤과 앵맹이의 방임", null, routines, MORNING, 10, 4); String json = objectMapper.writeValueAsString(createRoomRequest); @@ -204,6 +213,7 @@ void create_room_with_too_many_routine_fail() throws Exception { void create_room_with_no_routine_fail() throws Exception { // given List routines = new ArrayList<>(); + CreateRoomRequest createRoomRequest = new CreateRoomRequest( "비번 없는 재윤과 앵맹이의 방임", null, routines, MORNING, 10, 4); String json = objectMapper.writeValueAsString(createRoomRequest); @@ -216,7 +226,7 @@ void create_room_with_no_routine_fail() throws Exception { .andDo(print()); } - @DisplayName("올바르지 못한 시간으로 아침 방 생성") + @DisplayName("올바르지 못한 시간으로 아침 방 생성시 예외 발생") @ParameterizedTest @CsvSource({ "1", "3", "11", "12", "20" @@ -226,6 +236,7 @@ void create_morning_room_wrong_certify_time_fail(int certifyTime) throws Excepti List routines = new ArrayList<>(); routines.add("물 마시기"); routines.add("코테 풀기"); + CreateRoomRequest createRoomRequest = new CreateRoomRequest( "비번 없는 재윤과 앵맹이의 방임", null, routines, MORNING, certifyTime, 4); String json = objectMapper.writeValueAsString(createRoomRequest); @@ -248,6 +259,7 @@ void create_night_room_wrong_certify_time_fail(int certifyTime) throws Exception List routines = new ArrayList<>(); routines.add("물 마시기"); routines.add("코테 풀기"); + CreateRoomRequest createRoomRequest = new CreateRoomRequest( "비번 없는 재윤과 앵맹이의 방임", null, routines, NIGHT, certifyTime, 4); String json = objectMapper.writeValueAsString(createRoomRequest); @@ -261,6 +273,7 @@ void create_night_room_wrong_certify_time_fail(int certifyTime) throws Exception } @DisplayName("방 수정 성공 - 방장일 경우") + @WithMember(id = 1L) @Test void modify_room_success() throws Exception { // given @@ -272,19 +285,20 @@ void modify_room_success() throws Exception { .maxUserCount(5) .build(); - Participant participant = Participant.builder() - .room(room) - .memberId(1L) - .build(); + List routines = RoomFixture.routines(room); + + Participant participant = RoomFixture.participant(room, 1L); participant.enableManager(); - List routines = new ArrayList<>(); - routines.add("물 마시기"); - routines.add("코테 풀기"); + List newRoutines = new ArrayList<>(); + newRoutines.add("물 마시기"); + newRoutines.add("코테 풀기"); roomRepository.save(room); + routineRepository.saveAll(routines); participantRepository.save(participant); - ModifyRoomRequest modifyRoomRequest = new ModifyRoomRequest("수정할 방임!", null, routines, "1234", 10, 7); + + ModifyRoomRequest modifyRoomRequest = new ModifyRoomRequest("수정할 방임!", "공지공지", newRoutines, "4567", 10, 7); String json = objectMapper.writeValueAsString(modifyRoomRequest); // expected @@ -293,9 +307,20 @@ void modify_room_success() throws Exception { .content(json)) .andExpect(status().isOk()) .andDo(print()); + + Room modifiedRoom = roomRepository.findById(room.getId()).orElseThrow(); + List modifiedRoutines = routineSearchRepository.findAllByRoomId(room.getId()); + + assertThat(modifiedRoom.getTitle()).isEqualTo("수정할 방임!"); + assertThat(modifiedRoom.getCertifyTime()).isEqualTo(10); + assertThat(modifiedRoom.getPassword()).isEqualTo("4567"); + assertThat(modifiedRoom.getAnnouncement()).isEqualTo("공지공지"); + assertThat(modifiedRoom.getMaxUserCount()).isEqualTo(7); + assertThat(modifiedRoutines).hasSize(2); } @DisplayName("방 수정 실패 - 방장 아닐 경우") + @WithMember(id = 1L) @Test void unauthorized_modify_room_fail() throws Exception { // given @@ -307,10 +332,7 @@ void unauthorized_modify_room_fail() throws Exception { .maxUserCount(5) .build(); - Participant participant = Participant.builder() - .room(room) - .memberId(1L) - .build(); + Participant participant = RoomFixture.participant(room, 1L); List routines = new ArrayList<>(); routines.add("물 마시기"); @@ -332,6 +354,7 @@ void unauthorized_modify_room_fail() throws Exception { } @DisplayName("비밀번호 있는 방 참여 성공") + @WithMember(id = 1L) @Test void enter_room_with_password_success() throws Exception { // given @@ -356,15 +379,11 @@ void enter_room_with_password_success() throws Exception { } @DisplayName("비밀번호 없는 방 참여 성공") + @WithMember(id = 1L) @Test void enter_room_with_no_password_success() throws Exception { // given - Room room = Room.builder() - .title("처음 제목") - .roomType(MORNING) - .certifyTime(9) - .maxUserCount(5) - .build(); + Room room = RoomFixture.room(); roomRepository.save(room); EnterRoomRequest enterRoomRequest = new EnterRoomRequest(null); @@ -379,6 +398,7 @@ void enter_room_with_no_password_success() throws Exception { } @DisplayName("방 참여 후 인원수 증가 테스트") + @WithMember(id = 1L) @Test void enter_and_increase_room_user_count() throws Exception { // given @@ -407,6 +427,7 @@ void enter_and_increase_room_user_count() throws Exception { } @DisplayName("아침 방 참여 후 사용자의 방 입장 횟수 증가 테스트") + @WithMember(id = 1L) @Test void enter_and_increase_morning_room_count() throws Exception { // given @@ -436,6 +457,7 @@ void enter_and_increase_morning_room_count() throws Exception { } @DisplayName("저녁 방 참여 후 사용자의 방 입장 횟수 증가 테스트") + @WithMember(id = 1L) @Test void enter_and_increase_night_room_count() throws Exception { // given @@ -521,6 +543,7 @@ void enter_and_night_room_over_three_fail() throws Exception { } @DisplayName("비밀번호 불일치 방 참여시 예외 발생") + @WithMember(id = 1L) @Test void enter_room_wrong_password_fail() throws Exception { // given @@ -555,6 +578,7 @@ void enter_room_wrong_password_fail() throws Exception { } @DisplayName("인원수가 모두 찬 방 참여시 예외 발생") + @WithMember(id = 1L) @Test void enter_max_user_room_fail() throws Exception { // given @@ -585,6 +609,7 @@ void enter_max_user_room_fail() throws Exception { } @DisplayName("일반 사용자의 방 나가기 성공") + @WithMember(id = 1L) @Test void no_manager_exit_room_success() throws Exception { // given @@ -594,10 +619,8 @@ void no_manager_exit_room_success() throws Exception { .certifyTime(21) .maxUserCount(8) .build(); - Participant participant = Participant.builder() - .room(room) - .memberId(1L) - .build(); + + Participant participant = RoomFixture.participant(room, 1L); for (int i = 0; i < 4; i++) { room.increaseCurrentUserCount(); @@ -614,11 +637,13 @@ void no_manager_exit_room_success() throws Exception { participantRepository.flush(); Room findRoom = roomRepository.findById(room.getId()).orElseThrow(); Participant deletedParticipant = participantRepository.findById(participant.getId()).orElseThrow(); + assertThat(findRoom.getCurrentUserCount()).isEqualTo(4); assertThat(deletedParticipant.getDeletedAt()).isNotNull(); } @DisplayName("방장의 방 나가기 - 방 삭제 성공") + @WithMember(id = 1L) @Test void manager_delete_room_success() throws Exception { // given @@ -628,11 +653,10 @@ void manager_delete_room_success() throws Exception { .certifyTime(21) .maxUserCount(8) .build(); - Participant participant = Participant.builder() - .room(room) - .memberId(1L) - .build(); + + Participant participant = RoomFixture.participant(room, 1L); participant.enableManager(); + roomRepository.save(room); participantRepository.save(participant); @@ -642,11 +666,13 @@ void manager_delete_room_success() throws Exception { .andDo(print()); Participant deletedParticipant = participantRepository.findById(participant.getId()).orElseThrow(); + assertThat(roomRepository.findById(room.getId())).isEmpty(); assertThat(deletedParticipant.getDeletedAt()).isNotNull(); } @DisplayName("방장이 위임하지 않고 방 나가기 실패") + @WithMember(id = 1L) @Test void manager_exit_room_fail() throws Exception { // given @@ -656,10 +682,8 @@ void manager_exit_room_fail() throws Exception { .certifyTime(21) .maxUserCount(10) .build(); - Participant participant = Participant.builder() - .room(room) - .memberId(1L) - .build(); + + Participant participant = RoomFixture.participant(room, 1L); participant.enableManager(); for (int i = 0; i < 6; i++) { @@ -678,21 +702,13 @@ void manager_exit_room_fail() throws Exception { } @DisplayName("아침 방 나가기 이후 사용자의 방 입장 횟수 감소 테스트") + @WithMember(id = 1L) @Test void exit_and_decrease_morning_room_count() throws Exception { // given - Room room = Room.builder() - .title("방 제목") - .password("1234") - .roomType(MORNING) - .certifyTime(9) - .maxUserCount(5) - .build(); + Room room = RoomFixture.room(); - Participant participant = Participant.builder() - .room(room) - .memberId(1L) - .build(); + Participant participant = RoomFixture.participant(room, 1L); for (int i = 0; i < 3; i++) { member.enterMorningRoom(); @@ -713,6 +729,7 @@ void exit_and_decrease_morning_room_count() throws Exception { } @DisplayName("저녁 방 나가기 이후 사용자의 방 입장 횟수 감소 테스트") + @WithMember(id = 1L) @Test void exit_and_decrease_night_room_count() throws Exception { // given @@ -724,10 +741,7 @@ void exit_and_decrease_night_room_count() throws Exception { .maxUserCount(5) .build(); - Participant participant = Participant.builder() - .room(room) - .memberId(1L) - .build(); + Participant participant = RoomFixture.participant(room, 1L); for (int i = 0; i < 3; i++) { member.enterNightRoom(); @@ -748,6 +762,7 @@ void exit_and_decrease_night_room_count() throws Exception { } @DisplayName("방 상세 정보 조회 성공 테스트") + @WithMember(id = 1L) @Test void get_room_details_test() throws Exception { // given @@ -762,62 +777,34 @@ void get_room_details_test() throws Exception { room.increaseCurrentUserCount(); room.increaseCurrentUserCount(); - Routine routine1 = Routine.builder() - .room(room) - .content("물 마시기") - .build(); + List routines = RoomFixture.routines(room); - Routine routine2 = Routine.builder() - .room(room) - .content("코테 풀기") - .build(); - - Participant participant1 = Participant.builder() - .room(room) - .memberId(1L) - .build(); + Participant participant1 = RoomFixture.participant(room, 1L); participant1.enableManager(); - Member member2 = Member.builder() - .socialId(2L) - .nickname("NICKNAME_2") - .bug(BugFixture.bug()) - .build(); - - Member member3 = Member.builder() - .socialId(3L) - .nickname("NICKNAME_3") - .bug(BugFixture.bug()) - .build(); + Member member2 = MemberFixture.member(2L, "NICK2"); + Member member3 = MemberFixture.member(3L, "NICK3"); roomRepository.save(room); - routineRepository.save(routine1); - routineRepository.save(routine2); + routineRepository.saveAll(routines); memberRepository.save(member2); memberRepository.save(member3); - Participant participant2 = Participant.builder() - .room(room) - .memberId(member2.getId()) - .build(); - - Participant participant3 = Participant.builder() - .room(room) - .memberId(member3.getId()) - .build(); + Participant participant2 = RoomFixture.participant(room, member2.getId()); + Participant participant3 = RoomFixture.participant(room, member3.getId()); participantRepository.save(participant1); participantRepository.save(participant2); participantRepository.save(participant3); Certification certification1 = Certification.builder() - .routine(routine1) + .routine(routines.get(0)) .memberId(member.getId()) .image("member1Image") .build(); Certification certification2 = Certification.builder() - .routine(routine2) + .routine(routines.get(1)) .memberId(member.getId()) .image("member2Image") .build(); @@ -825,19 +812,12 @@ void get_room_details_test() throws Exception { certificationRepository.save(certification1); certificationRepository.save(certification2); - DailyMemberCertification dailyMemberCertification = DailyMemberCertification.builder() - .memberId(member.getId()) - .roomId(room.getId()) - .participant(participant1) - .build(); - + DailyMemberCertification dailyMemberCertification = RoomFixture.dailyMemberCertification(member.getId(), + room.getId(), participant1); dailyMemberCertificationRepository.save(dailyMemberCertification); - DailyRoomCertification dailyRoomCertification = DailyRoomCertification.builder() - .roomId(room.getId()) - .certifiedAt(LocalDate.now()) - .build(); - + DailyRoomCertification dailyRoomCertification = RoomFixture.dailyRoomCertification(room.getId(), + LocalDate.now()); dailyRoomCertificationRepository.save(dailyRoomCertification); // expected @@ -847,6 +827,7 @@ void get_room_details_test() throws Exception { } @DisplayName("방 추방 성공") + @WithMember(id = 1L) @Test void deport_member_success() throws Exception { // given @@ -875,6 +856,6 @@ void deport_member_success() throws Exception { assertThat(getRoom.getCurrentUserCount()).isEqualTo(1); assertThat(getMemberParticipant.getDeletedAt()).isNotNull(); - assertThat(participantSearchRepository.findOne(3L, room.getId())).isEmpty(); + assertThat(participantSearchRepository.findOne(member.getId(), room.getId())).isEmpty(); } } diff --git a/src/test/java/com/moabam/support/fixture/RoomFixture.java b/src/test/java/com/moabam/support/fixture/RoomFixture.java index 4a436205..088429e2 100644 --- a/src/test/java/com/moabam/support/fixture/RoomFixture.java +++ b/src/test/java/com/moabam/support/fixture/RoomFixture.java @@ -49,11 +49,11 @@ public static List routines(Room room) { Routine routine1 = Routine.builder() .room(room) - .content("물 마시기") + .content("첫 루틴") .build(); Routine routine2 = Routine.builder() .room(room) - .content("코테 풀기") + .content("두번째 루틴") .build(); routines.add(routine1);