use cooklang_import::{
convert_text_to_cooklang, extract_recipe_from_url, import_from_url, ImportResult,
RecipeImporter,
};
#[tokio::test]
#[ignore]
async fn test_builder_url_to_cooklang() {
let result = RecipeImporter::builder()
.url("https://www.bbcgoodfood.com/recipes/classic-cottage-pie")
.build()
.await;
assert!(result.is_ok());
match result.unwrap() {
ImportResult::Cooklang(cooklang) => {
assert!(!cooklang.is_empty());
assert!(cooklang.contains(">>"));
}
ImportResult::Recipe(_) => panic!("Expected Cooklang result"),
}
}
#[tokio::test]
#[ignore]
async fn test_builder_url_to_recipe() {
let result = RecipeImporter::builder()
.url("https://www.bbcgoodfood.com/recipes/classic-cottage-pie")
.extract_only()
.build()
.await;
assert!(result.is_ok());
match result.unwrap() {
ImportResult::Recipe(recipe) => {
assert!(!recipe.content.is_empty());
}
ImportResult::Cooklang(_) => panic!("Expected Recipe result"),
}
}
#[tokio::test]
#[ignore]
async fn test_builder_content_to_cooklang() {
let content = "2 eggs\n1 cup flour\n1/2 cup milk\n\nMix all ingredients together. Bake at 350°F for 30 minutes.";
let result = RecipeImporter::builder().text(content).build().await;
assert!(result.is_ok());
match result.unwrap() {
ImportResult::Cooklang(cooklang) => {
assert!(!cooklang.is_empty());
assert!(cooklang.contains(">>"));
}
ImportResult::Recipe(_) => panic!("Expected Cooklang result"),
}
}
#[tokio::test]
#[ignore]
async fn test_convenience_import_from_url() {
let result = import_from_url("https://www.bbcgoodfood.com/recipes/classic-cottage-pie").await;
assert!(result.is_ok());
let cooklang = result.unwrap();
assert!(!cooklang.is_empty());
assert!(cooklang.contains(">>"));
}
#[tokio::test]
#[ignore]
async fn test_convenience_extract_recipe_from_url() {
let result =
extract_recipe_from_url("https://www.bbcgoodfood.com/recipes/classic-cottage-pie").await;
assert!(result.is_ok());
let recipe = result.unwrap();
assert!(!recipe.content.is_empty());
}
#[tokio::test]
#[ignore]
async fn test_convenience_convert_text_to_cooklang_with_content() {
let content = "2 eggs\n1 cup flour\n1/2 cup milk\n\nMix all ingredients together. Bake at 350°F for 30 minutes.";
let result = convert_text_to_cooklang(content).await;
assert!(result.is_ok());
let cooklang = result.unwrap();
assert!(!cooklang.is_empty());
assert!(cooklang.contains(">>"));
}
#[tokio::test]
#[ignore]
async fn test_builder_text_to_cooklang() {
let recipe_text =
"Take 2 eggs and 1 cup of flour. Mix them together and bake at 350°F for 30 minutes.";
let result = RecipeImporter::builder().text(recipe_text).build().await;
assert!(result.is_ok());
match result.unwrap() {
ImportResult::Cooklang(cooklang) => {
assert!(!cooklang.is_empty());
assert!(cooklang.contains(">>"));
}
ImportResult::Recipe(_) => panic!("Expected Cooklang result"),
}
}
#[tokio::test]
#[ignore]
async fn test_convenience_convert_text_to_cooklang() {
use cooklang_import::convert_text_to_cooklang;
let recipe_text =
"Take 2 eggs and 1 cup of flour. Mix them together and bake at 350°F for 30 minutes.";
let result = convert_text_to_cooklang(recipe_text).await;
assert!(result.is_ok());
let cooklang = result.unwrap();
assert!(!cooklang.is_empty());
assert!(cooklang.contains(">>"));
}
#[tokio::test]
async fn test_builder_no_source_error() {
let result = RecipeImporter::builder().build().await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("No input source specified"));
}
#[tokio::test]
async fn test_builder_text_extract_only_error() {
let result = RecipeImporter::builder()
.text("content")
.extract_only()
.build()
.await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err
.to_string()
.contains("Cannot use extract_only() with text input"));
}
#[tokio::test]
async fn test_builder_empty_text_error_duplicate() {
let result = RecipeImporter::builder().text("").build().await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("Recipe text cannot be empty"));
}
#[tokio::test]
async fn test_builder_empty_text_error() {
let result = RecipeImporter::builder().text("").build().await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("Recipe text cannot be empty"));
}
#[tokio::test]
async fn test_builder_method_chaining() {
use cooklang_import::LlmProvider;
use std::time::Duration;
let builder = RecipeImporter::builder()
.url("https://example.com/recipe")
.provider(LlmProvider::OpenAI)
.timeout(Duration::from_secs(30));
assert!(std::mem::size_of_val(&builder) > 0);
}
#[tokio::test]
#[ignore] async fn test_builder_with_short_timeout() {
use std::time::Duration;
let result = RecipeImporter::builder()
.url("https://www.bbcgoodfood.com/recipes/classic-cottage-pie")
.timeout(Duration::from_millis(1))
.build()
.await;
assert!(result.is_err());
}
#[tokio::test]
#[ignore] async fn test_builder_with_anthropic_provider() {
use cooklang_import::LlmProvider;
let result = RecipeImporter::builder()
.url("https://www.bbcgoodfood.com/recipes/classic-cottage-pie")
.provider(LlmProvider::Anthropic)
.build()
.await;
assert!(result.is_ok());
match result.unwrap() {
ImportResult::Cooklang(cooklang) => {
assert!(!cooklang.is_empty());
assert!(cooklang.contains(">>"));
}
ImportResult::Recipe(_) => panic!("Expected Cooklang result"),
}
}
#[tokio::test]
#[ignore] async fn test_fetch_recipe_with_timeout() {
use std::time::Duration;
let result = cooklang_import::fetch_recipe_with_timeout(
"https://www.bbcgoodfood.com/recipes/classic-cottage-pie",
Some(Duration::from_secs(30)),
)
.await;
assert!(result.is_ok());
let recipe = result.unwrap();
assert!(!recipe.content.is_empty());
}
#[tokio::test]
#[ignore] async fn test_convert_recipe_with_provider() {
use cooklang_import::{convert_recipe_with_provider, Recipe};
let recipe = Recipe {
name: "Test Recipe".to_string(),
content: "2 eggs\n1 cup flour\n\nMix and bake".to_string(),
..Default::default()
};
let result = convert_recipe_with_provider(&recipe, None).await;
assert!(result.is_ok());
let result = convert_recipe_with_provider(&recipe, Some("openai")).await;
assert!(result.is_ok());
}