Skip to content

Commit 71a22a4

Browse files
committed
test(volunteer-apply): 봉사 지원 철회 기능 테스트
1 parent dc64424 commit 71a22a4

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.somemore.volunteerapply.service;
2+
3+
import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_VOLUNTEER_APPLY;
4+
import static com.somemore.volunteerapply.domain.ApplyStatus.APPROVED;
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.volunteerapply.domain.ApplyStatus;
11+
import com.somemore.volunteerapply.domain.VolunteerApply;
12+
import com.somemore.volunteerapply.repository.VolunteerApplyRepository;
13+
import java.util.Optional;
14+
import java.util.UUID;
15+
import org.junit.jupiter.api.DisplayName;
16+
import org.junit.jupiter.api.Test;
17+
import org.springframework.beans.factory.annotation.Autowired;
18+
19+
class WithdrawVolunteerApplyServiceTest extends IntegrationTestSupport {
20+
21+
@Autowired
22+
private WithdrawVolunteerApplyService withdrawVolunteerApplyService;
23+
24+
@Autowired
25+
private VolunteerApplyRepository volunteerApplyRepository;
26+
27+
@DisplayName("봉사 지원을 철회할 수 있다.")
28+
@Test
29+
void withdraw() {
30+
// given
31+
UUID volunteerId = UUID.randomUUID();
32+
33+
VolunteerApply apply = createApply(volunteerId, APPROVED, false);
34+
volunteerApplyRepository.save(apply);
35+
36+
// when
37+
withdrawVolunteerApplyService.withdraw(apply.getId(), volunteerId);
38+
39+
// then
40+
Optional<VolunteerApply> withdraw = volunteerApplyRepository.findById(apply.getId());
41+
42+
assertThat(withdraw).isEmpty();
43+
}
44+
45+
@DisplayName("지원한 본인이 아닐 경우 에러가 발생한다.")
46+
@Test
47+
void withdrawWhenWrongVolunteerId() {
48+
// given
49+
UUID wrongId = UUID.randomUUID();
50+
51+
VolunteerApply apply = createApply(UUID.randomUUID(), APPROVED, false);
52+
volunteerApplyRepository.save(apply);
53+
54+
// when
55+
// then
56+
assertThatThrownBy(
57+
() -> withdrawVolunteerApplyService.withdraw(apply.getId(), wrongId)
58+
).isInstanceOf(BadRequestException.class)
59+
.hasMessage(UNAUTHORIZED_VOLUNTEER_APPLY.getMessage());
60+
}
61+
62+
private VolunteerApply createApply(UUID volunteerId, ApplyStatus status, boolean attended) {
63+
return VolunteerApply.builder()
64+
.volunteerId(volunteerId)
65+
.recruitBoardId(1L)
66+
.status(status)
67+
.attended(attended)
68+
.build();
69+
}
70+
}

0 commit comments

Comments
 (0)