use cooklang_import::{
text_to_cooklang, url_to_recipe, ImportResult, RecipeComponents, 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 { content, .. } => {
assert!(!content.is_empty());
assert!(content.contains(">>"));
}
ImportResult::Components(_) => 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::Components(components) => {
assert!(!components.text.is_empty());
}
ImportResult::Cooklang { .. } => panic!("Expected Components 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 { content, .. } => {
assert!(!content.is_empty());
assert!(content.contains(">>"));
}
ImportResult::Components(_) => panic!("Expected Cooklang result"),
}
}
#[tokio::test]
#[ignore]
async fn test_convenience_url_to_recipe() {
let result = url_to_recipe("https://www.bbcgoodfood.com/recipes/classic-cottage-pie").await;
assert!(result.is_ok());
let components = result.unwrap();
assert!(!components.text.is_empty());
assert!(!components.name.is_empty());
}
#[tokio::test]
#[ignore]
async fn test_convenience_text_to_cooklang_with_content() {
let components = RecipeComponents {
text: "2 eggs\n1 cup flour\n1/2 cup milk\n\nMix all ingredients together. Bake at 350°F for 30 minutes.".to_string(),
metadata: String::new(),
name: "Simple Recipe".to_string(),
};
let result = text_to_cooklang(&components).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 { content, .. } => {
assert!(!content.is_empty());
assert!(content.contains(">>"));
}
ImportResult::Components(_) => panic!("Expected Cooklang result"),
}
}
#[tokio::test]
#[ignore]
async fn test_convenience_text_to_cooklang() {
let components = RecipeComponents {
text: "Take 2 eggs and 1 cup of flour. Mix them together and bake at 350°F for 30 minutes."
.to_string(),
metadata: String::new(),
name: String::new(),
};
let result = text_to_cooklang(&components).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]
#[ignore] async fn test_builder_text_extract_only_error() {
let result = RecipeImporter::builder()
.text("content")
.extract_only()
.build()
.await;
assert!(result.is_ok());
}
#[tokio::test]
#[ignore] async fn test_builder_empty_text_error_duplicate() {
let result = RecipeImporter::builder().text("").build().await;
assert!(result.is_ok());
}
#[tokio::test]
#[ignore] async fn test_builder_empty_text_error() {
let result = RecipeImporter::builder().text("").build().await;
assert!(result.is_ok());
}
#[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 { content, .. } => {
assert!(!content.is_empty());
assert!(content.contains(">>"));
}
ImportResult::Components(_) => panic!("Expected Cooklang result"),
}
}
#[tokio::test]
#[ignore] async fn test_builder_with_timeout_extract_only() {
use std::time::Duration;
let result = RecipeImporter::builder()
.url("https://www.bbcgoodfood.com/recipes/classic-cottage-pie")
.timeout(Duration::from_secs(30))
.extract_only()
.build()
.await;
assert!(result.is_ok());
match result.unwrap() {
ImportResult::Components(components) => {
assert!(!components.text.is_empty());
}
ImportResult::Cooklang { .. } => panic!("Expected Components result"),
}
}