1+ package com .somemore .facade .validator ;
2+
3+ import com .somemore .IntegrationTestSupport ;
4+ import com .somemore .global .exception .BadRequestException ;
5+ import com .somemore .recruitboard .domain .RecruitBoard ;
6+ import com .somemore .recruitboard .repository .RecruitBoardRepository ;
7+ import com .somemore .volunteerApply .domain .ApplyStatus ;
8+ import com .somemore .volunteerApply .domain .VolunteerApply ;
9+ import com .somemore .volunteerApply .repository .VolunteerApplyRepository ;
10+ import org .junit .jupiter .api .DisplayName ;
11+ import org .junit .jupiter .api .Test ;
12+ import org .springframework .beans .factory .annotation .Autowired ;
13+ import org .springframework .transaction .annotation .Transactional ;
14+
15+ import java .util .UUID ;
16+
17+ import static com .somemore .common .fixture .RecruitBoardFixture .createRecruitBoard ;
18+ import static com .somemore .global .exception .ExceptionMessage .UNAUTHORIZED_VOLUNTEER_DETAIL ;
19+ import static org .assertj .core .api .Assertions .assertThatCode ;
20+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
21+
22+ @ Transactional
23+ class VolunteerDetailAccessValidatorImplTest extends IntegrationTestSupport {
24+
25+ @ Autowired
26+ private VolunteerDetailAccessValidatorImpl volunteerDetailAccessValidatorImpl ;
27+
28+ @ Autowired
29+ private RecruitBoardRepository recruitBoardRepository ;
30+
31+ @ Autowired
32+ private VolunteerApplyRepository volunteerApplyRepository ;
33+
34+ @ DisplayName ("타겟 봉사자가 모집 글과 연관된 경우 검증 통과, 연관되지 않은 경우 예외를 던진다" )
35+ @ Test
36+ void validateByCenterIdThrowsExceptionWhenVolunteerNotLinked () {
37+ // given
38+ UUID centerId = UUID .randomUUID ();
39+
40+ RecruitBoard recruitBoard = createRecruitBoard (centerId );
41+ recruitBoardRepository .save (recruitBoard );
42+
43+ UUID unrelatedVolunteerId = UUID .randomUUID ();
44+ UUID relatedVolunteerId = UUID .randomUUID ();
45+
46+ VolunteerApply volunteerApply = createVolunteerApply (recruitBoard .getId (), relatedVolunteerId );
47+ volunteerApplyRepository .save (volunteerApply );
48+
49+ // when
50+ // then
51+ assertThatCode (() -> volunteerDetailAccessValidatorImpl .validateByCenterId (centerId , relatedVolunteerId ))
52+ .doesNotThrowAnyException ();
53+
54+ assertThatThrownBy (() -> volunteerDetailAccessValidatorImpl .validateByCenterId (centerId , unrelatedVolunteerId ))
55+ .isInstanceOf (BadRequestException .class )
56+ .hasMessage (UNAUTHORIZED_VOLUNTEER_DETAIL .getMessage ());
57+ }
58+
59+ private VolunteerApply createVolunteerApply (Long recruitId , UUID volunteerId ) {
60+ return VolunteerApply .builder ()
61+ .recruitBoardId (recruitId )
62+ .volunteerId (volunteerId )
63+ .status (ApplyStatus .WAITING )
64+ .attended (false )
65+ .build ();
66+ }
67+ }
0 commit comments