1+ package com .somemore .volunteer .service ;
2+
3+ import com .somemore .global .exception .NoSuchElementException ;
4+ import com .somemore .support .IntegrationTestSupport ;
5+ import com .somemore .user .domain .UserCommonAttribute ;
6+ import com .somemore .user .domain .UserRole ;
7+ import com .somemore .user .repository .usercommonattribute .UserCommonAttributeRepository ;
8+ import com .somemore .user .usecase .UserQueryUseCase ;
9+ import com .somemore .volunteer .domain .NEWVolunteer ;
10+ import com .somemore .volunteer .dto .VolunteerProfileResponseDto ;
11+ import com .somemore .volunteer .repository .NEWVolunteerRepository ;
12+ import com .somemore .volunteer .usecase .NEWVolunteerQueryUseCase ;
13+ import org .junit .jupiter .api .DisplayName ;
14+ import org .junit .jupiter .api .Test ;
15+ import org .springframework .beans .factory .annotation .Autowired ;
16+ import org .springframework .transaction .annotation .Transactional ;
17+
18+ import java .util .UUID ;
19+
20+ import static org .assertj .core .api .Assertions .assertThat ;
21+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
22+
23+ @ Transactional
24+ class GetVolunteerProfileServiceTest extends IntegrationTestSupport {
25+
26+ @ Autowired
27+ private GetVolunteerProfileService getVolunteerProfileService ;
28+
29+ @ Autowired
30+ private NEWVolunteerQueryUseCase volunteerQueryUseCase ;
31+
32+ @ Autowired
33+ private UserQueryUseCase userQueryUseCase ;
34+
35+ @ Autowired
36+ private NEWVolunteerRepository volunteerRepository ;
37+
38+ @ Autowired
39+ private UserCommonAttributeRepository userCommonAttributeRepository ;
40+
41+ @ Test
42+ @ DisplayName ("성공적으로 봉사자 프로필을 조회할 수 있다" )
43+ void testGetVolunteerProfileSuccess () {
44+ // given
45+ UUID userId = UUID .randomUUID ();
46+ NEWVolunteer expectedVolunteer = NEWVolunteer .createDefault (userId );
47+ UserCommonAttribute expectedCommonAttribute = UserCommonAttribute .createDefault (userId , UserRole .VOLUNTEER );
48+ volunteerRepository .save (expectedVolunteer );
49+ userCommonAttributeRepository .save (expectedCommonAttribute );
50+
51+ // when
52+ VolunteerProfileResponseDto volunteerProfileResponseDto = getVolunteerProfileService .getProfileByUserId (userId );
53+
54+ // then
55+ assertThat (volunteerProfileResponseDto )
56+ .isNotNull ();
57+ assertThat (volunteerProfileResponseDto .nickname ())
58+ .isEqualTo (expectedVolunteer .getNickname ());
59+ assertThat (volunteerProfileResponseDto .tier ())
60+ .isEqualTo (expectedVolunteer .getTier ().name ());
61+ assertThat (volunteerProfileResponseDto .imgUrl ())
62+ .isEqualTo (expectedCommonAttribute .getImgUrl ());
63+ assertThat (volunteerProfileResponseDto .introduce ())
64+ .isEqualTo (expectedCommonAttribute .getIntroduce ());
65+ assertThat (volunteerProfileResponseDto .totalVolunteerHours ())
66+ .isEqualTo (expectedVolunteer .getTotalVolunteerHours ());
67+ assertThat (volunteerProfileResponseDto .totalVolunteerCount ())
68+ .isEqualTo (expectedVolunteer .getTotalVolunteerCount ());
69+
70+ VolunteerProfileResponseDto .Detail detail = volunteerProfileResponseDto .detail ();
71+
72+ assertThat (detail .name ())
73+ .isEqualTo (expectedCommonAttribute .getName ());
74+ assertThat (detail .gender ())
75+ .isEqualTo (expectedVolunteer .getGender ().name ());
76+ assertThat (detail .contactNumber ())
77+ .isEqualTo (expectedCommonAttribute .getContactNumber ());
78+ }
79+
80+ @ Test
81+ @ DisplayName ("존재하지 않는 봉사자 프로필 조회 시 예외를 발생시킨다" )
82+ void testGetVolunteerProfileNotFound () {
83+ // given
84+ UUID nonExistUserId = UUID .randomUUID ();
85+
86+ // when
87+ // then
88+ assertThatThrownBy (() -> volunteerQueryUseCase .getByUserId (nonExistUserId ))
89+ .isInstanceOf (NoSuchElementException .class );
90+ }
91+
92+ }
0 commit comments