- update: database client to implement a database trait so we can mock it out

- update unit tests
- add: database client mock
This commit is contained in:
2024-11-25 22:20:15 -05:00
parent 3ff22c9a5b
commit 3fc6c6252c
15 changed files with 181 additions and 103 deletions

View File

@@ -0,0 +1,23 @@
use mockall::{mock, predicate::*};
use async_trait::async_trait;
use crate::database::{CreateUserResponse, GetUserResponse};
use crate::database_client::{DatabaseClientTrait};
#[cfg(test)]
mock! {
pub DatabaseClient {}
#[async_trait]
impl DatabaseClientTrait for DatabaseClient {
async fn connect(endpoint: &str) -> Result<Self, Box<dyn std::error::Error>>;
async fn get_user_by_userid(&mut self, user_id: i32) -> Result<GetUserResponse, Box<dyn std::error::Error>>;
async fn get_user_by_username(&mut self, user_id: &str) -> Result<GetUserResponse, Box<dyn std::error::Error>>;
async fn create_user(&mut self, username: &str, email: &str, password: &str) -> Result<CreateUserResponse, Box<dyn std::error::Error>>;
}
}
impl Clone for MockDatabaseClient {
fn clone(&self) -> Self {
MockDatabaseClient::new() // Create a new mock instance
}
}

View File

@@ -0,0 +1,2 @@
#[cfg(test)]
pub mod database_client_mock;