refactor(test/server): refactor server-side testing

This commit is contained in:
Zhongheng Liu 2025-12-29 14:02:52 +01:00
commit 88ef77d858

View file

@ -13,6 +13,8 @@ import org.springframework.http.HttpStatus;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.test.context.ActiveProfiles;
import server.WebSocketConfig;
import server.database.IngredientRepository;
import server.database.RecipeIngredientRepository;
import server.database.RecipeRepository;
import java.util.ArrayList;
@ -45,12 +47,21 @@ public class RecipeControllerTest {
private final RecipeRepository recipeRepository;
private List<Long> recipeIds;
public static final int NUM_RECIPES = 10;
private final IngredientRepository ingredientRepository;
private final RecipeIngredientRepository recipeIngredientRepository;
// Injects a test repository into the test class
@Autowired
public RecipeControllerTest(RecipeRepository recipeRepository, SimpMessagingTemplate template) {
public RecipeControllerTest(
RecipeRepository recipeRepository,
SimpMessagingTemplate template,
IngredientRepository ingredientRepository,
RecipeIngredientRepository recipeIngredientRepository
) {
this.recipeRepository = recipeRepository;
this.template = template;
this.ingredientRepository = ingredientRepository;
this.recipeIngredientRepository = recipeIngredientRepository;
}
@BeforeEach
@ -59,7 +70,12 @@ public class RecipeControllerTest {
.range(0, NUM_RECIPES)
.mapToObj(x -> new Recipe(null, "Recipe " + x, List.of(), List.of()))
.toList();
controller = new RecipeController(recipeRepository, template);
controller = new RecipeController(
recipeRepository,
template,
ingredientRepository,
recipeIngredientRepository
);
Set<String> tags = info.getTags();
List<Long> ids = new ArrayList<>();