Skip to content

Commit

Permalink
[test] merge 과정에서 깨지는 테스트코드 수정 및 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
june-777 committed Aug 14, 2024
1 parent 2f11b07 commit d88f38c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@

import camp.woowak.lab.infra.date.DateTimeProvider;
import camp.woowak.lab.menu.domain.MenuCategory;
import camp.woowak.lab.payaccount.domain.PayAccount;
import camp.woowak.lab.payaccount.repository.PayAccountRepository;
import camp.woowak.lab.store.domain.Store;
import camp.woowak.lab.store.domain.StoreAddress;
import camp.woowak.lab.store.domain.StoreCategory;
import camp.woowak.lab.store.repository.StoreCategoryRepository;
import camp.woowak.lab.store.repository.StoreRepository;
import camp.woowak.lab.vendor.domain.Vendor;
import camp.woowak.lab.vendor.repository.VendorRepository;
import camp.woowak.lab.web.authentication.NoOpPasswordEncoder;
import camp.woowak.lab.web.authentication.PasswordEncoder;

@DataJpaTest
class MenuCategoryRepositoryTest {
Expand All @@ -35,6 +39,9 @@ class MenuCategoryRepositoryTest {
@Autowired
StoreCategoryRepository storeCategoryRepository;

@Autowired
PayAccountRepository payAccountRepository;

@Nested
@DisplayName("가게와 메뉴카테고리 이름으로 메뉴카테고리를 조회하는 기능은")
class FindByStoreAndNameTest {
Expand All @@ -43,7 +50,9 @@ class FindByStoreAndNameTest {
@DisplayName("[Success] 가게와 메뉴카테고리 이름이 있으면 조회를 성공한다")
void success() {
// given
Vendor vendor = new Vendor();
PayAccount payAccount = payAccountRepository.save(new PayAccount());

Vendor vendor = createVendor(payAccount);
String categoryName = "돈가스";
StoreCategory storeCategory = new StoreCategory(categoryName);

Expand Down Expand Up @@ -77,8 +86,9 @@ void notExistMenuCategoryName() {
// given
String categoryName = "돈가스";
String notExistCategoryName = "xxx";
PayAccount payAccount = payAccountRepository.save(new PayAccount());

Vendor vendor = new Vendor();
Vendor vendor = createVendor(payAccount);
vendorRepository.saveAndFlush(vendor);

StoreCategory storeCategory = new StoreCategory(categoryName);
Expand Down Expand Up @@ -120,4 +130,10 @@ private Store createStore(Vendor vendor, StoreCategory storeCategory) {
);
}

private Vendor createVendor(PayAccount payAccount) {
PasswordEncoder passwordEncoder = new NoOpPasswordEncoder();
return new Vendor("vendorName", "[email protected]", "vendorPassword", "010-0000-0000", payAccount,
passwordEncoder);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
import camp.woowak.lab.menu.domain.MenuCategory;
import camp.woowak.lab.menu.repository.MenuCategoryRepository;
import camp.woowak.lab.menu.repository.MenuRepository;
import camp.woowak.lab.payaccount.domain.PayAccount;
import camp.woowak.lab.payaccount.domain.TestPayAccount;
import camp.woowak.lab.store.domain.Store;
import camp.woowak.lab.store.domain.StoreAddress;
import camp.woowak.lab.store.exception.NotFoundStoreException;
import camp.woowak.lab.store.repository.StoreRepository;
import camp.woowak.lab.store.service.dto.StoreMenuRegistrationRequest;
import camp.woowak.lab.vendor.domain.Vendor;
import camp.woowak.lab.web.authentication.NoOpPasswordEncoder;
import camp.woowak.lab.web.authentication.PasswordEncoder;

@ExtendWith(MockitoExtension.class)
class StoreMenuRegistrationServiceTest {
Expand All @@ -47,7 +51,7 @@ class StoreMenuRegistrationServiceTest {
@DisplayName("[Success] 메뉴 등록 성공")
void storeMenuRegistrationSuccess() {
// given
Vendor owner = new Vendor();
Vendor owner = createVendor();
List<StoreMenuRegistrationRequest.MenuLineItem> menuItems = List.of(
new StoreMenuRegistrationRequest.MenuLineItem("메뉴1", "image1.jpg", "카테고리1", 10000)
);
Expand All @@ -70,7 +74,7 @@ void storeMenuRegistrationSuccess() {
@DisplayName("[Exception] 존재하지 않는 가게")
void storeMenuRegistrationStoreNotFound() {
// given
Vendor owner = new Vendor();
Vendor owner = createVendor();
List<StoreMenuRegistrationRequest.MenuLineItem> menuItems = List.of(
new StoreMenuRegistrationRequest.MenuLineItem("메뉴1", "image1.jpg", "카테고리1", 10000)
);
Expand Down Expand Up @@ -99,4 +103,11 @@ private Store createValidStore() {
private MenuCategory createValidMenuCategory() {
return new MenuCategory(storeFixture, "1234567890");
}

private Vendor createVendor() {
PayAccount payAccount = new TestPayAccount(1L);
PasswordEncoder passwordEncoder = new NoOpPasswordEncoder();
return new Vendor("vendorName", "[email protected]", "vendorPassword", "010-0000-0000", payAccount,
passwordEncoder);
}
}

0 comments on commit d88f38c

Please sign in to comment.