Skip to content

Commit 51cb957

Browse files
committed
test(recruit-board): 봉사 모집글 삭제 기능 테스트
1 parent e5e280e commit 51cb957

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.somemore.recruitboard.service.command;
2+
3+
import static com.somemore.common.fixture.LocalDateTimeFixture.createStartDateTime;
4+
import static com.somemore.recruitboard.domain.VolunteerType.OTHER;
5+
import static org.assertj.core.api.Assertions.assertThat;
6+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
7+
8+
import com.somemore.IntegrationTestSupport;
9+
import com.somemore.global.exception.BadRequestException;
10+
import com.somemore.recruitboard.domain.RecruitBoard;
11+
import com.somemore.recruitboard.domain.RecruitmentInfo;
12+
import com.somemore.recruitboard.repository.RecruitBoardRepository;
13+
import java.time.LocalDateTime;
14+
import java.util.Optional;
15+
import java.util.UUID;
16+
import org.junit.jupiter.api.AfterEach;
17+
import org.junit.jupiter.api.BeforeEach;
18+
import org.junit.jupiter.api.DisplayName;
19+
import org.junit.jupiter.api.Test;
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
22+
class DeleteRecruitBoardServiceTest extends IntegrationTestSupport {
23+
24+
@Autowired
25+
private DeleteRecruitBoardService deleteRecruitBoardService;
26+
27+
@Autowired
28+
private RecruitBoardRepository recruitBoardRepository;
29+
30+
private RecruitBoard recruitBoard;
31+
32+
@BeforeEach
33+
void setUp() {
34+
recruitBoard = createRecruitBoard();
35+
recruitBoardRepository.saveAndFlush(recruitBoard);
36+
}
37+
38+
@AfterEach
39+
void tearDown() {
40+
recruitBoardRepository.deleteAllInBatch();
41+
}
42+
43+
@DisplayName("봉사 모집글 식별값으로 모집글을 삭제할 수 있다")
44+
@Test
45+
void deleteRecruitBoard() {
46+
// given
47+
UUID centerId = recruitBoard.getCenterId();
48+
Long recruitBoardId = recruitBoard.getId();
49+
50+
// when
51+
deleteRecruitBoardService.deleteRecruitBoard(centerId, recruitBoardId);
52+
53+
// then
54+
Optional<RecruitBoard> findBoard = recruitBoardRepository.findById(recruitBoardId);
55+
56+
assertThat(findBoard).isEmpty();
57+
}
58+
59+
@DisplayName("모집글 삭제시 작성자가 아니면 에러가 발생한다")
60+
@Test
61+
void deleteRecruitBoardWithWrongCenterId() {
62+
// given
63+
UUID wrongCenterId = UUID.randomUUID();
64+
Long recruitBoardId = recruitBoard.getId();
65+
66+
// when
67+
// then
68+
assertThatThrownBy(
69+
() -> deleteRecruitBoardService.deleteRecruitBoard(wrongCenterId, recruitBoardId)
70+
).isInstanceOf(BadRequestException.class);
71+
}
72+
73+
private static RecruitBoard createRecruitBoard() {
74+
75+
LocalDateTime startDateTime = createStartDateTime();
76+
LocalDateTime endDateTime = startDateTime.plusHours(1);
77+
78+
RecruitmentInfo recruitmentInfo = RecruitmentInfo.builder()
79+
.region("경기")
80+
.recruitmentCount(1)
81+
.volunteerStartDateTime(startDateTime)
82+
.volunteerEndDateTime(endDateTime)
83+
.volunteerType(OTHER)
84+
.admitted(true)
85+
.build();
86+
87+
return RecruitBoard.builder()
88+
.centerId(UUID.randomUUID())
89+
.locationId(1L)
90+
.title("봉사모집제목")
91+
.content("봉사모집내용")
92+
.imgUrl("https://image.domain.com/links")
93+
.recruitmentInfo(recruitmentInfo)
94+
.build();
95+
}
96+
}

0 commit comments

Comments
 (0)