1313import com .somemore .domains .volunteerapply .dto .response .VolunteerApplyResponseDto ;
1414import com .somemore .domains .volunteerapply .dto .response .VolunteerApplySummaryResponseDto ;
1515import com .somemore .domains .volunteerapply .repository .VolunteerApplyRepository ;
16+ import com .somemore .global .exception .ExceptionMessage ;
1617import com .somemore .global .exception .NoSuchElementException ;
1718import com .somemore .support .IntegrationTestSupport ;
1819import java .util .List ;
1920import java .util .UUID ;
21+
22+ import org .junit .jupiter .api .BeforeEach ;
2023import org .junit .jupiter .api .DisplayName ;
2124import org .junit .jupiter .api .Test ;
2225import org .springframework .beans .factory .annotation .Autowired ;
@@ -34,50 +37,75 @@ class VolunteerApplyQueryServiceTest extends IntegrationTestSupport {
3437 @ Autowired
3538 private VolunteerApplyRepository volunteerApplyRepository ;
3639
37- @ DisplayName ("recruitIds로 봉사자 ID 리스트를 조회할 수 있다" )
40+ private Long recruitBoardId ;
41+ private UUID volunteerId ;
42+ private VolunteerApply apply ;
43+
44+ @ BeforeEach
45+ void setUp () {
46+ recruitBoardId = 1234L ;
47+ volunteerId = UUID .randomUUID ();
48+ apply = createApply (volunteerId , recruitBoardId );
49+ volunteerApplyRepository .save (apply );
50+ }
51+
52+ @ DisplayName ("봉사 지원 아이디로 조회할 수 있다." )
3853 @ Test
39- void getVolunteerIdsByRecruitIds () {
40- // Given
41- Long recruitId1 = 10L ;
42- Long recruitId2 = 20L ;
43- UUID volunteerId1 = UUID .randomUUID ();
44- UUID volunteerId2 = UUID .randomUUID ();
54+ void getById () {
55+ // given
56+ Long id = apply .getId ();
4557
46- VolunteerApply apply1 = createApply ( volunteerId1 , recruitId1 );
47- VolunteerApply apply2 = createApply ( volunteerId2 , recruitId2 );
58+ // when
59+ VolunteerApply findApply = volunteerApplyQueryService . getById ( id );
4860
49- volunteerApplyRepository .save (apply1 );
50- volunteerApplyRepository .save (apply2 );
61+ // then
62+ assertThat (findApply .getId ()).isEqualTo (id );
63+ assertThat (findApply .getVolunteerId ()).isEqualTo (volunteerId );
64+ assertThat (findApply .getRecruitBoardId ()).isEqualTo (recruitBoardId );
65+ }
5166
52- // When
53- List <UUID > volunteerIds = volunteerApplyQueryService .getVolunteerIdsByRecruitIds (
54- List .of (recruitId1 , recruitId2 ));
67+ @ DisplayName ("존재하지 않는 봉사 지원 아이디로 조회할 경우 에러가 발생한다." )
68+ @ Test
69+ void getByIdWhenDoesNotExist () {
70+ // given
71+ Long wrongId = 999L ;
5572
56- // Then
57- assertThat (volunteerIds )
58- .hasSize (2 )
59- .containsExactlyInAnyOrder (volunteerId1 , volunteerId2 );
73+ // when
74+ // then
75+ assertThatThrownBy (
76+ () -> volunteerApplyQueryService .getById (wrongId ))
77+ .isInstanceOf (NoSuchElementException .class )
78+ .hasMessage (NOT_EXISTS_VOLUNTEER_APPLY .getMessage ());
6079 }
6180
6281 @ DisplayName ("모집글 아이디와 봉사자 아이디로 조회할 수 있다" )
6382 @ Test
6483 void getByRecruitIdAndVolunteerId () {
6584 // given
66- Long recruitId = 1234L ;
67- UUID volunteerId = UUID .randomUUID ();
68-
69- VolunteerApply newApply = createApply (volunteerId , recruitId );
70- volunteerApplyRepository .save (newApply );
71-
7285 // when
73- VolunteerApply apply = volunteerApplyQueryService .getByRecruitIdAndVolunteerId (
74- recruitId , volunteerId );
86+ VolunteerApply apply = volunteerApplyQueryService .getByRecruitIdAndVolunteerId (recruitBoardId , volunteerId );
7587
7688 // then
77- assertThat (apply .getRecruitBoardId ()).isEqualTo (recruitId );
89+ assertThat (apply .getRecruitBoardId ()).isEqualTo (recruitBoardId );
7890 assertThat (apply .getVolunteerId ()).isEqualTo (volunteerId );
7991 }
8092
93+ @ DisplayName ("존재하지 않는 모집글 아이디와 봉사자 아이디로 조회할 수 있다" )
94+ @ Test
95+ void getByRecruitIdAndVolunteerIdWhenDoesNotExist () {
96+ // given
97+ Long wrongRecruitBoardId = 999L ;
98+ UUID wrongVolunteerId = UUID .randomUUID ();
99+
100+ // when
101+ // then
102+ assertThatThrownBy (
103+ () -> volunteerApplyQueryService .getByRecruitIdAndVolunteerId (wrongRecruitBoardId , wrongVolunteerId ))
104+ .isInstanceOf (NoSuchElementException .class )
105+ .hasMessage (NOT_EXISTS_VOLUNTEER_APPLY .getMessage ());
106+
107+ }
108+
81109 @ DisplayName ("모집글 아이디로 지원 현황을 조회할 수 있다." )
82110 @ Test
83111 void getSummaryByRecruitBoardId () {
@@ -197,6 +225,31 @@ void getAllByIds() {
197225 .containsExactlyInAnyOrderElementsOf (ids );
198226 }
199227
228+ @ DisplayName ("recruitIds로 봉사자 ID 리스트를 조회할 수 있다" )
229+ @ Test
230+ void getVolunteerIdsByRecruitIds () {
231+ // Given
232+ Long recruitId1 = 10L ;
233+ Long recruitId2 = 20L ;
234+ UUID volunteerId1 = UUID .randomUUID ();
235+ UUID volunteerId2 = UUID .randomUUID ();
236+
237+ VolunteerApply apply1 = createApply (volunteerId1 , recruitId1 );
238+ VolunteerApply apply2 = createApply (volunteerId2 , recruitId2 );
239+
240+ volunteerApplyRepository .save (apply1 );
241+ volunteerApplyRepository .save (apply2 );
242+
243+ // When
244+ List <UUID > volunteerIds = volunteerApplyQueryService .getVolunteerIdsByRecruitIds (
245+ List .of (recruitId1 , recruitId2 ));
246+
247+ // Then
248+ assertThat (volunteerIds )
249+ .hasSize (2 )
250+ .containsExactlyInAnyOrder (volunteerId1 , volunteerId2 );
251+ }
252+
200253 @ DisplayName ("존재하지 않는 봉사 지원을 조회할 경우 에러가 발생한다." )
201254 @ Test
202255 void getByRecruitIdAndVolunteerIdWhenNotExist () {
0 commit comments