Skip to content

Commit bb47aa4

Browse files
committed
test(recruit-board): 모집글 Validator 추가에 따른 리팩토링 테스트
1 parent 88c4a05 commit bb47aa4

File tree

2 files changed

+6
-66
lines changed

2 files changed

+6
-66
lines changed

src/test/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardServiceTest.java

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
import com.somemore.domains.recruitboard.domain.RecruitBoard;
44
import com.somemore.domains.recruitboard.domain.RecruitmentInfo;
5-
import com.somemore.domains.recruitboard.repository.RecruitBoardJpaRepository;
65
import com.somemore.domains.recruitboard.repository.RecruitBoardRepository;
7-
import com.somemore.global.exception.BadRequestException;
86
import com.somemore.support.IntegrationTestSupport;
9-
import org.junit.jupiter.api.AfterEach;
107
import org.junit.jupiter.api.BeforeEach;
118
import org.junit.jupiter.api.DisplayName;
129
import org.junit.jupiter.api.Test;
1310
import org.springframework.beans.factory.annotation.Autowired;
11+
import org.springframework.transaction.annotation.Transactional;
1412

1513
import java.time.LocalDateTime;
1614
import java.util.Optional;
@@ -19,8 +17,8 @@
1917
import static com.somemore.domains.recruitboard.domain.VolunteerCategory.OTHER;
2018
import static com.somemore.support.fixture.LocalDateTimeFixture.createStartDateTime;
2119
import static org.assertj.core.api.Assertions.assertThat;
22-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2320

21+
@Transactional
2422
class DeleteRecruitBoardServiceTest extends IntegrationTestSupport {
2523

2624
@Autowired
@@ -29,9 +27,6 @@ class DeleteRecruitBoardServiceTest extends IntegrationTestSupport {
2927
@Autowired
3028
private RecruitBoardRepository recruitBoardRepository;
3129

32-
@Autowired
33-
private RecruitBoardJpaRepository recruitBoardJpaRepository;
34-
3530
private RecruitBoard recruitBoard;
3631

3732
@BeforeEach
@@ -40,11 +35,6 @@ void setUp() {
4035
recruitBoardRepository.save(recruitBoard);
4136
}
4237

43-
@AfterEach
44-
void tearDown() {
45-
recruitBoardJpaRepository.deleteAllInBatch();
46-
}
47-
4838
@DisplayName("봉사 모집글 식별값으로 모집글을 삭제할 수 있다")
4939
@Test
5040
void deleteRecruitBoard() {
@@ -61,20 +51,6 @@ void deleteRecruitBoard() {
6151
assertThat(findBoard).isEmpty();
6252
}
6353

64-
@DisplayName("모집글 삭제시 작성자가 아니면 에러가 발생한다")
65-
@Test
66-
void deleteRecruitBoardWithWrongCenterId() {
67-
// given
68-
UUID wrongCenterId = UUID.randomUUID();
69-
Long recruitBoardId = recruitBoard.getId();
70-
71-
// when
72-
// then
73-
assertThatThrownBy(
74-
() -> deleteRecruitBoardService.deleteRecruitBoard(wrongCenterId, recruitBoardId)
75-
).isInstanceOf(BadRequestException.class);
76-
}
77-
7854
private static RecruitBoard createRecruitBoard() {
7955

8056
LocalDateTime startDateTime = createStartDateTime();

src/test/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardServiceTest.java

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
import com.somemore.domains.recruitboard.dto.request.RecruitBoardUpdateRequestDto;
1010
import com.somemore.domains.recruitboard.repository.RecruitBoardJpaRepository;
1111
import com.somemore.domains.recruitboard.repository.RecruitBoardRepository;
12-
import com.somemore.global.exception.BadRequestException;
1312
import com.somemore.support.IntegrationTestSupport;
14-
import org.assertj.core.api.Assertions;
15-
import org.junit.jupiter.api.AfterEach;
1613
import org.junit.jupiter.api.BeforeEach;
1714
import org.junit.jupiter.api.DisplayName;
1815
import org.junit.jupiter.api.Test;
1916
import org.springframework.beans.factory.annotation.Autowired;
17+
import org.springframework.transaction.annotation.Transactional;
2018

2119
import java.math.BigDecimal;
2220
import java.time.LocalDateTime;
@@ -27,6 +25,7 @@
2725
import static com.somemore.support.fixture.LocalDateTimeFixture.*;
2826
import static org.assertj.core.api.Assertions.assertThat;
2927

28+
@Transactional
3029
class UpdateRecruitBoardServiceTest extends IntegrationTestSupport {
3130

3231
@Autowired
@@ -53,12 +52,6 @@ void setUp() {
5352
recruitBoardJpaRepository.saveAndFlush(recruitBoard);
5453
}
5554

56-
@AfterEach
57-
void tearDown() {
58-
recruitBoardJpaRepository.deleteAllInBatch();
59-
locationRepository.deleteAllInBatch();
60-
}
61-
6255
@DisplayName("봉사 모집글의 데이터를 업데이트하면 저장소에 반영된다.")
6356
@Test
6457
void updateRecruitBoard() {
@@ -79,8 +72,7 @@ void updateRecruitBoard() {
7972
.build();
8073

8174
// when
82-
updateRecruitBoardService.updateRecruitBoard(dto, recruitBoard.getId(), centerId,
83-
newImgUrl);
75+
updateRecruitBoardService.updateRecruitBoard(dto, recruitBoard.getId(), centerId, newImgUrl);
8476

8577
// then
8678
RecruitBoard updatedRecruitBoard = recruitBoardRepository.findById(recruitBoard.getId())
@@ -129,33 +121,6 @@ void updateRecruitBoardLocation() {
129121
.isEqualByComparingTo(dto.latitude());
130122
}
131123

132-
@DisplayName("봉사 모집글은 작성자만 수정할 수 있다")
133-
@Test
134-
void updateRecruitBoardWhenCenterIdIsWrong() {
135-
// given
136-
Long id = recruitBoard.getId();
137-
UUID wrongCenterId = UUID.randomUUID();
138-
LocalDateTime newStartDateTime = createUpdateStartDateTime();
139-
LocalDateTime newEndDateTime = newStartDateTime.plusHours(3);
140-
String newImgUrl = "https://image.domain.com/updates";
141-
RecruitBoardUpdateRequestDto dto = RecruitBoardUpdateRequestDto.builder()
142-
.title("업데이트 제목")
143-
.content("업데이트 내용")
144-
.recruitmentCount(1111)
145-
.volunteerStartDateTime(newStartDateTime)
146-
.volunteerEndDateTime(newEndDateTime)
147-
.volunteerCategory(ADMINISTRATIVE_SUPPORT)
148-
.admitted(false)
149-
.build();
150-
151-
// when
152-
// then
153-
Assertions.assertThatThrownBy(
154-
() -> updateRecruitBoardService.updateRecruitBoard(dto, id, wrongCenterId, newImgUrl)
155-
).isInstanceOf(BadRequestException.class);
156-
157-
}
158-
159124
@DisplayName("봉사 모집글 상태를 변경할 수 있다")
160125
@Test
161126
void updateRecruitBoardStatus() {
@@ -165,8 +130,7 @@ void updateRecruitBoardStatus() {
165130
LocalDateTime currentDateTime = createCurrentDateTime();
166131

167132
// when
168-
updateRecruitBoardService.updateRecruitBoardStatus(newStatus, recruitBoardId, centerId,
169-
currentDateTime);
133+
updateRecruitBoardService.updateRecruitBoardStatus(newStatus, recruitBoardId, centerId, currentDateTime);
170134

171135
// then
172136
RecruitBoard findBoard = recruitBoardRepository.findById(recruitBoardId).orElseThrow();

0 commit comments

Comments
 (0)