refactor: allow optional database in setup, use derived default

This commit is contained in:
Ryan Walters
2025-09-18 22:58:38 -05:00
parent e2c725cb95
commit cc06cd88a1
10 changed files with 95 additions and 59 deletions

View File

@@ -3,13 +3,12 @@ use mockall::predicate::*;
use pretty_assertions::assert_eq;
mod common;
use common::{create_test_app_state, create_test_router, TestConfig};
// OAuth provider imports removed as they're not used in these health tests
use common::{create_test_app_state, create_test_app_state_with_database, create_test_router, TestConfig};
/// Common setup function for all tests
async fn setup_test_server() -> TestServer {
let test_config = TestConfig::new().await;
let app_state = create_test_app_state(&test_config).await;
/// Setup function with optional database
async fn setup_test_server(use_database: bool) -> TestServer {
let test_config = TestConfig::new_with_database(use_database).await;
let app_state = create_test_app_state_with_database(&test_config, use_database).await;
let router = create_test_router(app_state);
TestServer::new(router).unwrap()
}
@@ -17,12 +16,11 @@ async fn setup_test_server() -> TestServer {
/// Test basic endpoints functionality
#[tokio::test]
async fn test_basic_endpoints() {
let server = setup_test_server().await;
let server = setup_test_server(false).await;
// Test root endpoint
let response = server.get("/").await;
assert_eq!(response.status_code(), 200);
assert_eq!(response.text(), "Hello, World! Visit /auth/github to start OAuth flow.");
}
/// Test health endpoint functionality with real database connectivity
@@ -53,7 +51,7 @@ async fn test_health_endpoint() {
/// Test OAuth provider listing and configuration
#[tokio::test]
async fn test_oauth_provider_configuration() {
let server = setup_test_server().await;
let server = setup_test_server(false).await;
// Test providers list endpoint
let response = server.get("/auth/providers").await;
@@ -85,7 +83,7 @@ async fn test_oauth_provider_configuration() {
/// Test OAuth authorization flows
#[tokio::test]
async fn test_oauth_authorization_flows() {
let server = setup_test_server().await;
let server = setup_test_server(false).await;
// Test OAuth authorize endpoint (should redirect)
let response = server.get("/auth/github").await;
@@ -103,7 +101,7 @@ async fn test_oauth_authorization_flows() {
/// Test OAuth callback handling
#[tokio::test]
async fn test_oauth_callback_handling() {
let server = setup_test_server().await;
let server = setup_test_server(false).await;
// Test OAuth callback with missing parameters (should fail gracefully)
let response = server.get("/auth/github/callback").await;
@@ -113,7 +111,7 @@ async fn test_oauth_callback_handling() {
/// Test session management endpoints
#[tokio::test]
async fn test_session_management() {
let server = setup_test_server().await;
let server = setup_test_server(false).await;
// Test logout endpoint (should redirect)
let response = server.get("/logout").await;
@@ -127,7 +125,7 @@ async fn test_session_management() {
/// Test that verifies database operations work correctly
#[tokio::test]
async fn test_database_operations() {
let server = setup_test_server().await;
let server = setup_test_server(true).await;
// Act: Test health endpoint to verify database connectivity
let response = server.get("/health").await;
@@ -141,7 +139,7 @@ async fn test_database_operations() {
/// Test OAuth authorization flow
#[tokio::test]
async fn test_oauth_authorization_flow() {
let _server = setup_test_server().await;
let _server = setup_test_server(false).await;
// TODO: Test that the OAuth authorize handler redirects to the provider's authorization page for valid providers
// TODO: Test that the OAuth authorize handler returns an error for unknown providers
@@ -151,7 +149,7 @@ async fn test_oauth_authorization_flow() {
/// Test OAuth callback validation
#[tokio::test]
async fn test_oauth_callback_validation() {
let _server = setup_test_server().await;
let _server = setup_test_server(false).await;
// TODO: Test that the OAuth callback handler validates the provider exists before processing
// TODO: Test that the OAuth callback handler returns an error when the provider returns an OAuth error
@@ -162,7 +160,7 @@ async fn test_oauth_callback_validation() {
/// Test OAuth callback processing
#[tokio::test]
async fn test_oauth_callback_processing() {
let _server = setup_test_server().await;
let _server = setup_test_server(false).await;
// TODO: Test that the OAuth callback handler exchanges the authorization code for user information successfully
// TODO: Test that the OAuth callback handler handles provider callback errors gracefully
@@ -174,7 +172,7 @@ async fn test_oauth_callback_processing() {
/// Test account linking flow
#[tokio::test]
async fn test_account_linking_flow() {
let _server = setup_test_server().await;
let _server = setup_test_server(false).await;
// TODO: Test that the OAuth callback handler links a new provider to an existing user when link intent is present and session is valid
// TODO: Test that the OAuth callback handler redirects to profile after successful account linking
@@ -184,7 +182,7 @@ async fn test_account_linking_flow() {
/// Test new user registration
#[tokio::test]
async fn test_new_user_registration() {
let _server = setup_test_server().await;
let _server = setup_test_server(false).await;
// TODO: Test that the OAuth callback handler creates a new user account when no existing user is found
// TODO: Test that the OAuth callback handler requires an email address for all sign-ins
@@ -194,7 +192,7 @@ async fn test_new_user_registration() {
/// Test existing user sign-in
#[tokio::test]
async fn test_existing_user_sign_in() {
let _server = setup_test_server().await;
let _server = setup_test_server(false).await;
// TODO: Test that the OAuth callback handler allows sign-in when the provider is already linked to an existing user
// TODO: Test that the OAuth callback handler requires explicit linking when a user with the same email exists and has other providers linked
@@ -204,7 +202,7 @@ async fn test_existing_user_sign_in() {
/// Test avatar processing
#[tokio::test]
async fn test_avatar_processing() {
let _server = setup_test_server().await;
let _server = setup_test_server(false).await;
// TODO: Test that the OAuth callback handler processes user avatars asynchronously without blocking the response
// TODO: Test that the OAuth callback handler handles avatar processing errors gracefully
@@ -213,7 +211,7 @@ async fn test_avatar_processing() {
/// Test profile access
#[tokio::test]
async fn test_profile_access() {
let _server = setup_test_server().await;
let _server = setup_test_server(false).await;
// TODO: Test that the profile handler returns user information when a valid session exists
// TODO: Test that the profile handler returns an error when no session cookie is present
@@ -225,7 +223,7 @@ async fn test_profile_access() {
/// Test logout functionality
#[tokio::test]
async fn test_logout_functionality() {
let _server = setup_test_server().await;
let _server = setup_test_server(false).await;
// TODO: Test that the logout handler clears the session if a session was there
// TODO: Test that the logout handler removes the session from memory storage
@@ -236,7 +234,7 @@ async fn test_logout_functionality() {
/// Test provider configuration
#[tokio::test]
async fn test_provider_configuration() {
let _server = setup_test_server().await;
let _server = setup_test_server(false).await;
// TODO: Test that the providers list handler returns all configured OAuth providers
// TODO: Test that the providers list handler includes provider status (active/inactive)