kordophone: add support for /messages
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user