fix(tests): make sure that the document_deletion and document_upload jobs use environment variables

This commit is contained in:
perf3ct 2025-06-20 20:59:07 +00:00
parent a2d6c318db
commit 4735199a99
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232
2 changed files with 24 additions and 0 deletions

View File

@ -12,6 +12,17 @@ use uuid::Uuid;
use readur::models::{DocumentResponse, CreateUser, LoginRequest, LoginResponse, UserRole}; use readur::models::{DocumentResponse, CreateUser, LoginRequest, LoginResponse, UserRole};
// Initialize test environment
fn init_test_env() {
use std::env;
// Load test environment variables
dotenvy::from_filename(".env.test").ok();
// Ensure we're using the test database
env::set_var("DATABASE_URL", "postgresql://readur_test:readur_test@localhost:5433/readur_test");
}
fn get_base_url() -> String { fn get_base_url() -> String {
std::env::var("API_URL").unwrap_or_else(|_| "http://localhost:8000".to_string()) std::env::var("API_URL").unwrap_or_else(|_| "http://localhost:8000".to_string())
} }
@ -450,6 +461,7 @@ async fn test_bulk_delete_mixed_existing_nonexistent() {
#[tokio::test] #[tokio::test]
async fn test_unauthorized_deletion() { async fn test_unauthorized_deletion() {
init_test_env();
let client = DocumentDeletionTestClient::new(); let client = DocumentDeletionTestClient::new();
skip_if_server_down!(client); skip_if_server_down!(client);

View File

@ -11,6 +11,17 @@ use readur::{
models::{Document, CreateUser, UserRole}, models::{Document, CreateUser, UserRole},
}; };
// Initialize test environment
fn init_test_env() {
use std::env;
// Load test environment variables
dotenvy::from_filename(".env.test").ok();
// Ensure we're using the test database
env::set_var("DATABASE_URL", "postgresql://readur_test:readur_test@localhost:5433/readur_test");
}
// Helper function to calculate file hash // Helper function to calculate file hash
fn calculate_file_hash(data: &[u8]) -> String { fn calculate_file_hash(data: &[u8]) -> String {
let mut hasher = Sha256::new(); let mut hasher = Sha256::new();
@ -119,6 +130,7 @@ async fn test_document_upload_duplicate_detection_returns_existing() -> Result<(
#[tokio::test] #[tokio::test]
async fn test_document_upload_unique_content_processed() -> Result<()> { async fn test_document_upload_unique_content_processed() -> Result<()> {
init_test_env();
let state = create_test_app_state().await?; let state = create_test_app_state().await?;
let user = create_test_user_with_suffix(&format!("upload_{}", uuid::Uuid::new_v4().simple())); let user = create_test_user_with_suffix(&format!("upload_{}", uuid::Uuid::new_v4().simple()));