Skip to content

Commit

Permalink
feat: 경매의 마지막 입찰을 조회하는 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonyj1022 committed Nov 22, 2023
1 parent 04c26bb commit 25c0e46
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,8 @@ public Optional<User> findLastBidder() {

return Optional.of(lastBid.getBidder());
}

public Optional<Bid> findLastBid() {
return Optional.ofNullable(lastBid);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.ddang.ddang.auction.domain;

import static org.assertj.core.api.Assertions.assertThat;

import com.ddang.ddang.auction.domain.fixture.AuctionFixture;
import com.ddang.ddang.bid.domain.Bid;
import com.ddang.ddang.user.domain.User;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;

@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
@SuppressWarnings("NonAsciiCharacters")
class AuctionTest extends AuctionFixture {
Expand Down Expand Up @@ -352,6 +353,43 @@ class AuctionTest extends AuctionFixture {
assertThat(actual).isEmpty();
}

@Test
void 마지막_입찰을_반환한다() {
// given
final Auction auction = Auction.builder()
.title("제목")
.seller(판매자)
.closingTime(LocalDateTime.now().minusDays(3L))
.startPrice(new Price(1_000))
.bidUnit(new BidUnit(1_000))
.build();
final Bid bid = new Bid(auction, 구매자, 유효한_입찰_금액);

auction.updateLastBid(bid);

// when
final Optional<Bid> actual = auction.findLastBid();

// then
assertThat(actual).contains(bid);
}

@Test
void 마지막_입찰이_없다면__Optional_반환한다() {
// given
final Auction auction = Auction.builder()
.title("제목")
.seller(판매자)
.closingTime(LocalDateTime.now().minusDays(3L))
.build();

// when
final Optional<Bid> actual = auction.findLastBid();

// then
assertThat(actual).isEmpty();
}

@Test
void 경매를_진행중이며_입찰자가_없는_경우_UNBIDDEN_반환한다() {
// given
Expand Down

0 comments on commit 25c0e46

Please sign in to comment.