Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface UploadApi {
@Operation(summary = "이미지 파일을 업로드한다.", description = """
서버가 multipart 파일을 받아 S3에 업로드합니다.

- target 쿼리파라미터로 이미지 저장 대상 도메인을 지정합니다. (CLUB, BANK, COUNCIL, USER)
- target 쿼리파라미터로 이미지 저장 대상 도메인을 지정합니다. (CLUB, BANK, COUNCIL, USER, UNIVERSITY)
- 응답의 fileUrl을 기존 도메인 API의 imageUrl로 사용합니다.

## 에러
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum UploadTarget {
BANK("은행"),
COUNCIL("총학생회"),
USER("사용자"),
UNIVERSITY("대학교"),
;

private final String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,26 @@ void uploadImageSuccess() throws Exception {
assertThat(requestCaptor.getValue().contentType()).isEqualTo("image/png");
}

@Test
@DisplayName("대학교 이미지를 업로드하면 university 경로에 저장한다")
void uploadUniversityImageSuccess() throws Exception {
// given
byte[] pngBytes = createPngBytes(8, 8);
MockMultipartFile file = imageFile("university.png", "image/png", pngBytes);

// when
MvcResult result = uploadImage(file, UploadTarget.UNIVERSITY)
.andExpect(status().isOk())
.andReturn();

// then
String responseBody = result.getResponse().getContentAsString();
String key = JsonPath.read(responseBody, "$.key");

assertThat(key).startsWith("test/university/");
assertThat(key).endsWith(".png");
}

@Test
@DisplayName("jpeg 이미지를 업로드하면 원본 형태로 저장한다")
void uploadJpegImageSuccess() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@ void uploadImageBuildsKeyWithoutPrefixWhenPrefixBlank() {
assertThat(response.key()).matches("bank/\\d{4}-\\d{2}-\\d{2}-[0-9a-f\\-]{36}\\.png");
}

@Test
@DisplayName("uploadImage는 UNIVERSITY target을 university 경로로 저장한다")
void uploadImageBuildsUniversityKeyPath() {
// given
MockMultipartFile file = new MockMultipartFile(
"file",
"university.png",
"image/png",
"png-data".getBytes(StandardCharsets.UTF_8)
);

// when
ImageUploadResponse response = uploadService.uploadImage(file, UploadTarget.UNIVERSITY);

// then
assertThat(response.key()).matches(
"konect/university/\\d{4}-\\d{2}-\\d{2}-[0-9a-f\\-]{36}\\.png"
);
}

@Test
@DisplayName("uploadImage는 leading slash prefix를 제거하고 trailing slash를 보정한다")
void uploadImageNormalizesPrefixWithLeadingSlash() {
Expand Down
Loading