Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.2.1 release-dev #409

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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