use serde_json::json;
use crate::providers::openai::streaming::extract_thinking_from_multiple_fields;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_thinking_field_priority_reasoning_content_first() {
let json_data = json!({
"role": "assistant",
"content": "Hello",
"reasoning_content": "DeepSeek thinking",
"thinking": "OpenAI thinking",
"reasoning": "Alternative reasoning"
});
let thinking = extract_thinking_from_multiple_fields(&json_data);
assert_eq!(thinking, Some("DeepSeek thinking".to_string()));
}
#[test]
fn test_thinking_field_priority_thinking_second() {
let json_data = json!({
"role": "assistant",
"content": "Hello",
"thinking": "OpenAI thinking",
"reasoning": "Alternative reasoning"
});
let thinking = extract_thinking_from_multiple_fields(&json_data);
assert_eq!(thinking, Some("OpenAI thinking".to_string()));
}
#[test]
fn test_thinking_field_priority_reasoning_third() {
let json_data = json!({
"role": "assistant",
"content": "Hello",
"reasoning": "Alternative reasoning"
});
let thinking = extract_thinking_from_multiple_fields(&json_data);
assert_eq!(thinking, Some("Alternative reasoning".to_string()));
}
#[test]
fn test_thinking_field_priority_empty_fields_ignored() {
let json_data = json!({
"role": "assistant",
"content": "Hello",
"reasoning_content": "",
"thinking": " ", "reasoning": "Alternative reasoning"
});
let thinking = extract_thinking_from_multiple_fields(&json_data);
assert_eq!(thinking, Some("Alternative reasoning".to_string()));
}
#[test]
fn test_thinking_field_priority_no_thinking_fields() {
let json_data = json!({
"role": "assistant",
"content": "Hello"
});
let thinking = extract_thinking_from_multiple_fields(&json_data);
assert_eq!(thinking, None);
}
#[test]
fn test_thinking_field_priority_null_values_ignored() {
let json_data = json!({
"role": "assistant",
"content": "Hello",
"reasoning_content": null,
"thinking": "OpenAI thinking",
"reasoning": "Alternative reasoning"
});
let thinking = extract_thinking_from_multiple_fields(&json_data);
assert_eq!(thinking, Some("OpenAI thinking".to_string()));
}
#[test]
fn test_thinking_field_priority_non_string_values_ignored() {
let json_data = json!({
"role": "assistant",
"content": "Hello",
"reasoning_content": 123,
"thinking": ["array", "value"],
"reasoning": "Alternative reasoning"
});
let thinking = extract_thinking_from_multiple_fields(&json_data);
assert_eq!(thinking, Some("Alternative reasoning".to_string()));
}
}