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 f06401e8..f1246d45 100644 --- a/src/main/java/com/moabam/api/application/bug/BugService.java +++ b/src/main/java/com/moabam/api/application/bug/BugService.java @@ -80,6 +80,10 @@ public PurchaseProductResponse purchaseBugProduct(Long memberId, Long productId, @Transactional public void use(Member member, BugType bugType, int count) { + if (count == 0) { + return; + } + Bug bug = member.getBug(); bug.use(bugType, count); @@ -88,6 +92,10 @@ public void use(Member member, BugType bugType, int count) { @Transactional public void reward(Member member, BugType bugType, int count) { + if (count == 0) { + return; + } + Bug bug = member.getBug(); bug.increase(bugType, count); @@ -104,6 +112,10 @@ public void charge(Long memberId, Product bugProduct) { @Transactional public void applyCoupon(Long memberId, BugType bugType, int count) { + if (count == 0) { + return; + } + Bug bug = getByMemberId(memberId); bug.increase(bugType, count); diff --git a/src/main/java/com/moabam/api/application/image/ImageService.java b/src/main/java/com/moabam/api/application/image/ImageService.java index c2b4208f..a70a783f 100644 --- a/src/main/java/com/moabam/api/application/image/ImageService.java +++ b/src/main/java/com/moabam/api/application/image/ImageService.java @@ -1,5 +1,8 @@ package com.moabam.api.application.image; +import static com.moabam.global.error.model.ErrorMessage.IMAGE_CONVERT_FAIL; + +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -10,7 +13,10 @@ import com.moabam.api.domain.image.ImageName; import com.moabam.api.domain.image.ImageResizer; import com.moabam.api.domain.image.ImageType; +import com.moabam.api.domain.image.NewImage; +import com.moabam.api.dto.room.CertifyRoomsRequest; import com.moabam.api.infrastructure.s3.S3Manager; +import com.moabam.global.error.exception.BadRequestException; import lombok.RequiredArgsConstructor; @@ -22,7 +28,7 @@ public class ImageService { private final S3Manager s3Manager; @Transactional - public List uploadImages(List multipartFiles, ImageType imageType) { + public List uploadImages(List multipartFiles, ImageType imageType) { List result = new ArrayList<>(); @@ -38,6 +44,24 @@ public List uploadImages(List multipartFiles, ImageType i return result; } + public List getNewImages(CertifyRoomsRequest request) { + return request.getCertifyRoomsRequest().stream() + .map(certifyRoomRequest -> { + try { + return NewImage.of(String.valueOf(certifyRoomRequest.getRoutineId()), + certifyRoomRequest.getImage().getContentType(), certifyRoomRequest.getImage().getBytes()); + } catch (IOException e) { + throw new BadRequestException(IMAGE_CONVERT_FAIL); + } + }) + .toList(); + } + + @Transactional + public void deleteImage(String imageUrl) { + s3Manager.deleteImage(imageUrl); + } + private ImageResizer toImageResizer(MultipartFile multipartFile, ImageType imageType) { ImageName imageName = ImageName.of(multipartFile, imageType); @@ -46,9 +70,4 @@ private ImageResizer toImageResizer(MultipartFile multipartFile, ImageType image .fileName(imageName.getFileName()) .build(); } - - @Transactional - public void deleteImage(String imageUrl) { - s3Manager.deleteImage(imageUrl); - } } 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 322ce92a..e98b64eb 100644 --- a/src/main/java/com/moabam/api/application/payment/PaymentMapper.java +++ b/src/main/java/com/moabam/api/application/payment/PaymentMapper.java @@ -5,7 +5,9 @@ import com.moabam.api.domain.payment.Order; import com.moabam.api.domain.payment.Payment; import com.moabam.api.domain.product.Product; +import com.moabam.api.dto.payment.ConfirmTossPaymentResponse; import com.moabam.api.dto.payment.PaymentResponse; +import com.moabam.api.dto.payment.RequestConfirmPaymentResponse; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -36,4 +38,12 @@ public static PaymentResponse toPaymentResponse(Payment payment) { .build()) .orElse(null); } + + public static RequestConfirmPaymentResponse toRequestConfirmPaymentResponse(Payment payment, + ConfirmTossPaymentResponse response) { + return RequestConfirmPaymentResponse.builder() + .payment(payment) + .paymentKey(response.paymentKey()) + .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 710e37b0..80b388a8 100644 --- a/src/main/java/com/moabam/api/application/payment/PaymentService.java +++ b/src/main/java/com/moabam/api/application/payment/PaymentService.java @@ -13,8 +13,10 @@ import com.moabam.api.dto.payment.ConfirmPaymentRequest; import com.moabam.api.dto.payment.ConfirmTossPaymentResponse; import com.moabam.api.dto.payment.PaymentRequest; +import com.moabam.api.dto.payment.RequestConfirmPaymentResponse; import com.moabam.api.infrastructure.payment.TossPaymentService; import com.moabam.global.error.exception.NotFoundException; +import com.moabam.global.error.exception.TossPaymentException; import lombok.RequiredArgsConstructor; @@ -36,16 +38,23 @@ public void request(Long memberId, Long paymentId, PaymentRequest request) { payment.request(request.orderId()); } - public Payment validateInfo(Long memberId, ConfirmPaymentRequest request) { + @Transactional + public RequestConfirmPaymentResponse requestConfirm(Long memberId, ConfirmPaymentRequest request) { Payment payment = getByOrderId(request.orderId()); payment.validateInfo(memberId, request.amount()); - return payment; + try { + ConfirmTossPaymentResponse response = tossPaymentService.confirm(request); + return PaymentMapper.toRequestConfirmPaymentResponse(payment, response); + } catch (TossPaymentException exception) { + payment.fail(request.paymentKey()); + throw exception; + } } @Transactional - public void confirm(Long memberId, Payment payment, ConfirmTossPaymentResponse response) { - payment.confirm(response.paymentKey()); + public void confirm(Long memberId, Payment payment, String paymentKey) { + payment.confirm(paymentKey); if (payment.isCouponApplied()) { couponService.discount(payment.getCouponWalletId(), memberId); @@ -53,11 +62,6 @@ public void confirm(Long memberId, Payment payment, ConfirmTossPaymentResponse r bugService.charge(memberId, payment.getProduct()); } - @Transactional - public void fail(Payment payment, String paymentKey) { - payment.fail(paymentKey); - } - 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/room/mapper/RoomMapper.java b/src/main/java/com/moabam/api/application/room/mapper/RoomMapper.java index 8282c0ee..aee5dd5d 100644 --- a/src/main/java/com/moabam/api/application/room/mapper/RoomMapper.java +++ b/src/main/java/com/moabam/api/application/room/mapper/RoomMapper.java @@ -45,6 +45,7 @@ public static RoomDetailsResponse toRoomDetailsResponse(Long memberId, Room room List todayCertificateRankResponses, double completePercentage) { return RoomDetailsResponse.builder() .roomId(room.getId()) + .roomCreatedAt(room.getCreatedAt()) .myMemberId(memberId) .title(room.getTitle()) .managerNickName(managerNickname) diff --git a/src/main/java/com/moabam/api/domain/image/ImageResizer.java b/src/main/java/com/moabam/api/domain/image/ImageResizer.java index 5a7d65ba..82b2f1d4 100644 --- a/src/main/java/com/moabam/api/domain/image/ImageResizer.java +++ b/src/main/java/com/moabam/api/domain/image/ImageResizer.java @@ -116,7 +116,7 @@ private BufferedImage getBufferedImage() { } } - private ResizedImage toMultipartFile(byte[] bytes) { - return ResizedImage.of(fileName, image.getContentType(), bytes); + private NewImage toMultipartFile(byte[] bytes) { + return NewImage.of(fileName, image.getContentType(), bytes); } } diff --git a/src/main/java/com/moabam/api/domain/image/ResizedImage.java b/src/main/java/com/moabam/api/domain/image/NewImage.java similarity index 85% rename from src/main/java/com/moabam/api/domain/image/ResizedImage.java rename to src/main/java/com/moabam/api/domain/image/NewImage.java index d7568527..6367d63c 100644 --- a/src/main/java/com/moabam/api/domain/image/ResizedImage.java +++ b/src/main/java/com/moabam/api/domain/image/NewImage.java @@ -12,15 +12,15 @@ import lombok.RequiredArgsConstructor; @RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public class ResizedImage implements MultipartFile { +public class NewImage implements MultipartFile { private final String name; private final String contentType; private final long size; private final byte[] bytes; - public static ResizedImage of(String name, String contentType, byte[] bytes) { - return new ResizedImage(name, contentType, bytes.length, bytes); + public static NewImage of(String name, String contentType, byte[] bytes) { + return new NewImage(name, contentType, bytes.length, bytes); } @Override diff --git a/src/main/java/com/moabam/api/dto/payment/ConfirmTossPaymentResponse.java b/src/main/java/com/moabam/api/dto/payment/ConfirmTossPaymentResponse.java index ee32917a..34b5bdb7 100644 --- a/src/main/java/com/moabam/api/dto/payment/ConfirmTossPaymentResponse.java +++ b/src/main/java/com/moabam/api/dto/payment/ConfirmTossPaymentResponse.java @@ -1,9 +1,6 @@ package com.moabam.api.dto.payment; -import java.time.LocalDateTime; - import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.moabam.api.domain.payment.PaymentStatus; import lombok.Builder; @@ -13,9 +10,7 @@ public record ConfirmTossPaymentResponse( String paymentKey, String orderId, String orderName, - PaymentStatus status, - int totalAmount, - LocalDateTime approvedAt + int totalAmount ) { } diff --git a/src/main/java/com/moabam/api/dto/payment/RequestConfirmPaymentResponse.java b/src/main/java/com/moabam/api/dto/payment/RequestConfirmPaymentResponse.java new file mode 100644 index 00000000..6c3b69ac --- /dev/null +++ b/src/main/java/com/moabam/api/dto/payment/RequestConfirmPaymentResponse.java @@ -0,0 +1,13 @@ +package com.moabam.api.dto.payment; + +import com.moabam.api.domain.payment.Payment; + +import lombok.Builder; + +@Builder +public record RequestConfirmPaymentResponse( + Payment payment, + String paymentKey +) { + +} diff --git a/src/main/java/com/moabam/api/dto/room/CertifyRoomRequest.java b/src/main/java/com/moabam/api/dto/room/CertifyRoomRequest.java new file mode 100644 index 00000000..594942e4 --- /dev/null +++ b/src/main/java/com/moabam/api/dto/room/CertifyRoomRequest.java @@ -0,0 +1,14 @@ +package com.moabam.api.dto.room; + +import org.springframework.web.multipart.MultipartFile; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class CertifyRoomRequest { + + private Long routineId; + private MultipartFile image; +} diff --git a/src/main/java/com/moabam/api/dto/room/CertifyRoomsRequest.java b/src/main/java/com/moabam/api/dto/room/CertifyRoomsRequest.java new file mode 100644 index 00000000..c2cf4110 --- /dev/null +++ b/src/main/java/com/moabam/api/dto/room/CertifyRoomsRequest.java @@ -0,0 +1,13 @@ +package com.moabam.api.dto.room; + +import java.util.List; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class CertifyRoomsRequest { + + private List certifyRoomsRequest; +} diff --git a/src/main/java/com/moabam/api/dto/room/RoomDetailsResponse.java b/src/main/java/com/moabam/api/dto/room/RoomDetailsResponse.java index 339ecbcc..cd019558 100644 --- a/src/main/java/com/moabam/api/dto/room/RoomDetailsResponse.java +++ b/src/main/java/com/moabam/api/dto/room/RoomDetailsResponse.java @@ -1,6 +1,7 @@ package com.moabam.api.dto.room; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; import com.moabam.api.domain.room.RoomType; @@ -10,6 +11,7 @@ @Builder public record RoomDetailsResponse( Long roomId, + LocalDateTime roomCreatedAt, Long myMemberId, String title, String managerNickName, diff --git a/src/main/java/com/moabam/api/infrastructure/payment/TossPaymentService.java b/src/main/java/com/moabam/api/infrastructure/payment/TossPaymentService.java index c53cc079..476cfe24 100644 --- a/src/main/java/com/moabam/api/infrastructure/payment/TossPaymentService.java +++ b/src/main/java/com/moabam/api/infrastructure/payment/TossPaymentService.java @@ -6,7 +6,6 @@ import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; @@ -21,7 +20,6 @@ import reactor.core.publisher.Mono; @Service -@Transactional(readOnly = true) @RequiredArgsConstructor public class TossPaymentService { @@ -39,7 +37,6 @@ public void init() { .build(); } - @Transactional public ConfirmTossPaymentResponse confirm(ConfirmPaymentRequest request) { return webClient.post() .uri("/v1/payments/confirm") diff --git a/src/main/java/com/moabam/api/presentation/PaymentController.java b/src/main/java/com/moabam/api/presentation/PaymentController.java index d27da27a..ab613b73 100644 --- a/src/main/java/com/moabam/api/presentation/PaymentController.java +++ b/src/main/java/com/moabam/api/presentation/PaymentController.java @@ -9,14 +9,11 @@ import org.springframework.web.bind.annotation.RestController; import com.moabam.api.application.payment.PaymentService; -import com.moabam.api.domain.payment.Payment; import com.moabam.api.dto.payment.ConfirmPaymentRequest; -import com.moabam.api.dto.payment.ConfirmTossPaymentResponse; import com.moabam.api.dto.payment.PaymentRequest; -import com.moabam.api.infrastructure.payment.TossPaymentService; +import com.moabam.api.dto.payment.RequestConfirmPaymentResponse; import com.moabam.global.auth.annotation.Auth; import com.moabam.global.auth.model.AuthMember; -import com.moabam.global.error.exception.TossPaymentException; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -27,7 +24,6 @@ public class PaymentController { private final PaymentService paymentService; - private final TossPaymentService tossPaymentService; @PostMapping("/{paymentId}") @ResponseStatus(HttpStatus.OK) @@ -39,13 +35,7 @@ public void request(@Auth AuthMember member, @PathVariable Long paymentId, @PostMapping("/confirm") @ResponseStatus(HttpStatus.OK) public void confirm(@Auth AuthMember member, @Valid @RequestBody ConfirmPaymentRequest request) { - Payment payment = paymentService.validateInfo(member.id(), request); - - try { - ConfirmTossPaymentResponse response = tossPaymentService.confirm(request); - paymentService.confirm(member.id(), payment, response); - } catch (TossPaymentException exception) { - paymentService.fail(payment, request.paymentKey()); - } + RequestConfirmPaymentResponse response = paymentService.requestConfirm(member.id(), request); + paymentService.confirm(member.id(), response.payment(), response.paymentKey()); } } diff --git a/src/main/java/com/moabam/api/presentation/RoomController.java b/src/main/java/com/moabam/api/presentation/RoomController.java index 66bb4bed..ffc3c52b 100644 --- a/src/main/java/com/moabam/api/presentation/RoomController.java +++ b/src/main/java/com/moabam/api/presentation/RoomController.java @@ -1,7 +1,7 @@ package com.moabam.api.presentation; import java.time.LocalDate; -import java.util.Map; +import java.util.List; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.DeleteMapping; @@ -12,16 +12,18 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; import com.moabam.api.application.image.ImageService; import com.moabam.api.application.room.CertificationService; import com.moabam.api.application.room.RoomService; import com.moabam.api.application.room.SearchService; +import com.moabam.api.domain.image.ImageType; +import com.moabam.api.domain.image.NewImage; import com.moabam.api.domain.room.RoomType; +import com.moabam.api.dto.room.CertifiedMemberInfo; +import com.moabam.api.dto.room.CertifyRoomsRequest; import com.moabam.api.dto.room.CreateRoomRequest; import com.moabam.api.dto.room.EnterRoomRequest; import com.moabam.api.dto.room.GetAllRoomsResponse; @@ -110,14 +112,11 @@ public RoomDetailsResponse getRoomDetails(@Auth AuthMember authMember, @PathVari @PostMapping("/{roomId}/certification") @ResponseStatus(HttpStatus.CREATED) public void certifyRoom(@Auth AuthMember authMember, @PathVariable("roomId") Long roomId, - @RequestPart(name = "file") Map multipartFiles) { - - log.info("multipartFiles Size = {}", multipartFiles.size()); - log.info(multipartFiles.toString()); - - // List imageUrls = imageService.uploadImages(multipartFiles, ImageType.CERTIFICATION); - // CertifiedMemberInfo info = certificationService.getCertifiedMemberInfo(authMember.id(), roomId, imageUrls); - // certificationService.certifyRoom(info); + CertifyRoomsRequest request) { + List images = imageService.getNewImages(request); + List imageUrls = imageService.uploadImages(images, ImageType.CERTIFICATION); + CertifiedMemberInfo info = certificationService.getCertifiedMemberInfo(authMember.id(), roomId, imageUrls); + certificationService.certifyRoom(info); } @PutMapping("/{roomId}/members/{memberId}/mandate") diff --git a/src/main/java/com/moabam/global/config/RedisConfig.java b/src/main/java/com/moabam/global/config/RedisConfig.java index 0e9cf0fb..cc412271 100644 --- a/src/main/java/com/moabam/global/config/RedisConfig.java +++ b/src/main/java/com/moabam/global/config/RedisConfig.java @@ -38,4 +38,12 @@ public RedisTemplate redisTemplate(RedisConnectionFactory redisC return redisTemplate; } + + @Bean + public ObjectMapper objectMapper() { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModules(new JavaTimeModule()); + + return objectMapper; + } } 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 8a16d99b..cd39ce68 100644 --- a/src/main/java/com/moabam/global/error/model/ErrorMessage.java +++ b/src/main/java/com/moabam/global/error/model/ErrorMessage.java @@ -31,6 +31,7 @@ public enum ErrorMessage { CERTIFICATION_NOT_FOUND("인증 정보가 없습니다."), NEED_TO_EXIT_ALL_ROOMS("모든 방에서 나가야 회원 탈퇴가 가능합니다."), PARTICIPANT_DEPORT_ERROR("방장은 자신을 추방할 수 없습니다."), + IMAGE_CONVERT_FAIL("이미지 변환을 실패했습니다."), LOGIN_FAILED("로그인에 실패했습니다."), REQUEST_FAILED("네트워크 접근 실패입니다."), diff --git a/src/test/java/com/moabam/api/application/image/ImageServiceTest.java b/src/test/java/com/moabam/api/application/image/ImageServiceTest.java index d8cdcc79..ea2e67ed 100644 --- a/src/test/java/com/moabam/api/application/image/ImageServiceTest.java +++ b/src/test/java/com/moabam/api/application/image/ImageServiceTest.java @@ -16,7 +16,7 @@ import org.springframework.web.multipart.MultipartFile; import com.moabam.api.domain.image.ImageType; -import com.moabam.api.domain.image.ResizedImage; +import com.moabam.api.domain.image.NewImage; import com.moabam.api.infrastructure.s3.S3Manager; import com.moabam.support.fixture.RoomFixture; @@ -38,7 +38,7 @@ void image_resize_upload_success() { MockMultipartFile image1 = RoomFixture.makeMultipartFile1(); List images = List.of(image1); - given(s3Manager.uploadImage(anyString(), any(ResizedImage.class))).willReturn(image1.getName()); + given(s3Manager.uploadImage(anyString(), any(NewImage.class))).willReturn(image1.getName()); // when List result = imageService.uploadImages(images, imageType); 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 3aa0e491..4158682c 100644 --- a/src/test/java/com/moabam/api/application/payment/PaymentServiceTest.java +++ b/src/test/java/com/moabam/api/application/payment/PaymentServiceTest.java @@ -9,6 +9,7 @@ import java.util.Optional; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -18,12 +19,14 @@ import com.moabam.api.application.bug.BugService; import com.moabam.api.application.coupon.CouponService; import com.moabam.api.domain.payment.Payment; +import com.moabam.api.domain.payment.PaymentStatus; import com.moabam.api.domain.payment.repository.PaymentRepository; import com.moabam.api.domain.payment.repository.PaymentSearchRepository; import com.moabam.api.dto.payment.ConfirmPaymentRequest; -import com.moabam.api.dto.payment.ConfirmTossPaymentResponse; import com.moabam.api.dto.payment.PaymentRequest; +import com.moabam.api.infrastructure.payment.TossPaymentService; import com.moabam.global.error.exception.NotFoundException; +import com.moabam.global.error.exception.TossPaymentException; @ExtendWith(MockitoExtension.class) class PaymentServiceTest { @@ -37,6 +40,9 @@ class PaymentServiceTest { @Mock CouponService couponService; + @Mock + TossPaymentService tossPaymentService; + @Mock PaymentRepository paymentRepository; @@ -58,32 +64,52 @@ void request_not_found_exception() { .hasMessage("존재하지 않는 결제 정보입니다."); } - @DisplayName("결제 정보 검증 시 해당 결제 정보가 존재하지 않으면 예외가 발생한다.") - @Test - void validate_info_not_found_exception() { - // given - Long memberId = 1L; - Payment payment = payment(bugProduct()); - ConfirmPaymentRequest request = confirmPaymentRequest(); - given(paymentSearchRepository.findByOrderId(request.orderId())).willReturn(Optional.empty()); - - // when, then - assertThatThrownBy(() -> paymentService.validateInfo(memberId, request)) - .isInstanceOf(NotFoundException.class) - .hasMessage("존재하지 않는 결제 정보입니다."); + @DisplayName("결제 승인을 요청한다.") + @Nested + class RequestConfirm { + + @DisplayName("해당 결제 정보가 존재하지 않으면 예외가 발생한다.") + @Test + void validate_info_not_found_exception() { + // given + Long memberId = 1L; + ConfirmPaymentRequest request = confirmPaymentRequest(); + given(paymentSearchRepository.findByOrderId(request.orderId())).willReturn(Optional.empty()); + + // when, then + assertThatThrownBy(() -> paymentService.requestConfirm(memberId, request)) + .isInstanceOf(NotFoundException.class) + .hasMessage("존재하지 않는 결제 정보입니다."); + } + + @DisplayName("토스 결제 승인 요청이 실패하면 결제 실패 처리한다.") + @Test + void toss_fail() { + // given + Long memberId = 1L; + Payment payment = payment(bugProduct()); + ConfirmPaymentRequest request = confirmPaymentRequest(); + given(paymentSearchRepository.findByOrderId(request.orderId())).willReturn(Optional.of(payment)); + given(tossPaymentService.confirm(request)).willThrow(TossPaymentException.class); + + // when, then + assertThatThrownBy(() -> paymentService.requestConfirm(memberId, request)) + .isInstanceOf(TossPaymentException.class); + assertThat(payment.getPaymentKey()).isEqualTo(PAYMENT_KEY); + assertThat(payment.getStatus()).isEqualTo(PaymentStatus.ABORTED); + } } - @DisplayName("결제 승인 시 쿠폰을 적용한 경우 쿠폰을 차감한 후 벌레를 충전한다.") + @DisplayName("결제 승인에 성공한다.") @Test - void confirm_with_coupon_success() { + void confirm_success() { // given Long memberId = 1L; Long couponWalletId = 1L; Payment payment = paymentWithCoupon(bugProduct(), discount1000Coupon(), couponWalletId); - ConfirmTossPaymentResponse response = confirmTossPaymentResponse(); // when - paymentService.confirm(memberId, payment, response); + paymentService.confirm(memberId, payment, PAYMENT_KEY); // then verify(couponService, times(1)).discount(couponWalletId, memberId); diff --git a/src/test/java/com/moabam/api/presentation/PaymentControllerTest.java b/src/test/java/com/moabam/api/presentation/PaymentControllerTest.java index 1c6321a8..7bbd2b6c 100644 --- a/src/test/java/com/moabam/api/presentation/PaymentControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/PaymentControllerTest.java @@ -172,10 +172,8 @@ void confirm_toss_exception() throws Exception { mockMvc.perform(post("/payments/confirm") .contentType(APPLICATION_JSON) .content(objectMapper.writeValueAsString(request))) - .andExpect(status().isOk()) + .andExpect(status().isInternalServerError()) .andDo(print()); - assertThat(payment.getPaymentKey()).isEqualTo(PAYMENT_KEY); - assertThat(payment.getStatus()).isEqualTo(PaymentStatus.ABORTED); } } } diff --git a/src/test/java/com/moabam/support/fixture/PaymentFixture.java b/src/test/java/com/moabam/support/fixture/PaymentFixture.java index 019b72ab..464652fb 100644 --- a/src/test/java/com/moabam/support/fixture/PaymentFixture.java +++ b/src/test/java/com/moabam/support/fixture/PaymentFixture.java @@ -2,12 +2,9 @@ import static com.moabam.support.fixture.ProductFixture.*; -import java.time.LocalDateTime; - import com.moabam.api.domain.coupon.Coupon; import com.moabam.api.domain.payment.Order; import com.moabam.api.domain.payment.Payment; -import com.moabam.api.domain.payment.PaymentStatus; import com.moabam.api.domain.product.Product; import com.moabam.api.dto.payment.ConfirmPaymentRequest; import com.moabam.api.dto.payment.ConfirmTossPaymentResponse; @@ -57,9 +54,7 @@ public static ConfirmTossPaymentResponse confirmTossPaymentResponse() { .paymentKey(PAYMENT_KEY) .orderId(ORDER_ID) .orderName(BUG_PRODUCT_NAME) - .status(PaymentStatus.DONE) .totalAmount(AMOUNT) - .approvedAt(LocalDateTime.of(2023, 1, 1, 1, 1)) .build(); } }