Skip to content

Commit

Permalink
[FEAT] validation for portfolio url start with https://
Browse files Browse the repository at this point in the history
  • Loading branch information
nogamsung committed Feb 22, 2024
1 parent 4a884ca commit a0508ed
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public ResponseEntity<DefaultNoResponse> updateDescription(
"LEVEL_FIELD_REQUIRED || LEVEL_TYPE_INVALID || INSTITUTION_NAME_LENGTH_INVALID || " +
"STARTED_AT_FIELD_REQUIRED || IS_CURRENT_FIELD_REQUIRED || CORPORATION_NAME_LENGTH_INVALID || " +
"WORK_DESCRIPTION_LENGTH_INVALID || PORTFOLIO_NAME_LENGTH_INVALID || " +
"PORTFOLIO_URL_FIELD_REQUIRED || PORTFOLIO_URL_LENGTH_INVALID || MEDIA_FIELD_REQUIRED || " +
"PORTFOLIO_URL_LENGTH_INVALID || PORTFOLIO_URL_FORMAT_INVALID|| MEDIA_FIELD_REQUIRED || " +
"MEDIA_TYPE_INVALID || EDUCATION_DATE_INVALID || EDUCATION_ENDED_AT_FIELD_REQUIRED || " +
"WORK_DATE_INVALID || WORK_ENDED_AT_FIELD_REQUIRED\n" +
"- 401 = TOKEN_UNAUTHENTICATED\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class PortfolioUpdateRequest {
private String portfolioName;

@ApiModelProperty(position = 2, required = true, value = "포트폴리오 URL", example = "github.com/gabojait")
@Size(min = 1, max = 1000, message = "URL은 1~1000자만 가능합니다.")
@Size(min = 10, max = 1000, message = "포트폴리오 URL은 10~1000자만 가능합니다.")
@Pattern(regexp = "^https\\:\\/\\/.+$", message = "포트폴리오 URL은 'https://'로 시작하는 형식만 가능합니다.")
private String portfolioUrl;

@ApiModelProperty(position = 3, required = true, value = "미디어", example = "LINK")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import lombok.Getter;
import org.springframework.http.HttpStatus;

import javax.validation.constraints.NotBlank;

import static org.springframework.http.HttpStatus.*;

@Getter
Expand Down Expand Up @@ -57,7 +55,7 @@ public enum ErrorCode {
INSTITUTION_NAME_LENGTH_INVALID(BAD_REQUEST, "학교명은 3~20자만 가능합니다."),
CORPORATION_NAME_LENGTH_INVALID(BAD_REQUEST, "기관명은 1~20자만 가능합니다."),
WORK_DESCRIPTION_LENGTH_INVALID(BAD_REQUEST, "경력 설명은 0~100자만 가능합니다."),
PORTFOLIO_URL_LENGTH_INVALID(BAD_REQUEST, "URL은 1~1000자만 가능합니다."),
PORTFOLIO_URL_LENGTH_INVALID(BAD_REQUEST, "포트폴리오 URL은 10~1000자만 가능합니다."),
PROJECT_NAME_LENGTH_INVALID(BAD_REQUEST, "프로젝트명은 1~20자만 가능합니다."),
PROJECT_DESCRIPTION_LENGTH_INVALID(BAD_REQUEST, "프로젝트 설명은 1~500자만 가능합니다."),
EXPECTATION_LENGTH_INVALID(BAD_REQUEST, "바라는 점은 1~200자만 가능합니다."),
Expand All @@ -80,6 +78,7 @@ public enum ErrorCode {
LEADER_POSITION_TYPE_INVALID(BAD_REQUEST, "팀장 포지션은 'DESIGNER', 'BACKEND', 'FRONTEND', 또는 'MANAGER' 중 하나여야 됩니다."),
LEVEL_TYPE_INVALID(BAD_REQUEST, "레벨은 'LOW', 'MID', 또는 'HIGH' 중 하나여야 됩니다."),
MEDIA_TYPE_INVALID(BAD_REQUEST, "미디어는 'LINK' 또는 'FILE' 중 하나여야 됩니다."),
PORTFOLIO_URL_FORMAT_INVALID(BAD_REQUEST, "포트폴리오 URL은 'https://'로 시작하는 형식만 가능합니다."),

// @Positive, @PositiveOrZero
USER_ID_POSITIVE_ONLY(BAD_REQUEST, "회원 식별자는 양수만 가능합니다."),
Expand Down Expand Up @@ -122,6 +121,7 @@ public enum ErrorCode {
*/
TOKEN_UNAUTHORIZED(FORBIDDEN, "권한이 없는 요청입니다. 로그인 후에 다시 시도 해주세요."),
REQUEST_FORBIDDEN(FORBIDDEN, "권한이 없는 요청입니다."),
SUSPEND_FORBIDDEN(FORBIDDEN, "정지일: START_DATE ~ END_DATE\n사유: REASON"),

/**
* 404 Not found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,11 @@ void givenPortfolioGreaterThan10SizePortfolioName_whenUpdateProfile_thenReturn40
}

@Test
@DisplayName("포트폴리오에 포트폴리오 URL이 1자 미만일시 프로필 업데이트를 하면 400을 반환한다.")
void givenPortfolioLessThan1SizePortfolioUrl_whenUpdateProfile_thenReturn400() throws Exception {
@DisplayName("포트폴리오에 포트폴리오 URL이 10자 미만일시 프로필 업데이트를 하면 400을 반환한다.")
void givenPortfolioLessThan10SizePortfolioUrl_whenUpdateProfile_thenReturn400() throws Exception {
// given
ProfileUpdateRequest request = createValidProfileUpdateRequest();
request.getPortfolios().get(0).setPortfolioUrl("");
request.getPortfolios().get(0).setPortfolioUrl("https://a");

// when
ResultActions actions = mockMvc.perform(
Expand All @@ -509,7 +509,7 @@ void givenPortfolioLessThan1SizePortfolioUrl_whenUpdateProfile_thenReturn400() t
void givenPortfolioGreaterThan1000SizePortfolioUrl_whenUpdateProfile_thenReturn400() throws Exception {
// given
ProfileUpdateRequest request = createValidProfileUpdateRequest();
request.getPortfolios().get(0).setPortfolioUrl("a".repeat(1001));
request.getPortfolios().get(0).setPortfolioUrl("https://" + "a".repeat(993));

// when
ResultActions actions = mockMvc.perform(
Expand All @@ -527,6 +527,29 @@ void givenPortfolioGreaterThan1000SizePortfolioUrl_whenUpdateProfile_thenReturn4
.value(PORTFOLIO_URL_LENGTH_INVALID.getMessage()));
}

@Test
@DisplayName("포트폴리오에 포트폴리오 URL이 잘못된 포맷일시 프로필 업데이트를 하면 400을 반환한다.")
void givenPortfolioFormatPortfolioUrl_whenUpdateProfile_thenReturn400() throws Exception {
// given
ProfileUpdateRequest request = createValidProfileUpdateRequest();
request.getPortfolios().get(0).setPortfolioUrl("a".repeat(100));

// when
ResultActions actions = mockMvc.perform(
post("/api/v1/user/profile")
.content(objectMapper.writeValueAsString(request))
.contentType(APPLICATION_JSON)
);

// then
actions.andDo(print())
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.responseCode")
.value(PORTFOLIO_URL_FORMAT_INVALID.name()))
.andExpect(jsonPath("$.responseMessage")
.value(PORTFOLIO_URL_FORMAT_INVALID.getMessage()));
}

@Test
@DisplayName("포트폴리오에 잘못된 미디어 입력시 프로필 업데이트를 하면 400을 반환한다.")
void givenPortfolioFormatMedia_whenUpdateProfile_thenReturn400() throws Exception {
Expand Down Expand Up @@ -741,7 +764,7 @@ private EducationUpdateRequest createValidEducationUpdateRequest() {
private PortfolioUpdateRequest createValidPortfolioUpdateRequest() {
return PortfolioUpdateRequest.builder()
.portfolioName("깃허브")
.portfolioUrl("github.com/gabojait")
.portfolioUrl("https://github.com/gabojait")
.media(Media.LINK.toString())
.build();
}
Expand Down

0 comments on commit a0508ed

Please sign in to comment.