1+ package com .somemore .recruitboard .service ;
2+
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+
5+ import com .somemore .IntegrationTestSupport ;
6+ import com .somemore .location .dto .request .LocationCreateRequestDto ;
7+ import com .somemore .location .repository .LocationRepository ;
8+ import com .somemore .recruitboard .domain .RecruitBoard ;
9+ import com .somemore .recruitboard .domain .VolunteerType ;
10+ import com .somemore .recruitboard .dto .request .RecruitCreateRequestDto ;
11+ import com .somemore .recruitboard .repository .RecruitBoardRepository ;
12+ import java .time .LocalDateTime ;
13+ import java .util .Optional ;
14+ import org .junit .jupiter .api .AfterEach ;
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 RecruitBoardUseCaseServiceTest extends IntegrationTestSupport {
20+
21+ @ Autowired
22+ private RecruitBoardUseCase recruitBoardUseCase ;
23+
24+ @ Autowired
25+ private RecruitBoardRepository recruitBoardRepository ;
26+
27+ @ Autowired
28+ private LocationRepository locationRepository ;
29+
30+ @ AfterEach
31+ void tearDown () {
32+ recruitBoardRepository .deleteAllInBatch ();
33+ locationRepository .deleteAllInBatch ();
34+ }
35+
36+ @ DisplayName ("봉사 모집글 생성 정보로 모집글을 저장한다" )
37+ @ Test
38+ void createRecruitBoardWithDto () {
39+ // given
40+ LocationCreateRequestDto locationDto = LocationCreateRequestDto .builder ()
41+ .address ("도로명 주소 33" )
42+ .latitude ("위도 정보" )
43+ .longitude ("경도 정보" )
44+ .build ();
45+
46+ RecruitCreateRequestDto dto = RecruitCreateRequestDto .builder ()
47+ .title ("봉사 모집글 작성" )
48+ .content ("봉사 하실분을 모집합니다. <br>" )
49+ .volunteerDate (LocalDateTime .now ())
50+ .volunteerType (VolunteerType .OTHER )
51+ .volunteerHours (4 )
52+ .admitted (true )
53+ .location (locationDto )
54+ .build ();
55+
56+ long centerId = 1L ;
57+ Optional <String > imgUrl = Optional .of ("https://image.domain.com/links" );
58+
59+ // when
60+ Long saveId = recruitBoardUseCase .createRecruitBoard (dto , centerId , imgUrl );
61+ Optional <RecruitBoard > recruitBoard = recruitBoardRepository .findById (saveId );
62+
63+ // then
64+ assertThat (recruitBoard .isPresent ()).isTrue ();
65+ assertThat (recruitBoard .get ().getId ()).isEqualTo (saveId );
66+ assertThat (recruitBoard .get ().getCenterId ()).isEqualTo (centerId );
67+ assertThat (recruitBoard .get ().getImgUrl ()).isEqualTo (imgUrl .get ());
68+ }
69+
70+ @ DisplayName ("봉사 모집글 저장시 이미지 링크가 없을 경우 빈 문자열을 저장한다" )
71+ @ Test
72+ void createRecruitBoardWhenImgUrlIsEmpty () {
73+ // given
74+ LocationCreateRequestDto locationDto = LocationCreateRequestDto .builder ()
75+ .address ("도로명 주소 33" )
76+ .latitude ("위도 정보" )
77+ .longitude ("경도 정보" )
78+ .build ();
79+
80+ RecruitCreateRequestDto dto = RecruitCreateRequestDto .builder ()
81+ .title ("봉사 모집글 작성" )
82+ .content ("봉사 하실분을 모집합니다. <br>" )
83+ .volunteerDate (LocalDateTime .now ())
84+ .volunteerType (VolunteerType .OTHER )
85+ .volunteerHours (4 )
86+ .admitted (true )
87+ .location (locationDto )
88+ .build ();
89+
90+ long centerId = 1L ;
91+ Optional <String > imgUrl = Optional .empty ();
92+
93+ // when
94+ Long saveId = recruitBoardUseCase .createRecruitBoard (dto , centerId , imgUrl );
95+ Optional <RecruitBoard > recruitBoard = recruitBoardRepository .findById (saveId );
96+
97+ // then
98+ assertThat (recruitBoard .isPresent ()).isTrue ();
99+ assertThat (recruitBoard .get ().getId ()).isEqualTo (saveId );
100+ assertThat (recruitBoard .get ().getCenterId ()).isEqualTo (centerId );
101+ assertThat (recruitBoard .get ().getImgUrl ()).isEqualTo ("" );
102+ }
103+ }
0 commit comments