From 77675884a2eeb0aab6ce57dccd2a260f5a973197 Mon Sep 17 00:00:00 2001 From: Timon Vonk Date: Sun, 23 Jun 2024 12:54:32 +0200 Subject: [PATCH] chore(transformers): improve test coverage --- swiftide/src/transformers/metadata_qa_code.rs | 26 +++++++++++++++++++ swiftide/src/transformers/metadata_qa_text.rs | 26 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/swiftide/src/transformers/metadata_qa_code.rs b/swiftide/src/transformers/metadata_qa_code.rs index e7260f7a..5fd720e7 100644 --- a/swiftide/src/transformers/metadata_qa_code.rs +++ b/swiftide/src/transformers/metadata_qa_code.rs @@ -142,3 +142,29 @@ impl Transformer for MetadataQACode { self.concurrency } } + +#[cfg(test)] +mod test { + use crate::MockSimplePrompt; + + use super::*; + + #[tokio::test] + async fn test_metadata_qacode() { + let mut client = MockSimplePrompt::new(); + + client + .expect_prompt() + .returning(|_| Ok("Q1: Hello\nA1: World".to_string())); + + let transformer = MetadataQACode::builder().client(client).build().unwrap(); + let node = IngestionNode::new("Some text"); + + let result = transformer.transform_node(node).await.unwrap(); + + assert_eq!( + result.metadata.get("Questions and Answers").unwrap(), + "Q1: Hello\nA1: World" + ); + } +} diff --git a/swiftide/src/transformers/metadata_qa_text.rs b/swiftide/src/transformers/metadata_qa_text.rs index 8ee46fe1..b33caf91 100644 --- a/swiftide/src/transformers/metadata_qa_text.rs +++ b/swiftide/src/transformers/metadata_qa_text.rs @@ -143,3 +143,29 @@ impl Transformer for MetadataQAText { self.concurrency } } + +#[cfg(test)] +mod test { + use crate::MockSimplePrompt; + + use super::*; + + #[tokio::test] + async fn test_metadata_qacode() { + let mut client = MockSimplePrompt::new(); + + client + .expect_prompt() + .returning(|_| Ok("Q1: Hello\nA1: World".to_string())); + + let transformer = MetadataQAText::builder().client(client).build().unwrap(); + let node = IngestionNode::new("Some text"); + + let result = transformer.transform_node(node).await.unwrap(); + + assert_eq!( + result.metadata.get("Questions and Answers").unwrap(), + "Q1: Hello\nA1: World" + ); + } +}