Skip to content

Commit

Permalink
edit : 중복된 닉네임 확인 API 메서드 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
kkangh00n committed Apr 23, 2024
1 parent 9e704f5 commit 3119124
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public ResponseEntity<UserProfileResponse> getAnotherUserProfile(

@Operation(summary = "닉네임 중복 체크 API")
@ApiResponse(useReturnTypeSchema = true)
@PostMapping("/valid")
@GetMapping("/valid")
public ResponseEntity<ValidNicknameResponse> validNickname(
@Parameter(hidden = true) @AuthenticationPrincipal User loginUser,
@RequestBody ValidNicknameRequest validNicknameRequest
ValidNicknameRequest validNicknameRequest
) {
ValidNicknameResponse response = userService.isExistNickname(validNicknameRequest,
loginUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

@DisplayName("[UserController 테스트]")
class UserApiControllerTest extends ApiTestSupport {
Expand Down Expand Up @@ -204,13 +206,15 @@ void getUserProfileTest2() throws Exception {
void validNicknameTest1() throws Exception {
//given
String notExistName = "절대 중복된 이름 아님";
ValidNicknameRequest validNicknameRequest = new ValidNicknameRequest(notExistName);

//then
mockMvc.perform(post("/api/v1/users/valid")
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("nickname", notExistName);

mockMvc.perform(get("/api/v1/users/valid")
.header(AUTHORIZATION, accessToken)
.contentType(MediaType.APPLICATION_JSON)
.content(toJson(validNicknameRequest)))
.params(params))
.andExpect(jsonPath("$.isNotValid").value(true));
}

Expand All @@ -222,13 +226,15 @@ void validNicknameTest2() throws Exception {
loginUser.updateUser(existName, List.of(Category.CUSTOMIZABLE), Gender.MALE, 2000,
AgeGroup.TWENTY, "2호선", "사당역", "testURL");
userRepository.save(loginUser);
ValidNicknameRequest validNicknameRequest = new ValidNicknameRequest(existName);

//then
mockMvc.perform(post("/api/v1/users/valid")
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("nickname", existName);

mockMvc.perform(get("/api/v1/users/valid")
.header(AUTHORIZATION, accessToken)
.contentType(MediaType.APPLICATION_JSON)
.content(toJson(validNicknameRequest)))
.params(params))
.andExpect(jsonPath("$.isNotValid").value(true));
}

Expand All @@ -241,13 +247,14 @@ void validNicknameTest3() throws Exception {

String existName = anotherUser.getName();

ValidNicknameRequest validNicknameRequest = new ValidNicknameRequest(existName);

//then
mockMvc.perform(post("/api/v1/users/valid")
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("nickname", existName);

mockMvc.perform(get("/api/v1/users/valid")
.header(AUTHORIZATION, accessToken)
.contentType(MediaType.APPLICATION_JSON)
.content(toJson(validNicknameRequest)))
.params(params))
.andExpect(jsonPath("$.isNotValid").value(true));
}

Expand All @@ -262,13 +269,13 @@ void validNicknameTest4() throws Exception {
AgeGroup.TWENTY, "2호선", "사당역", "testURL");
userRepository.save(loginUser);

ValidNicknameRequest validNicknameRequest = new ValidNicknameRequest(existName);

//then
mockMvc.perform(post("/api/v1/users/valid")
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("nickname", existName);
mockMvc.perform(get("/api/v1/users/valid")
.header(AUTHORIZATION, accessToken)
.contentType(MediaType.APPLICATION_JSON)
.content(toJson(validNicknameRequest)))
.params(params))
.andExpect(jsonPath("$.isNotValid").value(true));
}
}

0 comments on commit 3119124

Please sign in to comment.