- 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:
23
auth-service/src/mocks/database_client_mock.rs
Normal file
23
auth-service/src/mocks/database_client_mock.rs
Normal 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
|
||||
}
|
||||
}
|
||||
2
auth-service/src/mocks/mod.rs
Normal file
2
auth-service/src/mocks/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
#[cfg(test)]
|
||||
pub mod database_client_mock;
|
||||
Reference in New Issue
Block a user