Skip to content

Commit

Permalink
#90 test : 식당이름에 맞춰 카테고리 별로 메뉴를 반환하는지 테스트 한다
Browse files Browse the repository at this point in the history
  • Loading branch information
packdev937 committed Mar 4, 2024
1 parent 2ec85c6 commit 0448a67
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/test/java/ssu/eatssu/domain/menu/service/MenuServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.ArrayList;
import java.util.List;

import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -15,7 +16,9 @@
import ssu.eatssu.domain.menu.dto.MenuResponse.MenuInformationResponse;
import ssu.eatssu.domain.menu.dto.MenuResponse.MenusInformationResponse;
import ssu.eatssu.domain.menu.entity.Menu;
import ssu.eatssu.domain.menu.entity.MenuCategory;
import ssu.eatssu.domain.menu.repository.MealRepository;
import ssu.eatssu.domain.menu.repository.MenuCategoryRepository;
import ssu.eatssu.domain.menu.repository.MenuRepository;
import ssu.eatssu.domain.restaurant.entity.Restaurant;

Expand All @@ -31,6 +34,9 @@ class MenuServiceTest {
@Autowired
private MealRepository mealRepository;

@Autowired
private MenuCategoryRepository menuCategoryRepository;

@BeforeEach
void setUp() {
menuRepository.deleteAll();
Expand All @@ -42,15 +48,26 @@ void setUp() {
// given
List<Menu> menus = new ArrayList<>();
Restaurant foodCourt = Restaurant.from("FOOD_COURT");
menus.add(Menu.createFixed("라면", foodCourt, 3000, null));
menus.add(Menu.createFixed("떡볶이", foodCourt, 5000, null));
menus.add(Menu.createFixed("짜게치", foodCourt, 4000, null));
MenuCategory category1 = MenuCategory.builder().name("분식").restaurant(foodCourt).build();
MenuCategory category2 = MenuCategory.builder().name("한식").restaurant(foodCourt).build();
menus.add(Menu.createFixed("라면", foodCourt, 3000, category1));
menus.add(Menu.createFixed("떡볶이", foodCourt, 5000, category2));
menus.add(Menu.createFixed("짜게치", foodCourt, 4000, category1));
menuCategoryRepository.save(category1);
menuCategoryRepository.save(category2);
menuRepository.saveAll(menus);

// when & then
assertThat(menuService.findMenusByRestaurant(foodCourt))
.extracting(MenuInformationResponse::getName)
.containsExactly("라면", "떡볶이", "짜게치");
// when
Map<String, List<MenuInformationResponse>> response = menuService.findMenusByRestaurant(
foodCourt);

// then
assertThat(response).hasSize(2);
for (String key : response.keySet()) {
System.out.print(key + " : ");
response.get(key).forEach(menu -> System.out.print(menu.getName() + " "));
System.out.print("\n");
}
}

@Test
Expand Down

0 comments on commit 0448a67

Please sign in to comment.