Skip to content

Commit 7582212

Browse files
committed
refactor: #72 403 에러 검증 로직 제거
1 parent 060c726 commit 7582212

File tree

5 files changed

+7
-44
lines changed

5 files changed

+7
-44
lines changed

src/main/java/com/ajou/hertz/domain/user/controller/UserController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public UserResponse updateContactLinkV1(
127127
@RequestBody @Valid UpdateContactLinkRequest updateContactLinkRequest,
128128
@AuthenticationPrincipal UserPrincipal userPrincipal
129129
) {
130-
UserDto userUpdated = userCommandService.updateContactLink(userPrincipal.getUserId(), userPrincipal.getUserId(),
130+
UserDto userUpdated = userCommandService.updateContactLink(userPrincipal.getUserId(),
131131
updateContactLinkRequest.getContactLink());
132132
return UserResponse.from(userUpdated);
133133
}

src/main/java/com/ajou/hertz/domain/user/exception/UserIdForbiddenException.java

-11
This file was deleted.

src/main/java/com/ajou/hertz/domain/user/service/UserCommandService.java

+2-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import com.ajou.hertz.domain.user.dto.request.SignUpRequest;
1515
import com.ajou.hertz.domain.user.entity.User;
1616
import com.ajou.hertz.domain.user.exception.UserEmailDuplicationException;
17-
import com.ajou.hertz.domain.user.exception.UserIdForbiddenException;
1817
import com.ajou.hertz.domain.user.exception.UserKakaoUidDuplicationException;
1918
import com.ajou.hertz.domain.user.exception.UserPhoneDuplicationException;
2019
import com.ajou.hertz.domain.user.repository.UserRepository;
@@ -134,18 +133,12 @@ private String generateRandom16CharString() {
134133
/**
135134
*연락 수단을 변경합니다.
136135
*
137-
* @param loginUserId API를 호출한 유저의 ID
138-
* @param userId 변경하고자 하는 유저의 ID
136+
* @param userId 유저의 ID
139137
* @param contactLink 변경할 연락 수단
140-
*@throws UserIdForbiddenException 유저ID가 일치하지 않는 경우
141138
*
142139
*@return 변경된 유저 정보
143140
*/
144-
public UserDto updateContactLink(Long loginUserId, Long userId, String contactLink) {
145-
if (!loginUserId.equals(userId)) {
146-
User user = userQueryService.getById(userId);
147-
throw new UserIdForbiddenException(userId, loginUserId);
148-
}
141+
public UserDto updateContactLink(Long userId, String contactLink) {
149142
User user = userQueryService.getById(userId);
150143
user.changeContactLink(contactLink);
151144
return UserDto.from(user);

src/test/java/com/ajou/hertz/unit/domain/user/controller/UserControllerTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public void securitySetUp() throws Exception {
219219
String newContactLink = "https://new-contact-link.com";
220220
UserDto expectedResult = createUserDto(userId);
221221
UserDetails testUser = createTestUser(userId);
222-
given(userCommandService.updateContactLink(anyLong(), anyLong(), anyString())).willReturn(expectedResult);
222+
given(userCommandService.updateContactLink(anyLong(), anyString())).willReturn(expectedResult);
223223

224224
// when & then
225225
mvc.perform(
@@ -231,7 +231,7 @@ public void securitySetUp() throws Exception {
231231
)
232232
.andExpect(status().isOk())
233233
.andExpect(jsonPath("$.contactLink").value(expectedResult.getContactLink()));
234-
then(userCommandService).should().updateContactLink(userId, userId, newContactLink);
234+
then(userCommandService).should().updateContactLink(userId, newContactLink);
235235
verifyEveryMocksShouldHaveNoMoreInteractions();
236236
}
237237

src/test/java/com/ajou/hertz/unit/domain/user/service/UserCommandServiceTest.java

+2-21
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.ajou.hertz.domain.user.dto.request.SignUpRequest;
2929
import com.ajou.hertz.domain.user.entity.User;
3030
import com.ajou.hertz.domain.user.exception.UserEmailDuplicationException;
31-
import com.ajou.hertz.domain.user.exception.UserIdForbiddenException;
3231
import com.ajou.hertz.domain.user.exception.UserKakaoUidDuplicationException;
3332
import com.ajou.hertz.domain.user.exception.UserNotFoundByIdException;
3433
import com.ajou.hertz.domain.user.exception.UserPhoneDuplicationException;
@@ -182,7 +181,7 @@ static Stream<Arguments> testDataForCreateNewUserWithKakao() throws Exception {
182181
given(userQueryService.getById(userId)).willReturn(user);
183182

184183
// when
185-
UserDto updatedUserDto = sut.updateContactLink(userId, userId, contactLink);
184+
UserDto updatedUserDto = sut.updateContactLink(userId, contactLink);
186185

187186
// then
188187
then(userQueryService).should().getById(userId);
@@ -198,32 +197,14 @@ static Stream<Arguments> testDataForCreateNewUserWithKakao() throws Exception {
198197
given(userQueryService.getById(userId)).willThrow(UserNotFoundByIdException.class);
199198

200199
// when
201-
Throwable t = catchThrowable(() -> sut.updateContactLink(userId, userId, contactLink));
200+
Throwable t = catchThrowable(() -> sut.updateContactLink(userId, contactLink));
202201

203202
// then
204203
then(userQueryService).should().getById(userId);
205204
verifyEveryMocksShouldHaveNoMoreInteractions();
206205
assertThat(t).isInstanceOf(UserNotFoundByIdException.class);
207206
}
208207

209-
@Test
210-
void 주어진_유저_ID가_API를_호출한_유저의_ID와_일치하지_않는다면_에러가_발생한다() throws Exception {
211-
// given
212-
Long loginUserId = 1L;
213-
Long userId = 2L;
214-
String contactLink = "https://new-contactLink";
215-
User user = createUser(userId, "$2a$abc123", "12345");
216-
given(userQueryService.getById(userId)).willReturn(user);
217-
218-
// when
219-
Throwable t = catchThrowable(() -> sut.updateContactLink(loginUserId, userId, contactLink));
220-
221-
// then
222-
assertThat(t).isInstanceOf(UserIdForbiddenException.class);
223-
then(userQueryService).should().getById(userId);
224-
verifyEveryMocksShouldHaveNoMoreInteractions();
225-
}
226-
227208
private void verifyEveryMocksShouldHaveNoMoreInteractions() {
228209
then(userQueryService).shouldHaveNoMoreInteractions();
229210
then(userRepository).shouldHaveNoMoreInteractions();

0 commit comments

Comments
 (0)