Skip to content

Commit

Permalink
feat: 지부 테스트 코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ShimFFF committed Feb 8, 2024
1 parent 727af8c commit ff6818c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import com.umc.networkingService.domain.branch.dto.response.BranchResponse;
import com.umc.networkingService.domain.branch.entity.Branch;
import com.umc.networkingService.domain.branch.entity.BranchUniversity;
import com.umc.networkingService.domain.branch.execption.BranchHandler;
import com.umc.networkingService.domain.branch.repository.BranchRepository;
import com.umc.networkingService.domain.university.entity.University;
import com.umc.networkingService.global.common.enums.Semester;
import com.umc.networkingService.global.common.exception.RestApiException;
import com.umc.networkingService.global.utils.S3FileComponent;
import com.umc.networkingService.support.ServiceIntegrationTestConfig;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -28,7 +28,6 @@
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;

@DisplayName("Branch 서비스의 ")
@SpringBootTest
Expand All @@ -50,25 +49,25 @@ class BranchServiceTest extends ServiceIntegrationTestConfig {
@Transactional
void postBranch_Success() {
// given
BranchRequest.PostBranchDTO request = BranchRequest.PostBranchDTO.builder()
BranchRequest.BranchInfoDTO request = BranchRequest.BranchInfoDTO.builder()
.name("branchTestPost")
.semester(Semester.FIRST)
.image(null)
.description("Branch Description")
.build();

// when
UUID id = branchService.postBranch(request);
BranchResponse.BranchId id = branchService.postBranch(request);

// then
Optional<Branch> optionalBranch = branchRepository.findById(id);
Optional<Branch> optionalBranch = branchRepository.findById(id.getBranchId());
assertTrue(optionalBranch.isPresent());
Branch newBranch=optionalBranch.get();

assertEquals(request.getName(), newBranch.getName());
assertEquals(request.getDescription(), newBranch.getDescription());

branchRepository.deleteById(id);
branchRepository.deleteById(id.getBranchId());
}

@Test
Expand All @@ -83,8 +82,7 @@ void patchBranch_Success_img() {
"이미지 데이터".getBytes()
);

BranchRequest.PatchBranchDTO request =BranchRequest.PatchBranchDTO.builder()
.branchId(branch.getId())
BranchRequest.BranchInfoDTO request =BranchRequest.BranchInfoDTO.builder()
.name("Updated Branch")
.description("Updated Description")
.image(image)
Expand All @@ -95,7 +93,7 @@ void patchBranch_Success_img() {
given(s3FileComponent.uploadFile(any(), any())).willReturn("s3 url", "s3 url");

// when
branchService.patchBranch(request);
branchService.patchBranch(request, branch.getId());

// then
Optional<Branch> optionalBranch = branchRepository.findById(branch.getId());
Expand All @@ -113,16 +111,15 @@ void patchBranch_Success_img() {
@Transactional
void patchBranch_Success() {
// given
BranchRequest.PatchBranchDTO request =BranchRequest.PatchBranchDTO.builder()
.branchId(branch.getId())
BranchRequest.BranchInfoDTO request =BranchRequest.BranchInfoDTO.builder()
.name("Updated Branch")
.description("Updated Description")
.image(null)
.semester(Semester.FIFTH)
.build();

// when
branchService.patchBranch(request);
branchService.patchBranch(request, branch.getId());

// then
Optional<Branch> optionalBranch = branchRepository.findById(branch.getId());
Expand All @@ -139,14 +136,13 @@ void patchBranch_Success() {
@Transactional
void patchBranch_NonExisting_Failure() {
// given
BranchRequest.PatchBranchDTO request = BranchRequest.PatchBranchDTO.builder()
.branchId(UUID.randomUUID())
BranchRequest.BranchInfoDTO request = BranchRequest.BranchInfoDTO.builder()
.name("Updated Branch")
.image(null)
.build();

// when & then
assertThrows(BranchHandler.class, () -> branchService.patchBranch(request));
assertThrows(RestApiException.class, () -> branchService.patchBranch(request, UUID.randomUUID()));
}


Expand Down Expand Up @@ -236,7 +232,7 @@ void joinBranchDetail_NonExistingBranch_Failure() {
UUID nonExistingBranchId = UUID.randomUUID();

// when & then
assertThrows(BranchHandler.class, () -> branchService.joinBranchDetail(nonExistingBranchId));
assertThrows(RestApiException.class, () -> branchService.joinBranchDetail(nonExistingBranchId));
}

@Test
Expand All @@ -261,7 +257,7 @@ void deleteBranch_NonExisting_Failure() {


// when & then
assertThrows(BranchHandler.class, () -> branchService.deleteBranch(nonExistingBranchId));
assertThrows(RestApiException.class, () -> branchService.deleteBranch(nonExistingBranchId));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,25 @@ protected BranchUniversity createBranchUniversity() {
.build()
);
}

//새로운 브랜치 생성용
protected Branch createBranch( String name ) {
return branchRepository.save(
Branch.builder()
.name(name)
.semester(Semester.FIFTH)
.build()
);
}

//새로운 대학 생성용
protected University createUniversity( String name ) {
return universityRepository.save(
University.builder()
.name(name)
.totalPoint(0L)
.mascot(mascot)
.build()
);
}
}

0 comments on commit ff6818c

Please sign in to comment.