diff --git a/src/main/java/com/moabam/api/application/bug/BugMapper.java b/src/main/java/com/moabam/api/application/bug/BugMapper.java index 0095b05a..0d439458 100644 --- a/src/main/java/com/moabam/api/application/bug/BugMapper.java +++ b/src/main/java/com/moabam/api/application/bug/BugMapper.java @@ -5,7 +5,6 @@ import com.moabam.api.domain.bug.BugHistory; import com.moabam.api.domain.bug.BugType; import com.moabam.api.dto.bug.BugResponse; -import com.moabam.api.dto.bug.TodayBugResponse; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -21,13 +20,6 @@ public static BugResponse toBugResponse(Bug bug) { .build(); } - public static TodayBugResponse toTodayBugResponse(int morningBug, int nightBug) { - return TodayBugResponse.builder() - .morningBug(morningBug) - .nightBug(nightBug) - .build(); - } - public static BugHistory toUseBugHistory(Long memberId, BugType bugType, int quantity) { return BugHistory.builder() .memberId(memberId) diff --git a/src/main/java/com/moabam/api/application/bug/BugService.java b/src/main/java/com/moabam/api/application/bug/BugService.java index c7de536b..dcb87c13 100644 --- a/src/main/java/com/moabam/api/application/bug/BugService.java +++ b/src/main/java/com/moabam/api/application/bug/BugService.java @@ -1,7 +1,5 @@ package com.moabam.api.application.bug; -import static com.moabam.api.domain.bug.BugActionType.*; -import static com.moabam.api.domain.bug.BugType.*; import static com.moabam.api.domain.product.ProductType.*; import static com.moabam.global.error.model.ErrorMessage.*; import static java.util.Objects.*; @@ -14,9 +12,6 @@ import com.moabam.api.application.member.MemberService; import com.moabam.api.application.payment.PaymentMapper; import com.moabam.api.application.product.ProductMapper; -import com.moabam.api.domain.bug.BugHistory; -import com.moabam.api.domain.bug.BugType; -import com.moabam.api.domain.bug.repository.BugHistorySearchRepository; import com.moabam.api.domain.coupon.Coupon; import com.moabam.api.domain.coupon.repository.CouponRepository; import com.moabam.api.domain.member.Member; @@ -25,11 +20,9 @@ import com.moabam.api.domain.product.Product; import com.moabam.api.domain.product.repository.ProductRepository; import com.moabam.api.dto.bug.BugResponse; -import com.moabam.api.dto.bug.TodayBugResponse; import com.moabam.api.dto.product.ProductsResponse; import com.moabam.api.dto.product.PurchaseProductRequest; import com.moabam.api.dto.product.PurchaseProductResponse; -import com.moabam.global.common.util.ClockHolder; import com.moabam.global.error.exception.NotFoundException; import lombok.RequiredArgsConstructor; @@ -40,11 +33,9 @@ public class BugService { private final MemberService memberService; - private final BugHistorySearchRepository bugHistorySearchRepository; private final ProductRepository productRepository; private final PaymentRepository paymentRepository; private final CouponRepository couponRepository; - private final ClockHolder clockHolder; public BugResponse getBug(Long memberId) { Member member = memberService.getById(memberId); @@ -52,14 +43,6 @@ public BugResponse getBug(Long memberId) { return BugMapper.toBugResponse(member.getBug()); } - public TodayBugResponse getTodayBug(Long memberId) { - List todayRewardBug = bugHistorySearchRepository.find(memberId, REWARD, clockHolder.times()); - int morningBug = calculateBugQuantity(todayRewardBug, MORNING); - int nightBug = calculateBugQuantity(todayRewardBug, NIGHT); - - return BugMapper.toTodayBugResponse(morningBug, nightBug); - } - public ProductsResponse getBugProducts() { List products = productRepository.findAllByType(BUG); @@ -69,7 +52,7 @@ public ProductsResponse getBugProducts() { @Transactional public PurchaseProductResponse purchaseBugProduct(Long memberId, Long productId, PurchaseProductRequest request) { Product product = getById(productId); - Payment payment = PaymentMapper.toEntity(memberId, product); + Payment payment = PaymentMapper.toPayment(memberId, product); if (!isNull(request.couponId())) { // TODO: (임시) CouponWallet 에 존재하는 할인 쿠폰인지 확인 @홍혁준 @@ -82,13 +65,6 @@ public PurchaseProductResponse purchaseBugProduct(Long memberId, Long productId, return ProductMapper.toPurchaseProductResponse(payment); } - private int calculateBugQuantity(List bugHistory, BugType bugType) { - return bugHistory.stream() - .filter(history -> bugType.equals(history.getBugType())) - .mapToInt(BugHistory::getQuantity) - .sum(); - } - private Product getById(Long productId) { return productRepository.findById(productId) .orElseThrow(() -> new NotFoundException(PRODUCT_NOT_FOUND)); diff --git a/src/main/java/com/moabam/api/application/payment/PaymentMapper.java b/src/main/java/com/moabam/api/application/payment/PaymentMapper.java index c68b78c6..c5bf6c56 100644 --- a/src/main/java/com/moabam/api/application/payment/PaymentMapper.java +++ b/src/main/java/com/moabam/api/application/payment/PaymentMapper.java @@ -10,16 +10,16 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class PaymentMapper { - public static Payment toEntity(Long memberId, Product product) { + public static Payment toPayment(Long memberId, Product product) { Order order = Order.builder() .name(product.getName()) - .amount(product.getPrice()) .build(); return Payment.builder() .memberId(memberId) .product(product) .order(order) + .amount(product.getPrice()) .build(); } } diff --git a/src/main/java/com/moabam/api/application/payment/PaymentService.java b/src/main/java/com/moabam/api/application/payment/PaymentService.java index 914a3ca3..7d4b762f 100644 --- a/src/main/java/com/moabam/api/application/payment/PaymentService.java +++ b/src/main/java/com/moabam/api/application/payment/PaymentService.java @@ -20,13 +20,13 @@ public class PaymentService { private final PaymentRepository paymentRepository; @Transactional - public void requestPayment(Long memberId, Long paymentId, PaymentRequest request) { - Payment payment = getPayment(paymentId); + public void request(Long memberId, Long paymentId, PaymentRequest request) { + Payment payment = getById(paymentId); payment.validateByMember(memberId); payment.request(request.orderId()); } - private Payment getPayment(Long paymentId) { + private Payment getById(Long paymentId) { return paymentRepository.findById(paymentId) .orElseThrow(() -> new NotFoundException(PAYMENT_NOT_FOUND)); } diff --git a/src/main/java/com/moabam/api/application/product/ProductMapper.java b/src/main/java/com/moabam/api/application/product/ProductMapper.java index 45434316..32369eb2 100644 --- a/src/main/java/com/moabam/api/application/product/ProductMapper.java +++ b/src/main/java/com/moabam/api/application/product/ProductMapper.java @@ -35,7 +35,7 @@ public static PurchaseProductResponse toPurchaseProductResponse(Payment payment) return PurchaseProductResponse.builder() .paymentId(payment.getId()) .orderName(payment.getOrder().getName()) - .price(payment.getOrder().getAmount()) + .price(payment.getAmount()) .build(); } } diff --git a/src/main/java/com/moabam/api/domain/payment/Order.java b/src/main/java/com/moabam/api/domain/payment/Order.java index c2073481..c907c46d 100644 --- a/src/main/java/com/moabam/api/domain/payment/Order.java +++ b/src/main/java/com/moabam/api/domain/payment/Order.java @@ -1,11 +1,7 @@ package com.moabam.api.domain.payment; -import static com.moabam.global.error.model.ErrorMessage.*; -import static java.lang.Math.*; import static java.util.Objects.*; -import com.moabam.global.error.exception.BadRequestException; - import jakarta.persistence.Column; import jakarta.persistence.Embeddable; import lombok.AccessLevel; @@ -18,34 +14,15 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Order { - private static final int MIN_AMOUNT = 0; - @Column(name = "order_id") private String id; @Column(name = "order_name", nullable = false) private String name; - @Column(name = "amount", nullable = false) - private int amount; - @Builder - private Order(String id, String name, int amount) { - this.id = id; + private Order(String name) { this.name = requireNonNull(name); - this.amount = validateAmount(amount); - } - - private int validateAmount(int amount) { - if (amount < MIN_AMOUNT) { - throw new BadRequestException(INVALID_ORDER_AMOUNT); - } - - return amount; - } - - public void discountAmount(int price) { - this.amount = max(MIN_AMOUNT, amount - price); } public void updateId(String id) { diff --git a/src/main/java/com/moabam/api/domain/payment/Payment.java b/src/main/java/com/moabam/api/domain/payment/Payment.java index 7a8407d2..4f549cf4 100644 --- a/src/main/java/com/moabam/api/domain/payment/Payment.java +++ b/src/main/java/com/moabam/api/domain/payment/Payment.java @@ -1,16 +1,22 @@ package com.moabam.api.domain.payment; import static com.moabam.global.error.model.ErrorMessage.*; +import static java.lang.Math.*; import static java.util.Objects.*; +import java.time.LocalDateTime; + +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + import com.moabam.api.domain.coupon.Coupon; import com.moabam.api.domain.product.Product; -import com.moabam.global.common.entity.BaseTimeEntity; import com.moabam.global.error.exception.BadRequestException; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; import jakarta.persistence.FetchType; @@ -29,7 +35,10 @@ @Getter @Table(name = "payment") @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Payment extends BaseTimeEntity { +@EntityListeners(AuditingEntityListener.class) +public class Payment { + + private static final int MIN_AMOUNT = 0; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -50,6 +59,9 @@ public class Payment extends BaseTimeEntity { @Embedded private Order order; + @Column(name = "amount", nullable = false) + private int amount; + @Column(name = "payment_key") private String paymentKey; @@ -57,20 +69,31 @@ public class Payment extends BaseTimeEntity { @Column(name = "status", nullable = false) private PaymentStatus status; + @CreatedDate + @Column(name = "created_at", updatable = false, nullable = false) + private LocalDateTime createdAt; + + @Column(name = "requested_at") + private LocalDateTime requestedAt; + + @Column(name = "approved_at") + private LocalDateTime approvedAt; + @Builder - public Payment(Long memberId, Product product, Coupon coupon, Order order, String paymentKey, - PaymentStatus status) { + public Payment(Long memberId, Product product, Order order, int amount, PaymentStatus status) { this.memberId = requireNonNull(memberId); this.product = requireNonNull(product); - this.coupon = coupon; this.order = requireNonNull(order); - this.paymentKey = paymentKey; + this.amount = validateAmount(amount); this.status = requireNonNullElse(status, PaymentStatus.PENDING); } - public void applyCoupon(Coupon coupon) { - this.order.discountAmount(coupon.getPoint()); - this.coupon = coupon; + private int validateAmount(int amount) { + if (amount < MIN_AMOUNT) { + throw new BadRequestException(INVALID_PAYMENT_AMOUNT); + } + + return amount; } public void validateByMember(Long memberId) { @@ -79,6 +102,11 @@ public void validateByMember(Long memberId) { } } + public void applyCoupon(Coupon coupon) { + this.coupon = coupon; + this.amount = max(MIN_AMOUNT, amount - coupon.getPoint()); + } + public void request(String orderId) { this.order.updateId(orderId); this.status = PaymentStatus.REQUEST; diff --git a/src/main/java/com/moabam/api/dto/bug/TodayBugResponse.java b/src/main/java/com/moabam/api/dto/bug/TodayBugResponse.java deleted file mode 100644 index 11ee0dcc..00000000 --- a/src/main/java/com/moabam/api/dto/bug/TodayBugResponse.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.moabam.api.dto.bug; - -import lombok.Builder; - -@Builder -public record TodayBugResponse( - int morningBug, - int nightBug -) { - -} diff --git a/src/main/java/com/moabam/api/presentation/BugController.java b/src/main/java/com/moabam/api/presentation/BugController.java index b8f86633..5172a612 100644 --- a/src/main/java/com/moabam/api/presentation/BugController.java +++ b/src/main/java/com/moabam/api/presentation/BugController.java @@ -11,7 +11,6 @@ import com.moabam.api.application.bug.BugService; import com.moabam.api.dto.bug.BugResponse; -import com.moabam.api.dto.bug.TodayBugResponse; import com.moabam.api.dto.product.ProductsResponse; import com.moabam.api.dto.product.PurchaseProductRequest; import com.moabam.api.dto.product.PurchaseProductResponse; @@ -34,12 +33,6 @@ public BugResponse getBug(@CurrentMember AuthorizationMember member) { return bugService.getBug(member.id()); } - @GetMapping("/today") - @ResponseStatus(HttpStatus.OK) - public TodayBugResponse getTodayBug(@CurrentMember AuthorizationMember member) { - return bugService.getTodayBug(member.id()); - } - @GetMapping("/products") @ResponseStatus(HttpStatus.OK) public ProductsResponse getBugProducts() { diff --git a/src/main/java/com/moabam/api/presentation/PaymentController.java b/src/main/java/com/moabam/api/presentation/PaymentController.java index 6ca29298..a3049974 100644 --- a/src/main/java/com/moabam/api/presentation/PaymentController.java +++ b/src/main/java/com/moabam/api/presentation/PaymentController.java @@ -23,11 +23,11 @@ public class PaymentController { private final PaymentService paymentService; - @PostMapping("/{paymentId}/request") + @PostMapping("/{paymentId}") @ResponseStatus(HttpStatus.OK) - public void requestPayment(@CurrentMember AuthorizationMember member, + public void request(@CurrentMember AuthorizationMember member, @PathVariable Long paymentId, @Valid @RequestBody PaymentRequest request) { - paymentService.requestPayment(member.id(), paymentId, request); + paymentService.request(member.id(), paymentId, request); } } diff --git a/src/main/java/com/moabam/global/error/model/ErrorMessage.java b/src/main/java/com/moabam/global/error/model/ErrorMessage.java index f0a7039a..ae7bfe87 100644 --- a/src/main/java/com/moabam/global/error/model/ErrorMessage.java +++ b/src/main/java/com/moabam/global/error/model/ErrorMessage.java @@ -47,7 +47,7 @@ public enum ErrorMessage { INVALID_PRICE("가격은 0 이상이어야 합니다."), INVALID_QUANTITY("수량은 1 이상이어야 합니다."), INVALID_LEVEL("레벨은 1 이상이어야 합니다."), - INVALID_ORDER_AMOUNT("주문 금액은 0 이상이어야 합니다."), + INVALID_PAYMENT_AMOUNT("결제 금액은 0 이상이어야 합니다."), PRODUCT_NOT_FOUND("존재하지 않는 상품입니다."), diff --git a/src/test/java/com/moabam/api/application/payment/PaymentServiceTest.java b/src/test/java/com/moabam/api/application/payment/PaymentServiceTest.java index a2d0472e..f5599a33 100644 --- a/src/test/java/com/moabam/api/application/payment/PaymentServiceTest.java +++ b/src/test/java/com/moabam/api/application/payment/PaymentServiceTest.java @@ -45,7 +45,7 @@ void payment_not_found_exception() { given(paymentRepository.findById(paymentId)).willReturn(Optional.empty()); // when, then - assertThatThrownBy(() -> paymentService.requestPayment(memberId, paymentId, request)) + assertThatThrownBy(() -> paymentService.request(memberId, paymentId, request)) .isInstanceOf(NotFoundException.class) .hasMessage("존재하지 않는 결제 정보입니다."); } diff --git a/src/test/java/com/moabam/api/domain/payment/OrderTest.java b/src/test/java/com/moabam/api/domain/payment/OrderTest.java index 08cac418..c84b2dfc 100644 --- a/src/test/java/com/moabam/api/domain/payment/OrderTest.java +++ b/src/test/java/com/moabam/api/domain/payment/OrderTest.java @@ -5,61 +5,15 @@ import static org.assertj.core.api.Assertions.*; import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import com.moabam.global.error.exception.BadRequestException; - class OrderTest { - @DisplayName("금액이 음수이면 예외가 발생한다.") - @Test - void validate_bug_count_exception() { - Order.OrderBuilder orderBuilder = Order.builder() - .name(BUG_PRODUCT_NAME) - .amount(-1000); - - assertThatThrownBy(orderBuilder::build) - .isInstanceOf(BadRequestException.class) - .hasMessage("주문 금액은 0 이상이어야 합니다."); - } - - @DisplayName("금액을 할인한다.") - @Nested - class Use { - - @DisplayName("성공한다.") - @Test - void success() { - // given - Order order = order(); - - // when - order.discountAmount(1000); - - // then - assertThat(order.getAmount()).isEqualTo(BUG_PRODUCT_PRICE - 1000); - } - - @DisplayName("할인 금액이 주문 금액보다 크면 0으로 처리한다.") - @Test - void discount_amount_greater_than_order_amount() { - // given - Order order = order(); - - // when - order.discountAmount(10000); - - // then - assertThat(order.getAmount()).isZero(); - } - } - @DisplayName("주문 id를 갱신한다.") @Test void update_id_success() { // given - Order order = order(); + Order order = order(bugProduct()); // when order.updateId(ORDER_ID); diff --git a/src/test/java/com/moabam/api/domain/payment/PaymentTest.java b/src/test/java/com/moabam/api/domain/payment/PaymentTest.java index da458d68..190ce1c2 100644 --- a/src/test/java/com/moabam/api/domain/payment/PaymentTest.java +++ b/src/test/java/com/moabam/api/domain/payment/PaymentTest.java @@ -6,6 +6,7 @@ import static org.assertj.core.api.Assertions.*; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import com.moabam.api.domain.coupon.Coupon; @@ -13,19 +14,53 @@ class PaymentTest { - @DisplayName("쿠폰을 적용한다.") + @DisplayName("금액이 음수이면 예외가 발생한다.") @Test - void apply_coupon_success() { - // given - Payment payment = payment(bugProduct()); - Coupon coupon = discount1000Coupon(); + void validate_amount_exception() { + Payment.PaymentBuilder paymentBuilder = Payment.builder() + .memberId(1L) + .product(bugProduct()) + .order(order(bugProduct())) + .amount(-1000); - // when - payment.applyCoupon(coupon); + assertThatThrownBy(paymentBuilder::build) + .isInstanceOf(BadRequestException.class) + .hasMessage("결제 금액은 0 이상이어야 합니다."); + } - // then - assertThat(payment.getOrder().getAmount()).isEqualTo(2000); - assertThat(payment.getCoupon()).isEqualTo(coupon); + @DisplayName("쿠폰을 적용한다.") + @Nested + class ApplyCoupon { + + @DisplayName("성공한다.") + @Test + void success() { + // given + Payment payment = payment(bugProduct()); + Coupon coupon = discount1000Coupon(); + + // when + payment.applyCoupon(coupon); + + // then + assertThat(payment.getAmount()).isEqualTo(BUG_PRODUCT_PRICE - 1000); + assertThat(payment.getCoupon()).isEqualTo(coupon); + } + + @DisplayName("할인 금액이 더 크면 0으로 처리한다.") + @Test + void discount_amount_greater() { + // given + Payment payment = payment(bugProduct()); + Coupon coupon = discount10000Coupon(); + + // when + payment.applyCoupon(coupon); + + // then + assertThat(payment.getAmount()).isZero(); + assertThat(payment.getCoupon()).isEqualTo(coupon); + } } @DisplayName("해당 회원의 결제 정보가 아니면 예외가 발생한다.") diff --git a/src/test/java/com/moabam/api/presentation/BugControllerTest.java b/src/test/java/com/moabam/api/presentation/BugControllerTest.java index cc754567..1e5b8e0a 100644 --- a/src/test/java/com/moabam/api/presentation/BugControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/BugControllerTest.java @@ -2,7 +2,6 @@ import static com.moabam.global.auth.model.AuthorizationThreadLocal.*; import static com.moabam.support.fixture.BugFixture.*; -import static com.moabam.support.fixture.BugHistoryFixture.*; import static com.moabam.support.fixture.CouponFixture.*; import static com.moabam.support.fixture.MemberFixture.*; import static com.moabam.support.fixture.ProductFixture.*; @@ -37,7 +36,6 @@ import com.moabam.api.domain.product.Product; import com.moabam.api.domain.product.repository.ProductRepository; import com.moabam.api.dto.bug.BugResponse; -import com.moabam.api.dto.bug.TodayBugResponse; import com.moabam.api.dto.product.ProductsResponse; import com.moabam.api.dto.product.PurchaseProductRequest; import com.moabam.api.dto.product.PurchaseProductResponse; @@ -91,30 +89,6 @@ void get_bug_success() throws Exception { assertThat(actual).isEqualTo(expected); } - @DisplayName("오늘 보상 벌레를 조회한다.") - @WithMember - @Test - void get_today_bug_success() throws Exception { - // given - Long memberId = getAuthorizationMember().id(); - bugHistoryRepository.saveAll(List.of( - rewardMorningBug(memberId, 2), - rewardMorningBug(memberId, 3), - rewardNightBug(memberId, 5))); - TodayBugResponse expected = BugMapper.toTodayBugResponse(5, 5); - - // expected - String content = mockMvc.perform(get("/bugs/today") - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andDo(print()) - .andReturn() - .getResponse() - .getContentAsString(UTF_8); - TodayBugResponse actual = objectMapper.readValue(content, TodayBugResponse.class); - assertThat(actual).isEqualTo(expected); - } - @DisplayName("벌레 상품 목록을 조회한다.") @Test void get_bug_products_success() throws Exception { diff --git a/src/test/java/com/moabam/api/presentation/PaymentControllerTest.java b/src/test/java/com/moabam/api/presentation/PaymentControllerTest.java index b5e1a36b..9e9ad410 100644 --- a/src/test/java/com/moabam/api/presentation/PaymentControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/PaymentControllerTest.java @@ -48,7 +48,7 @@ class PaymentControllerTest extends WithoutFilterSupporter { @Nested @DisplayName("결제를 요청한다.") - class RequestPayment { + class Request { @DisplayName("성공한다.") @WithMember @@ -60,7 +60,7 @@ void success() throws Exception { PaymentRequest request = new PaymentRequest(ORDER_ID); // expected - mockMvc.perform(post("/payments/{paymentId}/request", payment.getId()) + mockMvc.perform(post("/payments/{paymentId}", payment.getId()) .contentType(APPLICATION_JSON) .content(objectMapper.writeValueAsString(request))) .andExpect(status().isOk()) @@ -80,7 +80,7 @@ void bad_request_body_exception(String orderId) throws Exception { PaymentRequest request = new PaymentRequest(orderId); // expected - mockMvc.perform(post("/payments/{paymentId}/request", paymentId) + mockMvc.perform(post("/payments/{paymentId}", paymentId) .contentType(APPLICATION_JSON) .content(objectMapper.writeValueAsString(request))) .andExpect(status().isBadRequest()) diff --git a/src/test/java/com/moabam/support/fixture/CouponFixture.java b/src/test/java/com/moabam/support/fixture/CouponFixture.java index 1f2082f1..b03acaac 100644 --- a/src/test/java/com/moabam/support/fixture/CouponFixture.java +++ b/src/test/java/com/moabam/support/fixture/CouponFixture.java @@ -14,9 +14,7 @@ public final class CouponFixture { public static final String DISCOUNT_1000_COUPON_NAME = "황금벌레 1000원 할인"; - public static final int DISCOUNT_1000_COUPON_STOCK = 100; - public static final LocalDateTime DISCOUNT_1000_COUPON_START_AT = LocalDateTime.of(2023, 1, 1, 0, 0); - public static final LocalDateTime DISCOUNT_1000_COUPON_END_AT = LocalDateTime.of(2023, 1, 1, 0, 0); + public static final String DISCOUNT_10000_COUPON_NAME = "황금벌레 10000원 할인"; public static Coupon coupon(int point, int stock) { return Coupon.builder() @@ -47,9 +45,21 @@ public static Coupon discount1000Coupon() { .name(DISCOUNT_1000_COUPON_NAME) .point(1000) .type(CouponType.DISCOUNT_COUPON) - .stock(DISCOUNT_1000_COUPON_STOCK) - .startAt(DISCOUNT_1000_COUPON_START_AT) - .endAt(DISCOUNT_1000_COUPON_END_AT) + .stock(100) + .startAt(LocalDateTime.of(2023, 1, 1, 0, 0)) + .endAt(LocalDateTime.of(2023, 1, 1, 0, 0)) + .adminId(1L) + .build(); + } + + public static Coupon discount10000Coupon() { + return Coupon.builder() + .name(DISCOUNT_10000_COUPON_NAME) + .point(10000) + .type(CouponType.DISCOUNT_COUPON) + .stock(100) + .startAt(LocalDateTime.of(2023, 1, 1, 0, 0)) + .endAt(LocalDateTime.of(2023, 1, 1, 0, 0)) .adminId(1L) .build(); } diff --git a/src/test/java/com/moabam/support/fixture/PaymentFixture.java b/src/test/java/com/moabam/support/fixture/PaymentFixture.java index 40db89c0..a47080ae 100644 --- a/src/test/java/com/moabam/support/fixture/PaymentFixture.java +++ b/src/test/java/com/moabam/support/fixture/PaymentFixture.java @@ -1,7 +1,5 @@ package com.moabam.support.fixture; -import static com.moabam.support.fixture.ProductFixture.*; - import com.moabam.api.domain.payment.Order; import com.moabam.api.domain.payment.Payment; import com.moabam.api.domain.product.Product; @@ -14,14 +12,14 @@ public static Payment payment(Product product) { return Payment.builder() .memberId(1L) .product(product) - .order(order()) + .order(order(product)) + .amount(product.getPrice()) .build(); } - public static Order order() { + public static Order order(Product product) { return Order.builder() - .name(BUG_PRODUCT_NAME) - .amount(BUG_PRODUCT_PRICE) + .name(product.getName()) .build(); } }