test: update fixtures and mocks
This commit is contained in:
parent
dc3f67ca87
commit
f6f4e5d2e4
7 changed files with 56 additions and 58 deletions
|
|
@ -220,30 +220,30 @@ pub fn openai_embedding_response(dimensions: usize) -> Value {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn sample_kb_entries() -> Vec<KBEntry> {
|
pub fn sample_kb_entries() -> Vec<KbEntry> {
|
||||||
vec![
|
vec![
|
||||||
KBEntry {
|
KbEntry {
|
||||||
id: "kb-001".to_string(),
|
id: "kb-001".to_string(),
|
||||||
title: "Product Overview".to_string(),
|
title: "Product Overview".to_string(),
|
||||||
content: "Our product is a comprehensive solution for business automation.".to_string(),
|
content: "Our product is a comprehensive solution for business automation.".to_string(),
|
||||||
category: Some("products".to_string()),
|
category: Some("products".to_string()),
|
||||||
tags: vec!["product".to_string(), "overview".to_string()],
|
tags: vec!["product".to_string(), "overview".to_string()],
|
||||||
},
|
},
|
||||||
KBEntry {
|
KbEntry {
|
||||||
id: "kb-002".to_string(),
|
id: "kb-002".to_string(),
|
||||||
title: "Pricing Plans".to_string(),
|
title: "Pricing Plans".to_string(),
|
||||||
content: "We offer three pricing plans: Basic ($29/mo), Pro ($79/mo), and Enterprise (custom).".to_string(),
|
content: "We offer three pricing plans: Basic ($29/mo), Pro ($79/mo), and Enterprise (custom).".to_string(),
|
||||||
category: Some("pricing".to_string()),
|
category: Some("pricing".to_string()),
|
||||||
tags: vec!["pricing".to_string(), "plans".to_string()],
|
tags: vec!["pricing".to_string(), "plans".to_string()],
|
||||||
},
|
},
|
||||||
KBEntry {
|
KbEntry {
|
||||||
id: "kb-003".to_string(),
|
id: "kb-003".to_string(),
|
||||||
title: "Support Hours".to_string(),
|
title: "Support Hours".to_string(),
|
||||||
content: "Our support team is available 24/7 for Enterprise customers and 9-5 EST for other plans.".to_string(),
|
content: "Our support team is available 24/7 for Enterprise customers and 9-5 EST for other plans.".to_string(),
|
||||||
category: Some("support".to_string()),
|
category: Some("support".to_string()),
|
||||||
tags: vec!["support".to_string(), "hours".to_string()],
|
tags: vec!["support".to_string(), "hours".to_string()],
|
||||||
},
|
},
|
||||||
KBEntry {
|
KbEntry {
|
||||||
id: "kb-004".to_string(),
|
id: "kb-004".to_string(),
|
||||||
title: "Return Policy".to_string(),
|
title: "Return Policy".to_string(),
|
||||||
content: "We offer a 30-day money-back guarantee on all plans. No questions asked.".to_string(),
|
content: "We offer a 30-day money-back guarantee on all plans. No questions asked.".to_string(),
|
||||||
|
|
@ -254,7 +254,7 @@ pub fn sample_kb_entries() -> Vec<KBEntry> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct KBEntry {
|
pub struct KbEntry {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub content: String,
|
pub content: String,
|
||||||
|
|
@ -303,27 +303,27 @@ pub struct Product {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn sample_faqs() -> Vec<FAQ> {
|
pub fn sample_faqs() -> Vec<Faq> {
|
||||||
vec![
|
vec![
|
||||||
FAQ {
|
Faq {
|
||||||
id: 1,
|
id: 1,
|
||||||
question: "How do I reset my password?".to_string(),
|
question: "How do I reset my password?".to_string(),
|
||||||
answer: "You can reset your password by clicking 'Forgot Password' on the login page.".to_string(),
|
answer: "You can reset your password by clicking 'Forgot Password' on the login page.".to_string(),
|
||||||
category: "account".to_string(),
|
category: "account".to_string(),
|
||||||
},
|
},
|
||||||
FAQ {
|
Faq {
|
||||||
id: 2,
|
id: 2,
|
||||||
question: "What payment methods do you accept?".to_string(),
|
question: "What payment methods do you accept?".to_string(),
|
||||||
answer: "We accept all major credit cards, PayPal, and bank transfers.".to_string(),
|
answer: "We accept all major credit cards, PayPal, and bank transfers.".to_string(),
|
||||||
category: "billing".to_string(),
|
category: "billing".to_string(),
|
||||||
},
|
},
|
||||||
FAQ {
|
Faq {
|
||||||
id: 3,
|
id: 3,
|
||||||
question: "How do I contact support?".to_string(),
|
question: "How do I contact support?".to_string(),
|
||||||
answer: "You can reach our support team via email at support@example.com or through live chat.".to_string(),
|
answer: "You can reach our support team via email at support@example.com or through live chat.".to_string(),
|
||||||
category: "support".to_string(),
|
category: "support".to_string(),
|
||||||
},
|
},
|
||||||
FAQ {
|
Faq {
|
||||||
id: 4,
|
id: 4,
|
||||||
question: "Can I cancel my subscription?".to_string(),
|
question: "Can I cancel my subscription?".to_string(),
|
||||||
answer: "Yes, you can cancel your subscription at any time from your account settings.".to_string(),
|
answer: "Yes, you can cancel your subscription at any time from your account settings.".to_string(),
|
||||||
|
|
@ -333,8 +333,7 @@ pub fn sample_faqs() -> Vec<FAQ> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
#[allow(clippy::upper_case_acronyms)]
|
pub struct Faq {
|
||||||
pub struct FAQ {
|
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub question: String,
|
pub question: String,
|
||||||
pub answer: String,
|
pub answer: String,
|
||||||
|
|
|
||||||
|
|
@ -74,16 +74,15 @@ impl Default for Customer {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
#[allow(clippy::upper_case_acronyms)]
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum Channel {
|
pub enum Channel {
|
||||||
#[default]
|
#[default]
|
||||||
WhatsApp,
|
WhatsApp,
|
||||||
Teams,
|
Teams,
|
||||||
Web,
|
Web,
|
||||||
SMS,
|
Sms,
|
||||||
Email,
|
Email,
|
||||||
API,
|
Api,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,11 +90,13 @@ struct ChatChoice {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[allow(clippy::struct_field_names)]
|
|
||||||
struct Usage {
|
struct Usage {
|
||||||
prompt_tokens: u32,
|
#[serde(rename = "prompt_tokens")]
|
||||||
completion_tokens: u32,
|
pub prompt: u32,
|
||||||
total_tokens: u32,
|
#[serde(rename = "completion_tokens")]
|
||||||
|
pub completion: u32,
|
||||||
|
#[serde(rename = "total_tokens")]
|
||||||
|
pub total: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|
@ -127,8 +129,10 @@ struct EmbeddingData {
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct EmbeddingUsage {
|
struct EmbeddingUsage {
|
||||||
prompt_tokens: u32,
|
#[serde(rename = "prompt_tokens")]
|
||||||
total_tokens: u32,
|
pub prompt: u32,
|
||||||
|
#[serde(rename = "total_tokens")]
|
||||||
|
pub total: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
|
@ -249,9 +253,9 @@ impl MockLLM {
|
||||||
finish_reason: "stop".to_string(),
|
finish_reason: "stop".to_string(),
|
||||||
}],
|
}],
|
||||||
usage: Usage {
|
usage: Usage {
|
||||||
prompt_tokens: 10,
|
prompt: 10,
|
||||||
completion_tokens: 20,
|
completion: 20,
|
||||||
total_tokens: 30,
|
total: 30,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -399,9 +403,9 @@ impl MockLLM {
|
||||||
finish_reason: "tool_calls".to_string(),
|
finish_reason: "tool_calls".to_string(),
|
||||||
}],
|
}],
|
||||||
usage: Usage {
|
usage: Usage {
|
||||||
prompt_tokens: 10,
|
prompt: 10,
|
||||||
completion_tokens: 20,
|
completion: 20,
|
||||||
total_tokens: 30,
|
total: 30,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -426,8 +430,8 @@ impl MockLLM {
|
||||||
}],
|
}],
|
||||||
model: "text-embedding-ada-002".to_string(),
|
model: "text-embedding-ada-002".to_string(),
|
||||||
usage: EmbeddingUsage {
|
usage: EmbeddingUsage {
|
||||||
prompt_tokens: 5,
|
prompt: 5,
|
||||||
total_tokens: 5,
|
total: 5,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -448,8 +452,8 @@ impl MockLLM {
|
||||||
}],
|
}],
|
||||||
model: "text-embedding-ada-002".to_string(),
|
model: "text-embedding-ada-002".to_string(),
|
||||||
usage: EmbeddingUsage {
|
usage: EmbeddingUsage {
|
||||||
prompt_tokens: 5,
|
prompt: 5,
|
||||||
total_tokens: 5,
|
total: 5,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -558,9 +562,9 @@ impl MockLLM {
|
||||||
finish_reason: "stop".to_string(),
|
finish_reason: "stop".to_string(),
|
||||||
}],
|
}],
|
||||||
usage: Usage {
|
usage: Usage {
|
||||||
prompt_tokens: 10,
|
prompt: 10,
|
||||||
completion_tokens: 20,
|
completion: 20,
|
||||||
total_tokens: 30,
|
total: 30,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -666,9 +670,9 @@ mod tests {
|
||||||
finish_reason: "stop".to_string(),
|
finish_reason: "stop".to_string(),
|
||||||
}],
|
}],
|
||||||
usage: Usage {
|
usage: Usage {
|
||||||
prompt_tokens: 10,
|
prompt: 10,
|
||||||
completion_tokens: 5,
|
completion: 5,
|
||||||
total_tokens: 15,
|
total: 15,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,9 @@ pub struct MockTeams {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[allow(clippy::struct_field_names)]
|
|
||||||
pub struct Activity {
|
pub struct Activity {
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub activity_type: String,
|
pub kind: String,
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub timestamp: String,
|
pub timestamp: String,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
|
@ -59,7 +58,7 @@ pub struct Activity {
|
||||||
impl Default for Activity {
|
impl Default for Activity {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
activity_type: "message".to_string(),
|
kind: "message".to_string(),
|
||||||
id: Uuid::new_v4().to_string(),
|
id: Uuid::new_v4().to_string(),
|
||||||
timestamp: chrono::Utc::now().to_rfc3339(),
|
timestamp: chrono::Utc::now().to_rfc3339(),
|
||||||
local_timestamp: None,
|
local_timestamp: None,
|
||||||
|
|
@ -124,10 +123,9 @@ pub struct Attachment {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[allow(clippy::struct_field_names)]
|
|
||||||
pub struct Entity {
|
pub struct Entity {
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub entity_type: String,
|
pub kind: String,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub mentioned: Option<ChannelAccount>,
|
pub mentioned: Option<ChannelAccount>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
|
@ -292,7 +290,7 @@ impl MockTeams {
|
||||||
let body: serde_json::Value = req.body_json().unwrap_or_default();
|
let body: serde_json::Value = req.body_json().unwrap_or_default();
|
||||||
|
|
||||||
let activity = Activity {
|
let activity = Activity {
|
||||||
activity_type: body
|
kind: body
|
||||||
.get("type")
|
.get("type")
|
||||||
.and_then(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.unwrap_or("message")
|
.unwrap_or("message")
|
||||||
|
|
@ -433,7 +431,7 @@ impl MockTeams {
|
||||||
let conversation_id = format!("conv-{}", Uuid::new_v4());
|
let conversation_id = format!("conv-{}", Uuid::new_v4());
|
||||||
|
|
||||||
Activity {
|
Activity {
|
||||||
activity_type: "message".to_string(),
|
kind: "message".to_string(),
|
||||||
id: Uuid::new_v4().to_string(),
|
id: Uuid::new_v4().to_string(),
|
||||||
timestamp: chrono::Utc::now().to_rfc3339(),
|
timestamp: chrono::Utc::now().to_rfc3339(),
|
||||||
local_timestamp: Some(chrono::Utc::now().to_rfc3339()),
|
local_timestamp: Some(chrono::Utc::now().to_rfc3339()),
|
||||||
|
|
@ -483,7 +481,7 @@ impl MockTeams {
|
||||||
activity.text = Some(format!("{mention_text} {text}"));
|
activity.text = Some(format!("{mention_text} {text}"));
|
||||||
|
|
||||||
activity.entities = Some(vec![Entity {
|
activity.entities = Some(vec![Entity {
|
||||||
entity_type: "mention".to_string(),
|
kind: "mention".to_string(),
|
||||||
mentioned: Some(ChannelAccount {
|
mentioned: Some(ChannelAccount {
|
||||||
id: self.bot_id.clone(),
|
id: self.bot_id.clone(),
|
||||||
name: Some(self.bot_name.clone()),
|
name: Some(self.bot_name.clone()),
|
||||||
|
|
@ -502,7 +500,7 @@ impl MockTeams {
|
||||||
let conversation_id = format!("conv-{}", Uuid::new_v4());
|
let conversation_id = format!("conv-{}", Uuid::new_v4());
|
||||||
|
|
||||||
Activity {
|
Activity {
|
||||||
activity_type: "conversationUpdate".to_string(),
|
kind: "conversationUpdate".to_string(),
|
||||||
id: Uuid::new_v4().to_string(),
|
id: Uuid::new_v4().to_string(),
|
||||||
timestamp: chrono::Utc::now().to_rfc3339(),
|
timestamp: chrono::Utc::now().to_rfc3339(),
|
||||||
local_timestamp: None,
|
local_timestamp: None,
|
||||||
|
|
@ -556,7 +554,7 @@ impl MockTeams {
|
||||||
let conversation_id = format!("conv-{}", Uuid::new_v4());
|
let conversation_id = format!("conv-{}", Uuid::new_v4());
|
||||||
|
|
||||||
Activity {
|
Activity {
|
||||||
activity_type: "invoke".to_string(),
|
kind: "invoke".to_string(),
|
||||||
id: Uuid::new_v4().to_string(),
|
id: Uuid::new_v4().to_string(),
|
||||||
timestamp: chrono::Utc::now().to_rfc3339(),
|
timestamp: chrono::Utc::now().to_rfc3339(),
|
||||||
local_timestamp: None,
|
local_timestamp: None,
|
||||||
|
|
@ -630,7 +628,7 @@ impl MockTeams {
|
||||||
let conversation_id = format!("conv-{}", Uuid::new_v4());
|
let conversation_id = format!("conv-{}", Uuid::new_v4());
|
||||||
|
|
||||||
Activity {
|
Activity {
|
||||||
activity_type: "messageReaction".to_string(),
|
kind: "messageReaction".to_string(),
|
||||||
id: Uuid::new_v4().to_string(),
|
id: Uuid::new_v4().to_string(),
|
||||||
timestamp: chrono::Utc::now().to_rfc3339(),
|
timestamp: chrono::Utc::now().to_rfc3339(),
|
||||||
local_timestamp: None,
|
local_timestamp: None,
|
||||||
|
|
@ -831,7 +829,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_activity_default() {
|
fn test_activity_default() {
|
||||||
let activity = Activity::default();
|
let activity = Activity::default();
|
||||||
assert_eq!(activity.activity_type, "message");
|
assert_eq!(activity.kind, "message");
|
||||||
assert_eq!(activity.channel_id, "msteams");
|
assert_eq!(activity.channel_id, "msteams");
|
||||||
assert!(!activity.id.is_empty());
|
assert!(!activity.id.is_empty());
|
||||||
}
|
}
|
||||||
|
|
@ -839,7 +837,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_activity_serialization() {
|
fn test_activity_serialization() {
|
||||||
let activity = Activity {
|
let activity = Activity {
|
||||||
activity_type: "message".to_string(),
|
kind: "message".to_string(),
|
||||||
id: "test-id".to_string(),
|
id: "test-id".to_string(),
|
||||||
timestamp: "2024-01-01T00:00:00Z".to_string(),
|
timestamp: "2024-01-01T00:00:00Z".to_string(),
|
||||||
local_timestamp: None,
|
local_timestamp: None,
|
||||||
|
|
@ -910,7 +908,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_entity_mention() {
|
fn test_entity_mention() {
|
||||||
let entity = Entity {
|
let entity = Entity {
|
||||||
entity_type: "mention".to_string(),
|
kind: "mention".to_string(),
|
||||||
mentioned: Some(ChannelAccount {
|
mentioned: Some(ChannelAccount {
|
||||||
id: "bot-id".to_string(),
|
id: "bot-id".to_string(),
|
||||||
name: Some("Bot".to_string()),
|
name: Some("Bot".to_string()),
|
||||||
|
|
|
||||||
|
|
@ -168,8 +168,8 @@ impl BrowserService {
|
||||||
self.port
|
self.port
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::unused_async)]
|
|
||||||
pub async fn stop(&mut self) -> Result<()> {
|
pub async fn stop(&mut self) -> Result<()> {
|
||||||
|
tokio::task::yield_now().await;
|
||||||
if let Some(mut process) = self.process.take() {
|
if let Some(mut process) = self.process.take() {
|
||||||
info!("Stopping browser");
|
info!("Stopping browser");
|
||||||
process.kill().ok();
|
process.kill().ok();
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,8 @@ impl RedisService {
|
||||||
Ok(service)
|
Ok(service)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::unused_async)]
|
|
||||||
async fn start_server(&mut self) -> Result<()> {
|
async fn start_server(&mut self) -> Result<()> {
|
||||||
|
tokio::task::yield_now().await;
|
||||||
log::info!("Starting Redis on port {}", self.port);
|
log::info!("Starting Redis on port {}", self.port);
|
||||||
|
|
||||||
let redis = Self::find_binary()?;
|
let redis = Self::find_binary()?;
|
||||||
|
|
@ -127,8 +127,8 @@ impl RedisService {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::unused_async)]
|
|
||||||
pub async fn execute(&self, args: &[&str]) -> Result<String> {
|
pub async fn execute(&self, args: &[&str]) -> Result<String> {
|
||||||
|
tokio::task::yield_now().await;
|
||||||
let redis_cli = Self::find_cli_binary()?;
|
let redis_cli = Self::find_cli_binary()?;
|
||||||
|
|
||||||
let mut cmd = Command::new(&redis_cli);
|
let mut cmd = Command::new(&redis_cli);
|
||||||
|
|
|
||||||
|
|
@ -107,10 +107,9 @@ impl Locator {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[allow(clippy::match_same_arms)]
|
|
||||||
pub fn to_css_selector(&self) -> String {
|
pub fn to_css_selector(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Self::Css(s) => s.clone(),
|
Self::Css(s) | Self::TagName(s) => s.clone(),
|
||||||
Self::XPath(_) => {
|
Self::XPath(_) => {
|
||||||
log::warn!("XPath locators not directly supported in CDP, use CSS selectors");
|
log::warn!("XPath locators not directly supported in CDP, use CSS selectors");
|
||||||
"*".to_string()
|
"*".to_string()
|
||||||
|
|
@ -119,7 +118,6 @@ impl Locator {
|
||||||
Self::Name(s) => format!("[name='{s}']"),
|
Self::Name(s) => format!("[name='{s}']"),
|
||||||
Self::LinkText(s) => format!("a:contains('{s}')"),
|
Self::LinkText(s) => format!("a:contains('{s}')"),
|
||||||
Self::PartialLinkText(s) => format!("a[href*='{s}']"),
|
Self::PartialLinkText(s) => format!("a[href*='{s}']"),
|
||||||
Self::TagName(s) => s.clone(),
|
|
||||||
Self::ClassName(s) => format!(".{s}"),
|
Self::ClassName(s) => format!(".{s}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue