diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ErrorCode.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ErrorCode.java index 3ebf85fa..80eaa3d8 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ErrorCode.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/exception/ErrorCode.java @@ -4,56 +4,36 @@ import org.springframework.http.HttpStatus; @Getter -// TODO: code 수정 필요 public enum ErrorCode { - FAIL_SOCIAL_DATA_GET(HttpStatus.UNAUTHORIZED.value(), "-20400"), - - FAIL_ACCESS_TOKEN_GET(HttpStatus.UNAUTHORIZED.value(), "-20400"), - - AUTHENTICATION_EMPTY(HttpStatus.UNAUTHORIZED.value(), "-20400"), - - JWT_TOKEN_EXCEPTION(HttpStatus.UNAUTHORIZED.value(), "-20400"), - - INVALID_AUTHORIZATION_HEADER(HttpStatus.BAD_REQUEST.value(), "-20400"), - - SECURITY_FILTER_AUTHORIZATION_REQUIRED(HttpStatus.FORBIDDEN.value(), "-20400"), - - SECURITY_FILTER_FORBIDDEN_ACCESS(HttpStatus.BAD_REQUEST.value(), "-20400"), - - NOT_LIKEABLE_MEMBER_TYPE(HttpStatus.BAD_REQUEST.value(), "-20400"), - - ADDITIONAL_INFO_ILLEGAL_ACCESS(HttpStatus.UNAUTHORIZED.value(), "-20400"), - - LOGIN_FAILED(HttpStatus.UNAUTHORIZED.value(), "-20400"), - - EMAIL_ALREADY_EXISTS(HttpStatus.CONFLICT.value(), "-10400"), - - CURRENT_LOCATION_EMPTY(HttpStatus.BAD_REQUEST.value(), "-20400"), - - INVALID_IMAGE_DOMAIN(HttpStatus.BAD_REQUEST.value(), "-20400"), - - FAIL_TO_DELETE_IMAGE(HttpStatus.CONFLICT.value(), "-20400"), - - FAIL_TO_UPLOAD_IMAGE(HttpStatus.CONFLICT.value(), "-20400"), - - FAIL_TO_PAY(HttpStatus.CONFLICT.value(), "-20400"), - - FAIL_TO_READ_IMAGE(HttpStatus.CONFLICT.value(), "-20400"), - - RESERVATION_NOT_FOUND_FOR_REVIEW(HttpStatus.NOT_FOUND.value(), "14044"), - - NO_LEFT_SEAT(HttpStatus.BAD_REQUEST.value(), "-10400"), - - URL_PARSING_FAILED(HttpStatus.BAD_REQUEST.value(), "-20400"), - - INVALID_INPUT_VALUE(HttpStatus.BAD_REQUEST.value(), "-20400"), - - UNAUTHORIZED(HttpStatus.UNAUTHORIZED.value(), "-20400"), - - ENTITY_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "-10404"), - - UNEXPECTED(HttpStatus.BAD_REQUEST.value(), "-1"); + EMAIL_ALREADY_EXISTS(HttpStatus.CONFLICT.value(), "-40904"), + FAIL_TO_DELETE_IMAGE(HttpStatus.CONFLICT.value(), "-40903"), + FAIL_TO_UPLOAD_IMAGE(HttpStatus.CONFLICT.value(), "-40902"), + FAIL_TO_PAY(HttpStatus.CONFLICT.value(), "-40901"), + FAIL_TO_READ_IMAGE(HttpStatus.CONFLICT.value(), "-40900"), + + RESERVATION_NOT_FOUND_FOR_REVIEW(HttpStatus.NOT_FOUND.value(), "40401"), + ENTITY_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "-40400"), + + SECURITY_FILTER_AUTHORIZATION_REQUIRED(HttpStatus.FORBIDDEN.value(), "-40300"), + + FAIL_SOCIAL_DATA_GET(HttpStatus.UNAUTHORIZED.value(), "-40106"), + FAIL_ACCESS_TOKEN_GET(HttpStatus.UNAUTHORIZED.value(), "-40105"), + AUTHENTICATION_EMPTY(HttpStatus.UNAUTHORIZED.value(), "-40104"), + JWT_TOKEN_EXCEPTION(HttpStatus.UNAUTHORIZED.value(), "-40103"), + ADDITIONAL_INFO_ILLEGAL_ACCESS(HttpStatus.UNAUTHORIZED.value(), "-40102"), + LOGIN_FAILED(HttpStatus.UNAUTHORIZED.value(), "-40101"), + UNAUTHORIZED(HttpStatus.UNAUTHORIZED.value(), "-40100"), + + INVALID_AUTHORIZATION_HEADER(HttpStatus.BAD_REQUEST.value(), "-40008"), + SECURITY_FILTER_FORBIDDEN_ACCESS(HttpStatus.BAD_REQUEST.value(), "-40007"), + NOT_LIKEABLE_MEMBER_TYPE(HttpStatus.BAD_REQUEST.value(), "-40006"), + CURRENT_LOCATION_EMPTY(HttpStatus.BAD_REQUEST.value(), "-40005"), + INVALID_IMAGE_DOMAIN(HttpStatus.BAD_REQUEST.value(), "-40004"), + NO_LEFT_SEAT(HttpStatus.BAD_REQUEST.value(), "-40003"), + URL_PARSING_FAILED(HttpStatus.BAD_REQUEST.value(), "-40002"), + INVALID_INPUT_VALUE(HttpStatus.BAD_REQUEST.value(), "-40001"), + UNEXPECTED(HttpStatus.BAD_REQUEST.value(), "-40000"); private final Integer status; private final String code; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java index 72cc7420..87c554b0 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java @@ -13,12 +13,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; -import org.ktc2.cokaen.wouldyouin._common.vo.Area; -import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; -import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curation1; import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; -import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.EventSlice; import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.R.event1; import org.ktc2.cokaen.wouldyouin._global.testdata.EventData.R.updatedEvent1; import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; @@ -27,7 +22,6 @@ import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host1; import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; -import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventResponse; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventSliceResponse; import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; @@ -42,7 +36,6 @@ import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.data.domain.PageRequest; @ExtendWith(MockitoExtension.class) class EventServiceUnitTest { @@ -107,7 +100,8 @@ void getAllByFilterOrderByDistanceAsc() { // when EventSliceResponse responses = eventService.getAllByFilterOrderByDistanceAsc( - location, currentLocation, event1.title, event1.category, event1.area, event1.pageable, event1.lastId); + location, currentLocation, event1.title, event1.category, event1.area, event1.pageable, + event1.lastId); // then assertThat(responses).isEqualTo(EventData.event1.response.slice.get()); @@ -117,7 +111,8 @@ void getAllByFilterOrderByDistanceAsc() { @DisplayName("Host ID를 통해 해당하는 모든 이벤트를 반환한다.") void getAllByHostIdOrderByCreatedDateDesc() { // given - given(eventRepository.findAllByHostIdOrderByEventIdDesc(host1.id, event1.lastId, event1.pageable)) + given(eventRepository.findAllByHostIdOrderByEventIdDesc(host1.id, event1.lastId, + event1.pageable)) .willReturn(EventData.EventSlice.get()); EventImage eventImage1 = EventData.event1.entity.get().getImages().get(0); EventImage eventImage2 = EventData.event1.entity.get().getImages().get(1); @@ -127,7 +122,8 @@ void getAllByHostIdOrderByCreatedDateDesc() { given(eventImageService.getImageUrl(eventImage3)).willReturn(R.event3.url); // when - EventSliceResponse responses = eventService.getAllByHostIdOrderByCreatedDateDesc(host1.id, event1.pageable, event1.lastId); + EventSliceResponse responses = eventService.getAllByHostIdOrderByCreatedDateDesc(host1.id, + event1.pageable, event1.lastId); // then assertThat(responses).isEqualTo(EventData.event1.response.slice.get()); @@ -147,11 +143,13 @@ void getAllByCreatedDateDesc() { given(eventImageService.getImageUrl(eventImage3)).willReturn(R.event3.url); // when - EventSliceResponse responses = eventService.getAllByCreatedDateDesc(event1.pageable, event1.lastId); + EventSliceResponse responses = eventService.getAllByCreatedDateDesc(event1.pageable, + event1.lastId); // then assertThat(responses).isEqualTo(EventData.event1.response.slice.get()); } + @Test @DisplayName("EventCreateRequest를 통해 이벤트를 생성한다.") void create() { @@ -169,7 +167,8 @@ void create() { given(eventRepository.save(any(Event.class))).willReturn(EventData.event1.entity.get()); // when - EventResponse response = eventService.create(host1.memberIdentifier, EventData.event1.request.create.get()); + EventResponse response = eventService.create(host1.memberIdentifier, + EventData.event1.request.create.get()); // then assertThat(response).isEqualTo(EventData.event1.response.get()); @@ -179,10 +178,12 @@ void create() { @DisplayName("EventEditRequest를 통해 이벤트를 수정한다.") void update1() { // given - given(eventRepository.findById(event1.id)).willReturn(Optional.of(EventData.event1.entity.get())); + given(eventRepository.findById(event1.id)).willReturn( + Optional.of(EventData.event1.entity.get())); given(eventImageService.getById(R.event4.id)).willReturn(ImageData.event4.entity.get()); given(eventImageService.getById(R.event5.id)).willReturn(ImageData.event5.entity.get()); - given(eventImageService.createThumbnail(event4.name)).willReturn(updatedEvent1.thumbnailUrl); + given(eventImageService.createThumbnail(event4.name)).willReturn( + updatedEvent1.thumbnailUrl); EventImage eventImage4 = EventData.updatedEvent1.entity.get().getImages().get(0); EventImage eventImage5 = EventData.updatedEvent1.entity.get().getImages().get(1); given(eventImageService.getImageUrl(eventImage4)).willReturn(R.event4.url); @@ -193,7 +194,8 @@ void update1() { EventData.event1.request.edit1.get()); // then - then(eventImageService).should(times(3)).deleteImage(any(MemberIdentifier.class), any(Long.class)); + then(eventImageService).should(times(3)) + .deleteImage(any(MemberIdentifier.class), any(Long.class)); assertThat(response).isEqualTo(EventData.updatedEvent1.response.get()); } @@ -202,11 +204,13 @@ void update1() { void update2() { // given MemberIdentifier differentMember = new MemberIdentifier(100L, MemberType.host); - given(eventRepository.findById(event1.id)).willReturn(Optional.of(EventData.event1.entity.get())); + given(eventRepository.findById(event1.id)).willReturn( + Optional.of(EventData.event1.entity.get())); // when, then UnauthorizedException exception = assertThrows( - UnauthorizedException.class, () -> eventService.update(differentMember, event1.id, EventData.event1.request.edit1.get())); + UnauthorizedException.class, () -> eventService.update(differentMember, event1.id, + EventData.event1.request.edit1.get())); assertThat(exception.getMessage()).isEqualTo("해당 이벤트에 접근할 권한이 없습니다."); } @@ -214,13 +218,15 @@ void update2() { @DisplayName("이벤트 ID를 통해 해당하는 이벤트를 삭제한다.") void delete() { // given - given(eventRepository.findById(event1.id)).willReturn(Optional.of(EventData.event1.entity.get())); + given(eventRepository.findById(event1.id)).willReturn( + Optional.of(EventData.event1.entity.get())); // when eventService.delete(host1.memberIdentifier, event1.id); // then - then(eventImageService).should(times(3)).deleteImage(any(MemberIdentifier.class), any(Long.class)); + then(eventImageService).should(times(3)) + .deleteImage(any(MemberIdentifier.class), any(Long.class)); then(eventRepository).should(times(1)).deleteById(event1.id); } @@ -229,7 +235,8 @@ void delete() { void deleteByInvalidId() { // given MemberIdentifier differentMember = new MemberIdentifier(100L, MemberType.host); - given(eventRepository.findById(event1.id)).willReturn(Optional.of(EventData.event1.entity.get())); + given(eventRepository.findById(event1.id)).willReturn( + Optional.of(EventData.event1.entity.get())); // when, then UnauthorizedException exception = assertThrows(