Skip to content

Commit

Permalink
Merge pull request #410 from UPbrella/dev
Browse files Browse the repository at this point in the history
v1.2.1 release
  • Loading branch information
birdieHyun authored Dec 18, 2023
2 parents 61b6dad + 7d6940f commit eb809b0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/main/java/upbrella/be/rent/entity/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 13 additions & 8 deletions src/test/java/upbrella/be/rent/service/RentServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
);
}

Expand Down

0 comments on commit eb809b0

Please sign in to comment.