From 7d6940fb8bdb0806b38cdb8584c8e72b15d63a7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=84=EB=8F=99=ED=98=84?= Date: Mon, 18 Dec 2023 20:28:57 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=B3=B4=EC=A6=9D=EA=B8=88=20=ED=99=98?= =?UTF-8?q?=EA=B8=89,=20=EC=9E=85=EA=B8=88=20=EC=97=AC=EB=B6=80=20?= =?UTF-8?q?=ED=86=A0=EA=B8=80=20=ED=98=95=EC=8B=9D=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20(#408)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/upbrella/be/rent/entity/History.java | 11 ++++++++++ .../be/rent/service/RentServiceTest.java | 21 ++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/java/upbrella/be/rent/entity/History.java b/src/main/java/upbrella/be/rent/entity/History.java index 20b3de78..81a803cc 100644 --- a/src/main/java/upbrella/be/rent/entity/History.java +++ b/src/main/java/upbrella/be/rent/entity/History.java @@ -57,12 +57,23 @@ public class History { public void refund(User user, LocalDateTime refundedAt) { + if (this.refundedAt != null || this.refundedBy != null) { + this.refundedAt = null; + this.refundedBy = null; + return; + } + this.refundedAt = refundedAt; this.refundedBy = user; } public void paid(User user, LocalDateTime paidAt) { + if (this.paidAt != null || this.paidBy != null) { + this.paidAt = null; + this.paidBy = null; + return; + } this.paidBy = user; this.paidAt = paidAt; } diff --git a/src/test/java/upbrella/be/rent/service/RentServiceTest.java b/src/test/java/upbrella/be/rent/service/RentServiceTest.java index 844fb5ff..3b55470a 100644 --- a/src/test/java/upbrella/be/rent/service/RentServiceTest.java +++ b/src/test/java/upbrella/be/rent/service/RentServiceTest.java @@ -10,7 +10,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; -import org.springframework.transaction.annotation.Transactional; import upbrella.be.config.FixtureBuilderFactory; import upbrella.be.config.FixtureFactory; import upbrella.be.rent.dto.response.HistoryInfoDto; @@ -20,7 +19,6 @@ import upbrella.be.rent.dto.response.RentalHistoryResponse; import upbrella.be.rent.entity.ConditionReport; import upbrella.be.rent.entity.History; -import upbrella.be.rent.exception.ExistingUmbrellaForRentException; import upbrella.be.rent.exception.NonExistingHistoryException; import upbrella.be.rent.exception.NotAvailableUmbrellaException; import upbrella.be.rent.exception.NotRefundedException; @@ -342,28 +340,35 @@ class checkRefundTest { void success() { // given + History historyForRefund = History.builder() + .id(33L) + .rentedAt(LocalDateTime.of(1000, 12, 3, 4, 24)) + .umbrella(foundUmbrella) + .user(userToRent) + .rentStoreMeta(foundStoreMeta) + .build(); + long loginedUserId = 7L; given(userService.findUserById(loginedUserId)) .willReturn(userToRent); given(rentRepository.findById(33L)) - .willReturn(Optional.of(history)); - given(rentRepository.save(history)) - .willReturn(history); + .willReturn(Optional.of(historyForRefund)); + // when rentService.checkRefund(33L, loginedUserId); //then - assertAll(() -> assertThat(history.getRefundedBy()) + assertAll(() -> assertThat(historyForRefund.getRefundedBy()) .isEqualTo(userToRent), - () -> assertThat(history.getRefundedAt()) + () -> assertThat(historyForRefund.getRefundedAt()) .isBeforeOrEqualTo(LocalDateTime.now()), () -> then(userService).should(times(1)) .findUserById(loginedUserId), () -> then(rentRepository).should(times(1)) .findById(33L), () -> then(rentRepository).should(times(1)) - .save(history) + .save(historyForRefund) ); }