diff --git a/.gitignore b/.gitignore index a9b041b..4a8b681 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ .Ds_store /redis .gradle +**/build/ diff --git a/spring-chatting-backend-server/build.gradle b/spring-chatting-backend-server/build.gradle index 7f80bb7..15a87f1 100644 --- a/spring-chatting-backend-server/build.gradle +++ b/spring-chatting-backend-server/build.gradle @@ -2,12 +2,30 @@ plugins { id 'java' id 'org.springframework.boot' version '3.0.5' id 'io.spring.dependency-management' version '1.1.0' + id 'jacoco' +} + +jacoco { + toolVersion = "0.8.8" } ext { set('springCloudVersion', "2022.0.1") } +jacocoTestReport { + dependsOn test // 리포트 생성을 위해서는 test가 먼저 완료되어야 함 + reports { + xml.enabled false + html.enabled true + } +} + +tasks.named('test') { + useJUnitPlatform() + finalizedBy jacocoTestReport // 테스트 종료후 항상 리포트 생성 +} + group = 'chattingBackend' version = project.rootProject.ext.projectVersion sourceCompatibility = '17' @@ -85,10 +103,6 @@ dependencies { testImplementation 'org.springframework.boot:spring-boot-starter-test' } -tasks.named('test') { - useJUnitPlatform() -} - // find the latest jar file in the build/libs directory def findLatestJar() { def jarDir = file("${project.buildDir}/libs") diff --git a/spring-chatting-backend-server/src/test/java/chatting/chat/domain/participant/api/ParticipantControllerTest.java b/spring-chatting-backend-server/src/test/java/chatting/chat/domain/participant/api/ParticipantControllerTest.java index b3c12b7..496d759 100644 --- a/spring-chatting-backend-server/src/test/java/chatting/chat/domain/participant/api/ParticipantControllerTest.java +++ b/spring-chatting-backend-server/src/test/java/chatting/chat/domain/participant/api/ParticipantControllerTest.java @@ -9,8 +9,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import chatting.chat.domain.participant.dto.ParticipantDto; import chatting.chat.domain.participant.service.ParticipantServiceImpl; import chatting.chat.domain.user.api.UserController; +import chatting.chat.domain.user.dto.UserDto; import chatting.chat.domain.user.entity.User; import chatting.chat.domain.user.service.UserService; import chatting.chat.web.error.GlobalExceptionHandler; @@ -19,6 +21,8 @@ import chatting.chat.web.sessionCluster.redis.UserRedisSessionRepository; import com.example.commondto.error.CustomException; import jakarta.servlet.http.Cookie; +import java.time.LocalDate; +import java.util.Arrays; import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; @@ -79,7 +83,7 @@ void whenValidParticipantAdd_thenSuccessShouldBeReturned() throws Exception { @Test @DisplayName("채팅방이 존재하지 않을 때 참여 시 에러 반환") - void addParticipant() throws Exception { + void whenRoomNotValid_then404ShouldBeReturned() throws Exception { // given String refreshToken = "validToken"; String userId = "userId"; @@ -93,10 +97,25 @@ void addParticipant() throws Exception { } @Test - void getParticipants() { - } + @DisplayName("내가 참여중인 채팅방 목록 조회 시 참여중인 채팅방 목록 반환 성공") + void whenValidUserGetHisParticipantList_thenValidParticipantListShouldBeReturned() + throws Exception { + // given + String refreshToken = "validToken"; + String userId = "userId"; + ParticipantDto participantDto = ParticipantDto.builder().userDto(UserDto.builder().userId(userId).userName("userName").userStatus("").build()) + .participantId(1L) + .createdAt(LocalDate.now()) + .updatedAt(LocalDate.now()) + .roomId(1L) + .roomName("roomName") + .build(); + UserRedisSession userRedisSession = new UserRedisSession(userId, refreshToken); + when(userRedisSessionRepository.findById(refreshToken)).thenReturn(Optional.of(userRedisSession)); + when(participantService.findAllByUserId(userId)).thenReturn(Arrays.asList(participantDto)); - @Test - void getParticipant() { + // when + then + mockMvc.perform(get("/participant").cookie(new Cookie("refreshToken", refreshToken))) + .andExpect(status().isOk()).andExpect(jsonPath("$[0].userDto.userId", is(userId))); } } \ No newline at end of file