Skip to content

Commit

Permalink
fix: merge 오류 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
choidongkuen committed Feb 11, 2024
2 parents 3320e60 + f3699f1 commit e46b706
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.teumteum.meeting.domain.response;

import java.util.List;
import net.teumteum.user.domain.User;

public record MeetingParticipantsForReviewResponse(
List<MeetingParticipantForReviewResponse> participants
) {

public static MeetingParticipantsForReviewResponse of(List<User> users) {
return new MeetingParticipantsForReviewResponse(
users.stream()
.map(user -> new MeetingParticipantForReviewResponse(
user.getId(),
user.getCharacterId(),
user.getName(),
user.getJob().getDetailJobClass()))
.toList()
);
}

public record MeetingParticipantForReviewResponse(
Long id,
Long characterId,
String name,
String job
) {

}
}
7 changes: 4 additions & 3 deletions src/main/java/net/teumteum/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ public InterestQuestionResponse getInterestQuestionByUserIds(List<Long> userIds,
}

private void checkUserExistence(Authenticated authenticated, String oauthId) {
userRepository.findByAuthenticatedAndOAuthId(authenticated, oauthId)
.ifPresent(user -> {
boolean userExists = userRepository.findByAuthenticatedAndOAuthId(authenticated, oauthId).isPresent();
Assert.isTrue(!userExists, () -> {
throw new IllegalArgumentException("일치하는 user 가 이미 존재합니다.");
});
}
);
}

private void checkMeetingExistence(Long meetingId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ void Register_user_card_with_201_created() throws Exception {
.andExpect(jsonPath("$.refreshToken").value(VALID_REFRESH_TOKEN));
}

@Test
@DisplayName("이미 카드 등록한 사용자의 등록 요청값이 주어지면, 400 Bad Request을 반환한다.")
void Return_400_bad_request_if_user_already_exist() throws Exception {
// given
UserRegisterRequest request = RequestFixture.userRegisterRequest(user);

given(userService.register(any(UserRegisterRequest.class)))
.willThrow(new IllegalArgumentException("일치하는 user 가 이미 존재합니다."));

// when && then
mockMvc.perform(post("/users")
.content(objectMapper.writeValueAsString(request))
.contentType(APPLICATION_JSON)
.with(csrf())
.header(AUTHORIZATION, VALID_ACCESS_TOKEN))
.andDo(print())
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.message").value("일치하는 user 가 이미 존재합니다."));
}

@Test
@DisplayName("유효하지 않은 사용자의 등록 요청값이 주어지면, 400 Bad Request 상태값을 반환한다.")
void Register_user_card_with_400_bad_request() throws Exception {
Expand Down Expand Up @@ -144,6 +164,26 @@ void Withdraw_user_with_200_ok() throws Exception {
.andDo(print())
.andExpect(status().isOk());
}

@Test
@DisplayName("회원 탈퇴 하고자 하는 회원이 존재하지 않으면")
void Return_400_bad_request_if_user_is_not_exist() throws Exception {
// given
UserWithdrawRequest request
= RequestFixture.userWithdrawRequest(List.of("쓰지 않는 앱이에요", "오류가 생겨서 쓸 수 없어요"));

doThrow(new IllegalArgumentException("일치하는 user가 이미 존재합니다.")).when(userService).withdraw(any(
UserWithdrawRequest.class), anyLong());

// when && then
mockMvc.perform(post("/users/withdraws")
.content(objectMapper.writeValueAsString(request))
.contentType(APPLICATION_JSON)
.with(csrf())
.header(AUTHORIZATION, VALID_ACCESS_TOKEN))
.andDo(print())
.andExpect(status().isBadRequest());
}
}

@Nested
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/net/teumteum/unit/user/service/UserServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ void If_valid_user_withdraw_request_withdraw_user() {
verify(redisService, times(1)).deleteData(anyString());
verify(withdrawReasonRepository, times(1)).saveAll(any());
}

@Test
@DisplayName("유저 id에 해당하는 유저가 존재하지 않는 경우, 400 Bad Request 을 반환한다.")
void Return_400_bad_request_if_user_is_not_exist() {
// given
UserWithdrawRequest request
= RequestFixture.userWithdrawRequest(List.of("쓰지 않는 앱이에요", "오류가 생겨서 쓸 수 없어요"));

long userId = 1L;

given(userRepository.findById(anyLong()))
.willThrow(new IllegalArgumentException("userId 에 해당하는 user를 찾을 수 없습니다."));

// When & Then
assertThatThrownBy(() -> userService.withdraw(request, userId))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("userId 에 해당하는 user를 찾을 수 없습니다.");
}
}

@Nested
Expand Down

0 comments on commit e46b706

Please sign in to comment.