Skip to content

Commit

Permalink
Unit test test_build_request_body() added
Browse files Browse the repository at this point in the history
  • Loading branch information
mulla028 committed Nov 13, 2024
1 parent ea80435 commit 20d741b
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/api/chat_completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
}
}

0 comments on commit 20d741b

Please sign in to comment.