Skip to content

Commit ce40522

Browse files
committed
test(user): 사용자 기본 정보 업데이트 서비스 테스트 추가
- 봉사자의 기본 정보를 업데이트하는 테스트 케이스 추가 - 센터의 기본 정보를 업데이트하는 테스트 케이스 추가
1 parent 7696cb9 commit ce40522

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package com.somemore.user.service;
2+
3+
import com.somemore.center.domain.NEWCenter;
4+
import com.somemore.center.repository.NEWCenterRepository;
5+
import com.somemore.support.IntegrationTestSupport;
6+
import com.somemore.user.domain.User;
7+
import com.somemore.user.domain.UserCommonAttribute;
8+
import com.somemore.user.domain.UserRole;
9+
import com.somemore.user.dto.UserAuthInfo;
10+
import com.somemore.user.dto.basicinfo.CenterBasicInfoRequestDto;
11+
import com.somemore.user.dto.basicinfo.CommonBasicInfoRequestDto;
12+
import com.somemore.user.dto.basicinfo.VolunteerBasicInfoRequestDto;
13+
import com.somemore.user.repository.user.UserRepository;
14+
import com.somemore.user.repository.usercommonattribute.UserCommonAttributeRepository;
15+
import com.somemore.volunteer.domain.NEWVolunteer;
16+
import com.somemore.volunteer.repository.NEWVolunteerRepository;
17+
import org.junit.jupiter.api.DisplayName;
18+
import org.junit.jupiter.api.Test;
19+
import org.springframework.beans.factory.annotation.Autowired;
20+
import org.springframework.transaction.annotation.Transactional;
21+
22+
import java.util.UUID;
23+
24+
import static org.assertj.core.api.Assertions.assertThat;
25+
26+
@Transactional
27+
class UpdateBasicInfoServiceTest extends IntegrationTestSupport {
28+
29+
@Autowired
30+
private UpdateBasicInfoService updateBasicInfoService;
31+
32+
@Autowired
33+
private UserRepository userRepository;
34+
@Autowired
35+
private UserCommonAttributeRepository userCommonAttributeRepository;
36+
@Autowired
37+
private NEWVolunteerRepository volunteerRepository;
38+
@Autowired
39+
private NEWCenterRepository centerRepository;
40+
41+
@Test
42+
@DisplayName("봉사자 기본 정보를 업데이트 할 수 있다.")
43+
void updateVolunteerBasicInfo() {
44+
// given
45+
UUID userId = UUID.randomUUID();
46+
UserAuthInfo authInfo = UserAuthInfo.of("test", "test");
47+
User user = User.of(authInfo, UserRole.VOLUNTEER);
48+
UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(userId, UserRole.VOLUNTEER);
49+
50+
NEWVolunteer volunteer = NEWVolunteer.createDefault(userId);
51+
52+
userRepository.save(user);
53+
userCommonAttributeRepository.save(userCommonAttribute);
54+
volunteerRepository.save(volunteer);
55+
56+
CommonBasicInfoRequestDto commonBasicInfoRequestDto = createCommonBasicInfoRequestDto();
57+
58+
VolunteerBasicInfoRequestDto volunteerBasicInfoRequestDto =
59+
new VolunteerBasicInfoRequestDto(
60+
commonBasicInfoRequestDto,
61+
"test",
62+
"test");
63+
64+
boolean customizedBeforeUpdate = userCommonAttributeRepository.findIsCustomizedByUserId(userId)
65+
.orElseThrow();
66+
67+
// when
68+
updateBasicInfoService.update(userId, volunteerBasicInfoRequestDto);
69+
70+
// then
71+
boolean customizedAfterUpdate = userCommonAttributeRepository.findIsCustomizedByUserId(userId)
72+
.orElseThrow();
73+
74+
assertThat(customizedBeforeUpdate).isFalse();
75+
assertThat(customizedAfterUpdate).isTrue();
76+
}
77+
78+
@Test
79+
@DisplayName("센터 기본 정보를 업데이트 할 수 있다.")
80+
void updateCenterBasicInfo() {
81+
// given
82+
UUID userId = UUID.randomUUID();
83+
UserAuthInfo authInfo = UserAuthInfo.of("centerTest", "centerTest");
84+
User user = User.of(authInfo, UserRole.CENTER);
85+
UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(userId, UserRole.CENTER);
86+
87+
NEWCenter center = NEWCenter.createDefault(userId);
88+
89+
userRepository.save(user);
90+
userCommonAttributeRepository.save(userCommonAttribute);
91+
centerRepository.save(center);
92+
93+
CommonBasicInfoRequestDto commonBasicInfoRequestDto = createCommonBasicInfoRequestDto();
94+
95+
CenterBasicInfoRequestDto centerBasicInfoRequestDto =
96+
new CenterBasicInfoRequestDto(
97+
commonBasicInfoRequestDto,
98+
"Main Center"
99+
);
100+
101+
boolean customizedBeforeUpdate = userCommonAttributeRepository.findIsCustomizedByUserId(userId)
102+
.orElseThrow();
103+
104+
// when
105+
updateBasicInfoService.update(userId, centerBasicInfoRequestDto);
106+
107+
// then
108+
boolean customizedAfterUpdate = userCommonAttributeRepository.findIsCustomizedByUserId(userId)
109+
.orElseThrow();
110+
111+
assertThat(customizedBeforeUpdate).isFalse();
112+
assertThat(customizedAfterUpdate).isTrue();
113+
}
114+
115+
private static CommonBasicInfoRequestDto createCommonBasicInfoRequestDto() {
116+
return new CommonBasicInfoRequestDto(
117+
"test",
118+
"test",
119+
"test",
120+
"test"
121+
);
122+
}
123+
}

0 commit comments

Comments
 (0)