From d6a72ab3a2182a8b438baf9e7917b25fb6168a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=85=B8=EA=B2=BD=EB=AF=BC?= Date: Fri, 24 Feb 2023 15:59:50 +0900 Subject: [PATCH 1/4] =?UTF-8?q?test=20:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80=20(#416)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test : 이벤트 상태변경 테스트 코드 작성 * refactor : 이벤트 정렬 기준 startAt 으로 변경 --- .../domain/domains/event/domain/Event.java | 16 +- .../repository/EventCustomRepositoryImpl.java | 8 +- .../domain/domains/event/EventTest.java | 156 ++++++++++++++++++ 3 files changed, 167 insertions(+), 13 deletions(-) create mode 100644 DuDoong-Domain/src/test/java/band/gosrock/domain/domains/event/EventTest.java diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/event/domain/Event.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/event/domain/Event.java index 37052a7d..9a0770da 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/event/domain/Event.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/event/domain/Event.java @@ -43,16 +43,12 @@ public class Event extends BaseTimeEntity { private EventStatus status = PREPARING; public LocalDateTime getStartAt() { - if (this.eventBasic == null) { - return null; - } + if (this.eventBasic == null) return null; return this.getEventBasic().getStartAt(); } public LocalDateTime getEndAt() { - if (this.eventBasic == null) { - return null; - } + if (this.eventBasic == null) return null; return this.getEventBasic().endAt(); } @@ -100,15 +96,11 @@ public void validateOpenStatus() { } public void validateStatusOpen() { - if (status != OPEN) { - throw EventNotOpenException.EXCEPTION; - } + if (status != OPEN) throw EventNotOpenException.EXCEPTION; } public void validateTicketingTime() { - if (!isTimeBeforeStartAt()) { - throw EventTicketingTimeIsPassedException.EXCEPTION; - } + if (!isTimeBeforeStartAt()) throw EventTicketingTimeIsPassedException.EXCEPTION; } public Boolean isRefundDateNotPassed() { diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/event/repository/EventCustomRepositoryImpl.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/event/repository/EventCustomRepositoryImpl.java index 2fb183a0..dffd718a 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/event/repository/EventCustomRepositoryImpl.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/event/repository/EventCustomRepositoryImpl.java @@ -6,8 +6,10 @@ import band.gosrock.domain.common.util.SliceUtil; import band.gosrock.domain.domains.event.domain.Event; import band.gosrock.domain.domains.event.domain.EventStatus; +import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; +import java.time.LocalDateTime; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; @@ -37,7 +39,7 @@ public Slice querySliceEventsByStatus(EventStatus status, Pageable pageab queryFactory .selectFrom(event) .where(eqStatusOpen()) - .orderBy(event.id.desc()) + .orderBy(startAtAsc()) .offset(pageable.getOffset()) .limit(pageable.getPageSize() + 1) .fetch(); @@ -68,4 +70,8 @@ private BooleanExpression eqStatusOpen() { private BooleanExpression nameContains(String keyword) { return keyword == null ? null : event.eventBasic.name.containsIgnoreCase(keyword); } + + private OrderSpecifier startAtAsc() { + return event.eventBasic.startAt.desc(); + } } diff --git a/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/event/EventTest.java b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/event/EventTest.java new file mode 100644 index 00000000..bead58be --- /dev/null +++ b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/event/EventTest.java @@ -0,0 +1,156 @@ +package band.gosrock.domain.domains.event; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.when; + +import band.gosrock.domain.domains.event.domain.Event; +import band.gosrock.domain.domains.event.domain.EventBasic; +import band.gosrock.domain.domains.event.domain.EventStatus; +import band.gosrock.domain.domains.event.exception.*; +import java.time.LocalDateTime; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.test.util.ReflectionTestUtils; + +@ExtendWith(MockitoExtension.class) +public class EventTest { + + @Mock EventBasic eventBasic; + + Event event; + + final LocalDateTime startAt = LocalDateTime.of(2022, 2, 15, 15, 0); + final Long runTime = 90L; + + @BeforeEach + void setup() { + event = Event.builder().build(); + } + + @Test + void startAt_가져오기_테스트() { + // given + LocalDateTime expectedStartAt = startAt; + // when + when(eventBasic.getStartAt()).thenReturn(expectedStartAt); + event.setEventBasic(eventBasic); + LocalDateTime actualStartAt = event.getStartAt(); + // then + assertEquals(expectedStartAt, actualStartAt); + } + + @Test + void eventBasic_null_이면_endAt도_반드시_null() { + // Given + event.setEventBasic(null); + // When + final LocalDateTime endAt = event.getEndAt(); + // Then + assertNull(endAt); + } + + @Test + void endAt_가져오기_테스트() { + // given + final EventBasic eventBasic = + EventBasic.builder().startAt(startAt).runTime(runTime).build(); + event.setEventBasic(eventBasic); + // when + final LocalDateTime expectedEndAt = startAt.plusMinutes(runTime); + final LocalDateTime actualEndAt = event.getEndAt(); + // then + assertEquals(expectedEndAt, actualEndAt); + } + + // @Test + // public void eventBasic_중복수정은_불가능하다() { + // // given + // // reflection 으로 updated 에 true 강제 주입 + // ReflectionTestUtils.setField(event, "isUpdated", true); + // // then + // assertThrows(CannotModifyEventBasicException.class, () -> + // event.setEventBasic(eventBasic)); + // } + + @Test + public void eventBasic_업데이트_테스트() { + // given + EventBasic eventBasic = + EventBasic.builder().name("test event").startAt(startAt).runTime(runTime).build(); + // when + event.setEventBasic(eventBasic); + // then + assertNotNull(event.getEventBasic()); + assertEquals(eventBasic, event.getEventBasic()); + } + + @Test + void 이벤트_정산중으로_상태변경_테스트() { + // given + final EventStatus originalStatus = event.getStatus(); + final EventStatus expectedStatus = EventStatus.CALCULATING; + // when + event.calculate(); + // then + assertEquals(expectedStatus, event.getStatus()); + assertNotEquals(originalStatus, expectedStatus); + assertThrows(AlreadyCalculatingStatusException.class, () -> event.calculate()); + } + + @Test + void 이벤트_종료로_상태변경_테스트() { + // given + final EventStatus originalStatus = event.getStatus(); + final EventStatus expectedStatus = EventStatus.CLOSED; + // when + event.close(); + // then + assertEquals(expectedStatus, event.getStatus()); + assertNotEquals(originalStatus, expectedStatus); + assertThrows(AlreadyCloseStatusException.class, () -> event.close()); + } + + @Test + void 이벤트_오픈으로_상태변경_테스트() { + // given + final EventStatus originalStatus = event.getStatus(); + final EventStatus expectedStatus = EventStatus.OPEN; + // when + event.open(); + // then + assertEquals(expectedStatus, event.getStatus()); + assertNotEquals(originalStatus, expectedStatus); + assertThrows(AlreadyOpenStatusException.class, () -> event.open()); + } + + @Test + void 이벤트_준비중으로_상태변경_테스트() { + // given + // reflection + ReflectionTestUtils.setField(event, "status", EventStatus.OPEN); + final EventStatus originalStatus = event.getStatus(); + final EventStatus expectedStatus = EventStatus.PREPARING; + // when + event.prepare(); + // then + assertEquals(expectedStatus, event.getStatus()); + assertNotEquals(originalStatus, expectedStatus); + assertThrows(AlreadyPreparingStatusException.class, () -> event.prepare()); + } + + @Test + void 이벤트_삭제_상태변경_테스트() { + // given + final EventStatus originalStatus = event.getStatus(); + final EventStatus expectedStatus = EventStatus.DELETED; + // when + event.deleteSoft(); + // then + assertEquals(expectedStatus, event.getStatus()); + assertNotEquals(originalStatus, expectedStatus); + assertThrows(AlreadyDeletedStatusException.class, () -> event.deleteSoft()); + } +} From d60d3f2900ff73c561036f079d45ca7dbe136608 Mon Sep 17 00:00:00 2001 From: Minjoon Kim <59060780+sanbonai06@users.noreply.github.com> Date: Sat, 25 Feb 2023 01:28:39 +0900 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20=EB=B0=9C=EA=B8=89=20=ED=8B=B0?= =?UTF-8?q?=EC=BC=93=20=EC=9E=85=EC=9E=A5=20=EC=B2=98=EB=A6=AC=20uuid?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95=20(#422)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 발급 티켓 입장 처리 uuid로 수정 * refactor: 티켓 정보 가져오기 API uuid로 수정 --- .../controller/AdminIssuedTicketController.java | 6 +++--- .../controller/IssuedTicketController.java | 6 +++--- .../api/issuedTicket/mapper/IssuedTicketMapper.java | 4 ++-- .../service/EntranceIssuedTicketUseCase.java | 4 ++-- .../issuedTicket/service/ReadIssuedTicketUseCase.java | 6 +++--- .../issuedTicket/adaptor/IssuedTicketAdaptor.java | 10 ++++++++-- .../repository/IssuedTicketRepository.java | 2 ++ .../service/IssuedTicketDomainService.java | 4 ++-- .../service/IssuedTicketDomainServiceTest.java | 4 ++-- 9 files changed, 27 insertions(+), 19 deletions(-) diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/controller/AdminIssuedTicketController.java b/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/controller/AdminIssuedTicketController.java index c7f631f7..a0057e90 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/controller/AdminIssuedTicketController.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/controller/AdminIssuedTicketController.java @@ -40,9 +40,9 @@ public PageResponse getIssuedTickets( } @Operation(summary = "[어드민 기능] 발급 티켓 입장 처리 API 입니다.") - @PatchMapping(value = "/{issuedTicketId}") + @PatchMapping(value = "/{uuid}") public IssuedTicketInfoVo patchIssuedTicketStatus( - @PathVariable Long eventId, @PathVariable Long issuedTicketId) { - return entranceIssuedTicketUseCase.execute(eventId, issuedTicketId); + @PathVariable Long eventId, @PathVariable String uuid) { + return entranceIssuedTicketUseCase.execute(eventId, uuid); } } diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/controller/IssuedTicketController.java b/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/controller/IssuedTicketController.java index 3a29afd0..45b47df0 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/controller/IssuedTicketController.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/controller/IssuedTicketController.java @@ -22,8 +22,8 @@ public class IssuedTicketController { private final ReadIssuedTicketUseCase readIssuedTicketUseCase; @Operation(summary = "발급 티켓 가져오기 API 입니다.") - @GetMapping(value = "/{issuedTicketId}", produces = "application/json; charset=utf-8") - public RetrieveIssuedTicketDetailResponse getIssuedTicket(@PathVariable Long issuedTicketId) { - return readIssuedTicketUseCase.execute(issuedTicketId); + @GetMapping(value = "/{uuid}", produces = "application/json; charset=utf-8") + public RetrieveIssuedTicketDetailResponse getIssuedTicket(@PathVariable String uuid) { + return readIssuedTicketUseCase.execute(uuid); } } diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/mapper/IssuedTicketMapper.java b/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/mapper/IssuedTicketMapper.java index 1755a599..ef329903 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/mapper/IssuedTicketMapper.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/mapper/IssuedTicketMapper.java @@ -64,8 +64,8 @@ private static User getUser(List users, Long userId) { @Transactional(readOnly = true) public RetrieveIssuedTicketDetailResponse toIssuedTicketDetailResponse( - Long currentUserId, Long issuedTicketId) { - IssuedTicket issuedTicket = issuedTicketAdaptor.findForUser(currentUserId, issuedTicketId); + Long currentUserId, String uuid) { + IssuedTicket issuedTicket = issuedTicketAdaptor.findForUser(currentUserId, uuid); Event event = eventAdaptor.findById(issuedTicket.getEventId()); return RetrieveIssuedTicketDetailResponse.of(issuedTicket, event); } diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/service/EntranceIssuedTicketUseCase.java b/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/service/EntranceIssuedTicketUseCase.java index 78be49ed..4642f08e 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/service/EntranceIssuedTicketUseCase.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/service/EntranceIssuedTicketUseCase.java @@ -18,7 +18,7 @@ public class EntranceIssuedTicketUseCase { @Transactional @HostRolesAllowed(role = MANAGER, findHostFrom = EVENT_ID) - public IssuedTicketInfoVo execute(Long eventId, Long issuedTicketId) { - return issuedTicketDomainService.processingEntranceIssuedTicket(eventId, issuedTicketId); + public IssuedTicketInfoVo execute(Long eventId, String uuid) { + return issuedTicketDomainService.processingEntranceIssuedTicket(eventId, uuid); } } diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/service/ReadIssuedTicketUseCase.java b/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/service/ReadIssuedTicketUseCase.java index 7ae97dea..524347c0 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/service/ReadIssuedTicketUseCase.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/issuedTicket/service/ReadIssuedTicketUseCase.java @@ -16,11 +16,11 @@ public class ReadIssuedTicketUseCase { /** * 발급 티켓 상세 정보 API * - * @param issuedTicketId 발급 티켓 id + * @param uuid 발급 티켓 id * @return RetrieveIssuedTicketDetailResponse */ - public RetrieveIssuedTicketDetailResponse execute(Long issuedTicketId) { + public RetrieveIssuedTicketDetailResponse execute(String uuid) { Long currentUserId = SecurityUtils.getCurrentUserId(); - return issuedTicketMapper.toIssuedTicketDetailResponse(currentUserId, issuedTicketId); + return issuedTicketMapper.toIssuedTicketDetailResponse(currentUserId, uuid); } } diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/adaptor/IssuedTicketAdaptor.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/adaptor/IssuedTicketAdaptor.java index cf3646ec..ccdf6397 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/adaptor/IssuedTicketAdaptor.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/adaptor/IssuedTicketAdaptor.java @@ -28,10 +28,10 @@ public void saveAll(List issuedTickets) { issuedTicketRepository.saveAll(issuedTickets); } - public IssuedTicket findForUser(Long currentUserId, Long issuedTicketId) { + public IssuedTicket findForUser(Long currentUserId, String uuid) { IssuedTicket issuedTicket = issuedTicketRepository - .find(issuedTicketId) + .findByUuid(uuid) .orElseThrow(() -> IssuedTicketNotFoundException.EXCEPTION); if (!Objects.equals(issuedTicket.getUserInfo().getUserId(), currentUserId)) { throw IssuedTicketUserNotMatchedException.EXCEPTION; @@ -80,4 +80,10 @@ public IssuedTicket queryByIssuedTicketNo(String issuedTicketNo) { .findByIssuedTicketNo(issuedTicketNo) .orElseThrow(() -> IssuedTicketNotFoundException.EXCEPTION); } + + public IssuedTicket queryByIssuedTicketUuid(String uuid) { + return issuedTicketRepository + .findByUuid(uuid) + .orElseThrow(() -> IssuedTicketNotFoundException.EXCEPTION); + } } diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/repository/IssuedTicketRepository.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/repository/IssuedTicketRepository.java index 47ecc22e..17ec01da 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/repository/IssuedTicketRepository.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/repository/IssuedTicketRepository.java @@ -15,4 +15,6 @@ public interface IssuedTicketRepository Optional findByIssuedTicketNo(String issuedTicketNo); Boolean existsByEventId(Long eventId); + + Optional findByUuid(String uuid); } diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/service/IssuedTicketDomainService.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/service/IssuedTicketDomainService.java index b8dc8811..88c38261 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/service/IssuedTicketDomainService.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/issuedTicket/service/IssuedTicketDomainService.java @@ -64,8 +64,8 @@ public void doneOrderEventAfterRollBackWithdrawIssuedTickets(Long itemId, String /* 발급 티켓 입장 처리 로직 */ - public IssuedTicketInfoVo processingEntranceIssuedTicket(Long eventId, Long issuedTicketId) { - IssuedTicket issuedTicket = issuedTicketAdaptor.queryIssuedTicket(issuedTicketId); + public IssuedTicketInfoVo processingEntranceIssuedTicket(Long eventId, String uuid) { + IssuedTicket issuedTicket = issuedTicketAdaptor.queryByIssuedTicketUuid(uuid); issuedTicketValidator.validIssuedTicketEventIdEqualEvent(issuedTicket, eventId); issuedTicket.entrance(); return issuedTicket.toIssuedTicketInfoVo(); diff --git a/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/issuedTicket/service/IssuedTicketDomainServiceTest.java b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/issuedTicket/service/IssuedTicketDomainServiceTest.java index fa83e2b2..f829c2e1 100644 --- a/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/issuedTicket/service/IssuedTicketDomainServiceTest.java +++ b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/issuedTicket/service/IssuedTicketDomainServiceTest.java @@ -208,12 +208,12 @@ void setUp() { @Test public void 발급_티켓_입장_처리_로직_정상_작동_테스트() { // given - given(issuedTicketAdaptor.queryIssuedTicket(any())).willReturn(issuedTicket1); + given(issuedTicketAdaptor.queryByIssuedTicketUuid(any())).willReturn(issuedTicket1); given(issuedTicketOptionAnswer.getAdditionalPrice()).willReturn(w3000); given(issuedTicketOptionAnswer1.getAdditionalPrice()).willReturn(w3000); // when - issuedTicketDomainService.processingEntranceIssuedTicket(1L, 1L); + issuedTicketDomainService.processingEntranceIssuedTicket(1L, "UUID"); // then assertEquals(issuedTicket1.getIssuedTicketStatus(), IssuedTicketStatus.ENTRANCE_COMPLETED); From cc01b221fae8080dfb53be44eb6e6d5ba71f920a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=B1=84=EB=A6=B0=20=28Bryn=29?= <67696767+cofls6581@users.noreply.github.com> Date: Sat, 25 Feb 2023 02:03:19 +0900 Subject: [PATCH 3/4] =?UTF-8?q?test=20:=20=EC=BF=A0=ED=8F=B0=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test : 쿠폰 도메인 테스트 코드 작성 * style : spotless 적용 * feat : @EnumClass 적용 --- .../domains/coupon/domain/ApplyTarget.java | 2 + .../domains/coupon/domain/DiscountType.java | 2 + .../coupon/domain/CouponCampaignTest.java | 61 ++++++++ .../coupon/domain/CouponStockInfoTest.java | 46 ++++++ .../coupon/domain/IssuedCouponTest.java | 136 +++++++++++++++++- 5 files changed, 240 insertions(+), 7 deletions(-) create mode 100644 DuDoong-Domain/src/test/java/band/gosrock/domain/domains/coupon/domain/CouponCampaignTest.java create mode 100644 DuDoong-Domain/src/test/java/band/gosrock/domain/domains/coupon/domain/CouponStockInfoTest.java diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/coupon/domain/ApplyTarget.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/coupon/domain/ApplyTarget.java index caa2fa54..6ad51264 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/coupon/domain/ApplyTarget.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/coupon/domain/ApplyTarget.java @@ -1,11 +1,13 @@ package band.gosrock.domain.domains.coupon.domain; +import band.gosrock.common.annotation.EnumClass; import lombok.AllArgsConstructor; import lombok.Getter; @Getter @AllArgsConstructor +@EnumClass public enum ApplyTarget { ALL("ALL"), SUB("SUB"); diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/coupon/domain/DiscountType.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/coupon/domain/DiscountType.java index 6430593c..428f061b 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/coupon/domain/DiscountType.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/coupon/domain/DiscountType.java @@ -1,11 +1,13 @@ package band.gosrock.domain.domains.coupon.domain; +import band.gosrock.common.annotation.EnumClass; import lombok.AllArgsConstructor; import lombok.Getter; @Getter @AllArgsConstructor +@EnumClass public enum DiscountType { // 정액 할인 AMOUNT("AMOUNT"), diff --git a/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/coupon/domain/CouponCampaignTest.java b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/coupon/domain/CouponCampaignTest.java new file mode 100644 index 00000000..bcab38a0 --- /dev/null +++ b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/coupon/domain/CouponCampaignTest.java @@ -0,0 +1,61 @@ +package band.gosrock.domain.domains.coupon.domain; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import band.gosrock.domain.common.vo.DateTimePeriod; +import band.gosrock.domain.domains.coupon.exception.NotIssuingCouponPeriodException; +import band.gosrock.domain.domains.coupon.exception.WrongDiscountAmountException; +import java.time.LocalDateTime; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class CouponCampaignTest { + CouponCampaign couponCampaign; + + @BeforeEach + void setUp() { + LocalDateTime nowTime = LocalDateTime.now(); + DateTimePeriod dateTimePeriod = + new DateTimePeriod(nowTime.minusDays(2), nowTime.minusDays(1)); + + CouponStockInfo couponStockInfo = + CouponStockInfo.builder().issuedAmount(3L).remainingAmount(1L).build(); + couponCampaign = + CouponCampaign.builder() + .discountType(DiscountType.PERCENTAGE) + .couponStockInfo(couponStockInfo) + .dateTimePeriod(dateTimePeriod) + .build(); + } + + @Test + public void testValidatePercentageAmount() { + assertThrows( + WrongDiscountAmountException.class, + () -> { + couponCampaign.validatePercentageAmount(DiscountType.PERCENTAGE, 101L); + }); + } + + @Test + public void testDecreaseCouponStock() { + // given + // when + couponCampaign.decreaseCouponStock(); + // then + assertEquals(couponCampaign.getCouponStockInfo().getRemainingAmount(), 0L); + } + + @Test + public void testValidateIssuePeriod() { + assertThrows( + NotIssuingCouponPeriodException.class, + () -> { + couponCampaign.validateIssuePeriod(); + }); + } +} diff --git a/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/coupon/domain/CouponStockInfoTest.java b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/coupon/domain/CouponStockInfoTest.java new file mode 100644 index 00000000..4b8397a3 --- /dev/null +++ b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/coupon/domain/CouponStockInfoTest.java @@ -0,0 +1,46 @@ +package band.gosrock.domain.domains.coupon.domain; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import band.gosrock.domain.domains.coupon.exception.NoCouponStockLeftException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class CouponStockInfoTest { + + CouponStockInfo zeroCouponStockInfo; + CouponStockInfo leftCouponStockInfo; + + @BeforeEach + void setUp() { + zeroCouponStockInfo = + CouponStockInfo.builder().remainingAmount(0L).issuedAmount(3L).build(); + leftCouponStockInfo = + CouponStockInfo.builder().remainingAmount(1L).issuedAmount(3L).build(); + } + + @Test + public void 쿠폰_남은_재고_없음() { + // given + zeroCouponStockInfo = + CouponStockInfo.builder().remainingAmount(0L).issuedAmount(3L).build(); + // when, then + assertThrows( + NoCouponStockLeftException.class, () -> zeroCouponStockInfo.decreaseCouponStock()); + } + + @Test + public void 쿠폰_남은_재고_있음() { + // given + leftCouponStockInfo = + CouponStockInfo.builder().remainingAmount(1L).issuedAmount(3L).build(); + // when + leftCouponStockInfo.decreaseCouponStock(); + // then + assertEquals(leftCouponStockInfo.getRemainingAmount(), 0L); + } +} diff --git a/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/coupon/domain/IssuedCouponTest.java b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/coupon/domain/IssuedCouponTest.java index 15f961d0..04d72b83 100644 --- a/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/coupon/domain/IssuedCouponTest.java +++ b/DuDoong-Domain/src/test/java/band/gosrock/domain/domains/coupon/domain/IssuedCouponTest.java @@ -1,36 +1,51 @@ package band.gosrock.domain.domains.coupon.domain; import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.BDDMockito.given; -import band.gosrock.domain.domains.coupon.exception.AlreadyUsedCouponException; -import band.gosrock.domain.domains.coupon.exception.NotMyCouponException; +import band.gosrock.domain.common.vo.Money; +import band.gosrock.domain.domains.coupon.exception.*; +import java.time.LocalDateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) class IssuedCouponTest { static Long userId = 1L; - + static LocalDateTime createdAt = LocalDateTime.now().minusDays(5); + static Long validTerm = 7L; + static Long discountAmount = 10000L; + static Long minimumCost = 50000L; + static Long discountPercentage = 30L; IssuedCoupon issuedCoupon; + @Mock CouponCampaign couponCampaign; @BeforeEach void setUp() { - issuedCoupon = IssuedCoupon.builder().userId(userId).build(); + issuedCoupon = IssuedCoupon.builder().userId(userId).couponCampaign(couponCampaign).build(); } @Test void 사용가능한_쿠폰_상태_확인() { - // given - // when - // 이미 사용한 상태라면? + // 이미 사용한 상태 쿠폰 사용 issuedCoupon.use(); // then assertThrows(AlreadyUsedCouponException.class, () -> issuedCoupon.use()); } + @Test + public void use_usageStatusFalse_setUsageStatusToTrue() { + // 사용 안한 쿠폰 사용 + // when + issuedCoupon.use(); + // then + assertTrue(issuedCoupon.getUsageStatus()); + } + @Test void 내쿠폰_확인() { // given @@ -39,4 +54,111 @@ void setUp() { // assertThrows(NotMyCouponException.class, () -> issuedCoupon.validMine(2L)); } + + @Test + public void validMine_validUserId_noExceptionThrown() { + // when + issuedCoupon.validMine(1L); + // then + assertEquals(issuedCoupon.getUserId(), 1L); + } + + // @Test + // void testIsAvailableTerm() { + // //given + // given(couponCampaign.getValidTerm()).willReturn(validTerm); + // //LocalDateTime localDateTime = Mockito.mock(new + // TypeToken(){}.getCreatedAt()); + // given(issuedCoupon.getCreatedAt()).willReturn(createdAt); + // //when + // Boolean result = issuedCoupon.isAvailableTerm(); + // //then + // assertTrue(result); + // } + // + // @Test + // public void testCalculateValidTerm() { + // // given + // given(couponCampaign.getValidTerm()).willReturn(validTerm); + // given(issuedCoupon.getCreatedAt()).willReturn(createdAt); + // // when + // LocalDateTime result = issuedCoupon.calculateValidTerm(); + // // then + // assertEquals(result, createdAt.plusDays(validTerm)); + // } + + @Test + void testGetDiscountAmount_withAmountDiscountType() { + given(couponCampaign.getDiscountType()).willReturn(DiscountType.AMOUNT); + given(couponCampaign.getDiscountAmount()).willReturn(discountAmount); + given(couponCampaign.getMinimumCost()).willReturn(minimumCost); + + Money supplyAmount = Money.wons(60000L); + Money expectedDiscountAmount = Money.wons(10000L); + Money actualDiscountAmount = issuedCoupon.getDiscountAmount(supplyAmount); + + assertEquals(expectedDiscountAmount, actualDiscountAmount); + } + + @Test + void testGetDiscountAmount_withPercentageDiscountType() { + given(couponCampaign.getDiscountType()).willReturn(DiscountType.PERCENTAGE); + given(couponCampaign.getDiscountAmount()).willReturn(discountPercentage); + given(couponCampaign.getMinimumCost()).willReturn(minimumCost); + + Money supplyAmount = Money.wons(60000L); + Money expectedDiscountAmount = Money.wons(18000L); + Money actualDiscountAmount = issuedCoupon.getDiscountAmount(supplyAmount); + + assertEquals(expectedDiscountAmount, actualDiscountAmount); + } + + @Test + void testCheckSupplyAmount_withLessThanDiscount() { + Money supply = Money.wons(5000L); + Long discount = discountAmount; + Long minimum = minimumCost; + + assertThrows( + SupplyLessThenDiscountException.class, + () -> issuedCoupon.checkSupplyAmount(supply, discount, minimum)); + } + + @Test + void testCheckSupplyAmount_withLessThanMinimum() { + Money supply = Money.wons(40000L); + Long discount = discountAmount; + Long minimum = minimumCost; + + assertThrows( + SupplyLessThenMinimumException.class, + () -> issuedCoupon.checkSupplyAmount(supply, discount, minimum)); + } + + @Test + void testCheckSupplyAmount_withValidSupply() { + Money supply = Money.wons(60000L); + Long discount = discountAmount; + Long minimum = minimumCost; + + Money expectedDiscountAmount = Money.wons(10000L); + Money actualDiscountAmount = issuedCoupon.checkSupplyAmount(supply, discount, minimum); + + assertEquals(expectedDiscountAmount, actualDiscountAmount); + } + + @Test + public void recovery_usageStatusFalse() { + // 쿠폰 사용 안한 상태 + assertThrows(AlreadyRecoveredCouponException.class, () -> issuedCoupon.recovery()); + } + + @Test + public void recovery_usageStatusTrue() { + // 쿠폰 이미 사용한 상태 + issuedCoupon.use(); + issuedCoupon.recovery(); + // then + assertFalse(issuedCoupon.getUsageStatus()); + } } From 60ea4de2691027318ddfb7128bab4f117ca9a595 Mon Sep 17 00:00:00 2001 From: Chan Jin Date: Sat, 25 Feb 2023 02:06:54 +0900 Subject: [PATCH 4/4] =?UTF-8?q?refactor=20:=20register=20email=20contents?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20(#423)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor : 회원가입 메일 내용 리팩터링 * refactor : 회원가입 폼 수정 * fix : div 닫기 * refactor : 푸터 최종 수정 --- .../resources/templates/fragments/footer.html | 218 ++++++++++++------ .../src/main/resources/templates/signUp.html | 119 +++++++--- 2 files changed, 234 insertions(+), 103 deletions(-) diff --git a/DuDoong-Infrastructure/src/main/resources/templates/fragments/footer.html b/DuDoong-Infrastructure/src/main/resources/templates/fragments/footer.html index c3146c55..b16b7729 100644 --- a/DuDoong-Infrastructure/src/main/resources/templates/fragments/footer.html +++ b/DuDoong-Infrastructure/src/main/resources/templates/fragments/footer.html @@ -13,77 +13,124 @@ th:fragment="footer" style=" overflow: hidden; - padding: 0px; margin-top: 20px; - background: #6f6f6f; + padding-top: 20px; + padding-right: 15px; + padding-left: 15px; + background: #E3E4E8; border: 0; font-family: AppleSDGothic, apple sd gothic neo, noto sans korean, noto sans korean regular, noto sans cjk kr, noto sans cjk, nanum gothic, malgun gothic, dotum, arial, helvetica, MS Gothic, sans-serif !important; " > -
- -
+ - + + + + + + +
+
+
+ +
+
+ +
+ + target="_blank" + title="카카오톡 채널" + > + + +
+ + + + + + + + diff --git a/DuDoong-Infrastructure/src/main/resources/templates/signUp.html b/DuDoong-Infrastructure/src/main/resources/templates/signUp.html index feda4e24..d89ad19f 100644 --- a/DuDoong-Infrastructure/src/main/resources/templates/signUp.html +++ b/DuDoong-Infrastructure/src/main/resources/templates/signUp.html @@ -60,9 +60,38 @@
divider
- +
+ + + + + + +
+
+
+
@@ -86,6 +115,7 @@ -webkit-text-size-adjust: 100%; table-layout: fixed; margin-top: 15px; + margin-bottom: 15px; " width="100%" > @@ -125,7 +155,7 @@ style="display: inline" rel="noreferrer noopener" > 본인의 속한 그룹을 내가 속한 그룹을  호스트 - 로 만들어 보세요!
@@ -189,7 +218,7 @@ style="display: inline" rel="noreferrer noopener" > 이벤트 - 를 열어 공연을 홍보 할 수 있어요  @@ -282,7 +311,7 @@ style="display: inline" rel="noreferrer noopener" > 티켓 - 을 만들어 판매하세요! 
@@ -345,7 +373,7 @@ style="display: inline" rel="noreferrer noopener" >
- 예약한 사람의 명단을 손쉽게 조회할 수 있어요 - -
+ 옵션을 만들어 설문을 받아보세요 
@@ -397,6 +424,7 @@ -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; table-layout: fixed; + " width="100%" > @@ -436,7 +464,7 @@ style="display: inline" rel="noreferrer noopener" >
- 옵션 - 을 만들어 설문을 받아보세요 
+ 예약자 명단을 손쉽게 조회할 수 있어요 + +
+
QR코드QR티켓 로 손쉽게 티켓을 체크해보세요으로 입장을 체크해요
@@ -542,13 +570,30 @@
divider
-
+
+ +
+ +
+ 지금 바로! 이벤트를 만들어 관객들을 모집하세요! 지금 바로 공연을 만들고 관객들을 모집해보세요!
@@ -557,6 +602,8 @@ > button
+
+