Skip to content

Commit

Permalink
[chore] build 디렉토리 ignore 및 테스트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ghkdqhrbals committed Dec 31, 2023
1 parent a0719c3 commit 49e5876
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
.Ds_store
/redis
.gradle
**/build/
22 changes: 18 additions & 4 deletions spring-chatting-backend-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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";
Expand All @@ -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)));
}
}

0 comments on commit 49e5876

Please sign in to comment.