Skip to content

Commit

Permalink
fix: 원 가격이 없는 경우 n빵 가격을 비교하지 않도록 변경 (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
fromitive authored Aug 8, 2024
1 parent c3062fa commit e2dcb84
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public double calculateDiscountRate() {

public void validateOriginPrice() {
int dividedPrice = totalPrice / totalCount;
if (originPrice < dividedPrice) {
if (originPrice != null && originPrice < dividedPrice) {
throw new MarketException(OfferingErrorCode.CANNOT_ORIGIN_PRICE_LESS_THEN_DIVIDED_PRICE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void setUp() {
member = memberFixture.createMember();
}

@DisplayName("공모 정보를 받아 공모를 작성합니다")
@DisplayName("공모 정보를 받아 공모를 작성 할 수 있다.")
@Test
void should_createOffering_when_givenOfferingCreateRequest() {
OfferingSaveRequest request = new OfferingSaveRequest(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.zzang.chongdae.offering.service;

import com.zzang.chongdae.global.integration.IntegrationTest;
import com.zzang.chongdae.member.repository.entity.MemberEntity;
import com.zzang.chongdae.offering.service.dto.OfferingSaveRequest;
import java.time.LocalDateTime;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

// TODO: service 테스트 환경도 IntegrationTest 동일하게 적용하지 않을 경우 data.sql 정보가 db에 저장됨
public class OfferingServiceTest extends IntegrationTest {

@Autowired
OfferingService offeringService;

@DisplayName("공목 등록 시 원 가격 정보가 없더라도 공모 작성에 성공할 수 있다.")
@Test
void should_createOffering_when_givenOfferingWithoutOriginPriceCreateRequest() {

// given
MemberEntity member = memberFixture.createMember("pizza");
OfferingSaveRequest request = new OfferingSaveRequest(
"공모 제목",
"www.naver.com",
"www.naver.com/favicon.ico",
5,
10000,
null,
"서울특별시 광진구 구의강변로 3길 11",
"상세주소아파트",
"구의동",
LocalDateTime.parse("2024-10-11T10:00:00"),
"내용입니다."
);
Long expected = 1L;

// when
Long actual = offeringService.saveOffering(request, member);

// then
Assertions.assertEquals(expected, actual);
}
}

0 comments on commit e2dcb84

Please sign in to comment.