recipes/api/src/domain/recipe/fetch_list.rs

59 lines
2.1 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use crate::repo::recipe::RecipeRepo;
use super::types;
pub fn execute(repo: &impl RecipeRepo) -> Vec<types::Recipe> {
repo.get_recipes()
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{
domain::{misc_types::Lang, recipe::types::RecipeIngredientMeasure},
repo::recipe::InMemoryRecipeRepo,
};
#[test]
fn should_return_all_recipes() {
let repo = InMemoryRecipeRepo::new();
let res = execute(&repo);
match res.as_slice() {
[salad, pizza_base] => {
assert_eq!(salad.key, String::from("fruit_salad"));
assert_eq!(salad.lang, Lang::Rus);
assert_eq!(salad.name, String::from("Фруктовый салат"));
assert_eq!(
salad.instructions,
vec![
"Нарезать бананы кружочками",
"Нарезать яблоки и апельсины кубиками",
"Все ингредиенты перемешать",
]
);
match salad.ingredients.as_slice() {
[banana, apple, orange] => {
assert_eq!(banana.ingredient.key, "banana");
assert_eq!(banana.measure, RecipeIngredientMeasure::Gram(150));
assert_eq!(apple.ingredient.key, "apple");
assert_eq!(apple.measure, RecipeIngredientMeasure::Gram(150));
assert_eq!(orange.ingredient.key, "orange");
assert_eq!(orange.measure, RecipeIngredientMeasure::Gram(150));
}
_ => unreachable!(),
}
assert_eq!(pizza_base.key, String::from("thin_crispy_pizza_base"));
assert_eq!(pizza_base.lang, Lang::Rus);
assert_eq!(
pizza_base.name,
String::from("Тонкая хрустящая основа для пиццы")
);
}
_ => unreachable!(),
}
}
}