Skip to content

Commit

Permalink
test: 경매 입찰(구매) 요청 수량 검증에 대한 테스트 코드 작성
Browse files Browse the repository at this point in the history
- 경매 재고보다 많은 수량을 입찰(구매)하려는 경우 예외가 발생
- 인당 구매 제한 수량보다 많은 수량을 입찰(구매)하려는 경우 예외가 발생
  • Loading branch information
chhs2131 committed Aug 12, 2024
1 parent 15134b0 commit e67927f
Showing 1 changed file with 83 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,31 @@ void when_change_auction_that_is_started() {
@DisplayName("경매 입찰(구매)을 진행할 때")
class submitBidTest {
@Test
@Disabled
@DisplayName("요청을 정상적으로 처리한다.")
void success_case() {
// TODO
// given
long auctionId = 1L;
long price = 10000L;
long quantity = 100L;

Auction auction = Auction.builder()
.startedAt(ZonedDateTime.now())
.finishedAt(ZonedDateTime.now().plusMinutes(10))
.sellerId(1L)
.productName("Test Product")
.originPrice(10000)
.stock(100)
.maximumPurchaseLimitCount(100)
.pricePolicy(new ConstantPricePolicy(1000))
.variationDuration(Duration.ofMinutes(1L))
.isShowStock(true)
.build();

// when
when(auctionRepository.findById(auctionId)).thenReturn(Optional.of(auction));

// then
assertThatNoException().isThrownBy(() -> auctionService.submitBid(auctionId, price, quantity));
}

@Test
Expand All @@ -233,5 +254,65 @@ void when_invalid_auction_id_should_throw_exception() {
.isInstanceOf(NotFoundException.class)
.satisfies(exception -> assertThat(exception).hasFieldOrPropertyWithValue("errorCode", ErrorCode.A011));
}

@Test
@DisplayName("경매 재고보다 많은 수량을 입찰(구매)하려는 경우 예외가 발생하고 에러 코드는 A014이다.")
void when_quantity_more_than_auction_stock_should_throw_exception() {
// given
long auctionId = 1L;
long price = 10000L;
long quantity = 100L;

Auction auction = Auction.builder()
.startedAt(ZonedDateTime.now())
.finishedAt(ZonedDateTime.now().plusMinutes(10))
.sellerId(1L)
.productName("Test Product")
.originPrice(10000)
.stock(50) // 경매 재고
.maximumPurchaseLimitCount(50)
.pricePolicy(new ConstantPricePolicy(1000))
.variationDuration(Duration.ofMinutes(1L))
.isShowStock(true)
.build();

// when
when(auctionRepository.findById(auctionId)).thenReturn(Optional.of(auction));

// then
assertThatThrownBy(() -> auctionService.submitBid(auctionId, price, quantity))
.isInstanceOf(BadRequestException.class)
.satisfies(exception -> assertThat(exception).hasFieldOrPropertyWithValue("errorCode", ErrorCode.A014));
}

@Test
@DisplayName("인당 구매 제한 수량보다 많은 수량을 입찰(구매)하려는 경우 예외가 발생하고 에러 코드는 A014이다.")
void when_quantity_more_than_maximum_pruchase_limit_should_throw_exception() {
// given
long auctionId = 1L;
long price = 10000L;
long quantity = 100L;

Auction auction = Auction.builder()
.startedAt(ZonedDateTime.now())
.finishedAt(ZonedDateTime.now().plusMinutes(10))
.sellerId(1L)
.productName("Test Product")
.originPrice(10000)
.stock(10000)
.maximumPurchaseLimitCount(10) // 인당 구매 수량 제한
.pricePolicy(new ConstantPricePolicy(1000))
.variationDuration(Duration.ofMinutes(1L))
.isShowStock(true)
.build();

// when
when(auctionRepository.findById(auctionId)).thenReturn(Optional.of(auction));

// then
assertThatThrownBy(() -> auctionService.submitBid(auctionId, price, quantity))
.isInstanceOf(BadRequestException.class)
.satisfies(exception -> assertThat(exception).hasFieldOrPropertyWithValue("errorCode", ErrorCode.A014));
}
}
}

0 comments on commit e67927f

Please sign in to comment.