From 20d741b36924836f1a0e9a05fee9599c0b4c5c93 Mon Sep 17 00:00:00 2001 From: mulla028 Date: Tue, 12 Nov 2024 22:04:37 -0500 Subject: [PATCH 1/2] Unit test test_build_request_body() added --- src/api/chat_completions.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/api/chat_completions.rs b/src/api/chat_completions.rs index 30a5974..5c7dd09 100644 --- a/src/api/chat_completions.rs +++ b/src/api/chat_completions.rs @@ -77,8 +77,10 @@ impl Instance { #[cfg(test)] mod tests { + use std::path::PathBuf; use super::*; use httpmock::prelude::*; + use crate::read_words_from_file; #[tokio::test] async fn test_post_chat_completions() { @@ -104,4 +106,39 @@ mod tests { .unwrap(); mock.assert(); } + + #[test] + fn test_build_request_body() { + // Mock input data + let link_words = vec!["link1".to_string(), "link2".to_string()]; + let avoid_words = vec!["avoid1".to_string(), "avoid2".to_string()]; + let model_id = "model".to_string(); + + // Assign result to the result of build_request_body() method + let result = Instance::build_request_body(&link_words, &avoid_words, &model_id); + + // Format expected content + let expected_content = format!( + "To Link:\n{}\n\nTo Avoid:\n{}", + link_words.join("\n"), + avoid_words.join("\n") + ); + + // Mock expected output + let expected = json!( + { + "messages": [ + { + "role": "system", + "content": SYSTEM_PROMPT, + }, + { + "role": "user", + "content": expected_content + } + ], + "model": model_id + }); + assert_eq!(expected, result); + } } From c0eb05182310b18039fb6e81884178c8ed36ee05 Mon Sep 17 00:00:00 2001 From: mulla028 Date: Tue, 12 Nov 2024 22:11:35 -0500 Subject: [PATCH 2/2] Linter applied --- src/api/chat_completions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/chat_completions.rs b/src/api/chat_completions.rs index 5c7dd09..a78df05 100644 --- a/src/api/chat_completions.rs +++ b/src/api/chat_completions.rs @@ -77,10 +77,10 @@ impl Instance { #[cfg(test)] mod tests { - use std::path::PathBuf; use super::*; - use httpmock::prelude::*; use crate::read_words_from_file; + use httpmock::prelude::*; + use std::path::PathBuf; #[tokio::test] async fn test_post_chat_completions() {