From d88f38cdeb7e20d9e189a5d39f250cd96b58bc85 Mon Sep 17 00:00:00 2001 From: june-777 Date: Wed, 14 Aug 2024 20:24:59 +0900 Subject: [PATCH] =?UTF-8?q?[test]=20merge=20=EA=B3=BC=EC=A0=95=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EA=B9=A8=EC=A7=80=EB=8A=94=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MenuCategoryRepositoryTest.java | 20 +++++++++++++++++-- .../StoreMenuRegistrationServiceTest.java | 15 ++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/test/java/camp/woowak/lab/menu/repository/MenuCategoryRepositoryTest.java b/src/test/java/camp/woowak/lab/menu/repository/MenuCategoryRepositoryTest.java index a20df6a5..37b7ceb5 100644 --- a/src/test/java/camp/woowak/lab/menu/repository/MenuCategoryRepositoryTest.java +++ b/src/test/java/camp/woowak/lab/menu/repository/MenuCategoryRepositoryTest.java @@ -12,6 +12,8 @@ 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; @@ -19,6 +21,8 @@ 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 { @@ -35,6 +39,9 @@ class MenuCategoryRepositoryTest { @Autowired StoreCategoryRepository storeCategoryRepository; + @Autowired + PayAccountRepository payAccountRepository; + @Nested @DisplayName("가게와 메뉴카테고리 이름으로 메뉴카테고리를 조회하는 기능은") class FindByStoreAndNameTest { @@ -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); @@ -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); @@ -120,4 +130,10 @@ private Store createStore(Vendor vendor, StoreCategory storeCategory) { ); } + private Vendor createVendor(PayAccount payAccount) { + PasswordEncoder passwordEncoder = new NoOpPasswordEncoder(); + return new Vendor("vendorName", "vendorEmail@example.com", "vendorPassword", "010-0000-0000", payAccount, + passwordEncoder); + } + } \ No newline at end of file diff --git a/src/test/java/camp/woowak/lab/store/service/StoreMenuRegistrationServiceTest.java b/src/test/java/camp/woowak/lab/store/service/StoreMenuRegistrationServiceTest.java index 7f9256ee..afd1801e 100644 --- a/src/test/java/camp/woowak/lab/store/service/StoreMenuRegistrationServiceTest.java +++ b/src/test/java/camp/woowak/lab/store/service/StoreMenuRegistrationServiceTest.java @@ -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 { @@ -47,7 +51,7 @@ class StoreMenuRegistrationServiceTest { @DisplayName("[Success] 메뉴 등록 성공") void storeMenuRegistrationSuccess() { // given - Vendor owner = new Vendor(); + Vendor owner = createVendor(); List menuItems = List.of( new StoreMenuRegistrationRequest.MenuLineItem("메뉴1", "image1.jpg", "카테고리1", 10000) ); @@ -70,7 +74,7 @@ void storeMenuRegistrationSuccess() { @DisplayName("[Exception] 존재하지 않는 가게") void storeMenuRegistrationStoreNotFound() { // given - Vendor owner = new Vendor(); + Vendor owner = createVendor(); List menuItems = List.of( new StoreMenuRegistrationRequest.MenuLineItem("메뉴1", "image1.jpg", "카테고리1", 10000) ); @@ -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", "vendorEmail@example.com", "vendorPassword", "010-0000-0000", payAccount, + passwordEncoder); + } } \ No newline at end of file