Fix tests
This commit is contained in:
@@ -10,4 +10,5 @@ async-trait = "0.1.80"
|
||||
serde = { version = "1.0.152", features = ["derive"] }
|
||||
serde_json = "1.0.91"
|
||||
time = { version = "0.3.17", features = ["parsing", "serde"] }
|
||||
tokio = { version = "1.37.0", features = ["full"] }
|
||||
uuid = { version = "1.6.1", features = ["v4", "fast-rng", "macro-diagnostics"] }
|
||||
|
||||
@@ -3,20 +3,29 @@ use self::test_client::TestClient;
|
||||
use crate::APIInterface;
|
||||
|
||||
pub mod api_interface {
|
||||
use crate::model::Conversation;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_version() {
|
||||
let client = TestClient{};
|
||||
let version = client.get_version();
|
||||
assert_eq!(version, "KordophoneTest-1.0");
|
||||
#[tokio::test]
|
||||
async fn test_version() {
|
||||
let client = TestClient::new();
|
||||
let version = client.get_version().await.unwrap();
|
||||
assert_eq!(version, client.version);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversations() {
|
||||
let client = TestClient{};
|
||||
let conversations = client.get_conversations();
|
||||
#[tokio::test]
|
||||
async fn test_conversations() {
|
||||
let mut client = TestClient::new();
|
||||
|
||||
let test_convo = Conversation::builder()
|
||||
.display_name("Test Conversation")
|
||||
.build();
|
||||
|
||||
client.conversations.push(test_convo.clone());
|
||||
|
||||
let conversations = client.get_conversations().await.unwrap();
|
||||
assert_eq!(conversations.len(), 1);
|
||||
assert_eq!(conversations[0].display_name, Some("Test Conversation".to_string()));
|
||||
assert_eq!(conversations[0].display_name, test_convo.display_name);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,34 @@
|
||||
use async_trait::async_trait;
|
||||
|
||||
pub use crate::APIInterface;
|
||||
use crate::model::Conversation;
|
||||
|
||||
pub struct TestClient {}
|
||||
pub struct TestClient {
|
||||
pub version: &'static str,
|
||||
pub conversations: Vec<Conversation>,
|
||||
}
|
||||
|
||||
impl APIInterface for TestClient {
|
||||
fn get_version(&self) -> String {
|
||||
return "KordophoneTest-1.0".to_string()
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub enum TestError {}
|
||||
|
||||
fn get_conversations(&self) -> Vec<Conversation> {
|
||||
let mut conversations = Vec::new();
|
||||
conversations.push(Conversation::builder().display_name("Test Conversation").build());
|
||||
conversations
|
||||
impl TestClient {
|
||||
pub fn new() -> TestClient {
|
||||
TestClient {
|
||||
version: "KordophoneTest-1.0",
|
||||
conversations: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl APIInterface for TestClient {
|
||||
type Error = TestError;
|
||||
|
||||
async fn get_version(&self) -> Result<String, Self::Error> {
|
||||
Ok(self.version.to_string())
|
||||
}
|
||||
|
||||
async fn get_conversations(&self) -> Result<Vec<Conversation>, Self::Error> {
|
||||
Ok(self.conversations.clone())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user