use async_trait::async_trait; use std::collections::HashMap; pub use crate::APIInterface; use crate::{ api::http_client::Credentials, model::{conversation, Conversation, ConversationID, JwtToken, Message} }; pub struct TestClient { pub version: &'static str, pub conversations: Vec, pub messages: HashMap>, } #[derive(Debug)] pub enum TestError { ConversationNotFound, } impl TestClient { pub fn new() -> TestClient { TestClient { version: "KordophoneTest-1.0", conversations: vec![], messages: HashMap::>::new(), } } } #[async_trait] impl APIInterface for TestClient { type Error = TestError; async fn authenticate(&mut self, _credentials: Credentials) -> Result { Ok(JwtToken::dummy()) } async fn get_version(&mut self) -> Result { Ok(self.version.to_string()) } async fn get_conversations(&mut self) -> Result, Self::Error> { Ok(self.conversations.clone()) } async fn get_messages(&mut self, conversation_id: &ConversationID) -> Result, Self::Error> { if let Some(messages) = self.messages.get(conversation_id) { return Ok(messages.clone()) } Err(TestError::ConversationNotFound) } }