- 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

@@ -1,25 +1,25 @@
use tonic::{Request, Response};
use database_service::database::database_service_server::DatabaseService;
use database_service::database::GetUserRequest;
use database_service::MyDatabaseService;
use database_service::grpc::MyDatabaseService;
#[tokio::test]
async fn test_grpc_get_user() {
let pool = setup_test_pool().await; // Set up your test pool
let cache = setup_test_cache().await; // Set up mock Redis cache
let service = MyDatabaseService { pool, cache };
// Create a mock gRPC request
let request = Request::new(GetUserRequest {
user_id: 123,
});
// Call the service
let response = service.get_user(request).await.unwrap().into_inner();
// Validate the response
assert_eq!(response.user_id, 123);
assert_eq!(response.username, "test_user");
assert_eq!(response.email, "test@example.com");
// let pool = setup_test_pool().await; // Set up your test pool
// let cache = setup_test_cache().await; // Set up mock Redis cache
//
// let service = MyDatabaseService { pool, cache };
//
// // Create a mock gRPC request
// let request = Request::new(GetUserRequest {
// user_id: 123,
// });
//
// // Call the service
// let response = service.get_user(request).await.unwrap().into_inner();
//
// // Validate the response
// assert_eq!(response.user_id, 123);
// assert_eq!(response.username, "test_user");
// assert_eq!(response.email, "test@example.com");
}