Private
Public Access
1
0

kordophone: add support for /messages

This commit is contained in:
2025-01-20 19:43:21 -08:00
parent 793faab721
commit a8104c379c
8 changed files with 206 additions and 6 deletions

View File

@@ -1,21 +1,29 @@
use async_trait::async_trait;
use std::collections::HashMap;
pub use crate::APIInterface;
use crate::{api::http_client::Credentials, model::{Conversation, JwtToken}};
use crate::{
api::http_client::Credentials,
model::{conversation, Conversation, ConversationID, JwtToken, Message}
};
pub struct TestClient {
pub version: &'static str,
pub conversations: Vec<Conversation>,
pub messages: HashMap<ConversationID, Vec<Message>>,
}
#[derive(Debug)]
pub enum TestError {}
pub enum TestError {
ConversationNotFound,
}
impl TestClient {
pub fn new() -> TestClient {
TestClient {
version: "KordophoneTest-1.0",
conversations: vec![],
messages: HashMap::<ConversationID, Vec<Message>>::new(),
}
}
}
@@ -35,4 +43,12 @@ impl APIInterface for TestClient {
async fn get_conversations(&mut self) -> Result<Vec<Conversation>, Self::Error> {
Ok(self.conversations.clone())
}
async fn get_messages(&mut self, conversation: Conversation) -> Result<Vec<Message>, Self::Error> {
if let Some(messages) = self.messages.get(&conversation.guid) {
return Ok(messages.clone())
}
Err(TestError::ConversationNotFound)
}
}