Update remaining tests to use simplified setup

This commit is contained in:
dal 2025-04-07 16:19:25 -06:00
parent 6ce9f18e41
commit 72c376df7e
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
1 changed files with 86 additions and 8 deletions

View File

@ -209,11 +209,50 @@ fn create_default_chart_config() -> database::types::metric_yml::ChartConfig {
// Test unauthorized access // Test unauthorized access
#[tokio::test] #[tokio::test]
async fn test_update_metric_status_unauthorized() -> Result<()> { async fn test_update_metric_status_unauthorized() -> Result<()> {
// Initialize lazy static to ensure pools are initialized // Initialize database connection pool
lazy_static::initialize(&_INIT); if let Err(e) = init_pools().await {
panic!("Failed to initialize test pools: {}", e);
}
// Set up test environment with viewer user (limited permissions) // Create a test ID for unique naming
let setup = TestSetup::new(Some(UserOrganizationRole::Viewer)).await?; let test_id = format!("test-{}", Uuid::new_v4());
// Create organization and user IDs
let organization_id = Uuid::new_v4();
let user_id = Uuid::new_v4();
// Create mock user and organization - with VIEWER role
let user = AuthenticatedUser {
id: user_id,
email: format!("test-{}@example.com", test_id),
name: Some(format!("Test User {}", test_id)),
config: json!({"preferences": {"theme": "light"}}),
created_at: Utc::now(),
updated_at: Utc::now(),
attributes: json!({}),
avatar_url: None,
organizations: vec![OrganizationMembership {
id: organization_id,
role: UserOrganizationRole::Viewer,
}],
teams: vec![],
};
let organization = Organization {
id: organization_id,
name: format!("Test Organization {}", test_id),
domain: Some(format!("test-{}.org", test_id)),
created_at: Utc::now(),
updated_at: Utc::now(),
deleted_at: None,
};
// Create our simplified test setup
let setup = TestSetup {
user,
organization,
test_id,
};
// Create a test metric file // Create a test metric file
let metric_id = Uuid::new_v4(); let metric_id = Uuid::new_v4();
@ -323,11 +362,50 @@ async fn test_update_metric_status_unauthorized() -> Result<()> {
// Test edge cases for status updates // Test edge cases for status updates
#[tokio::test] #[tokio::test]
async fn test_update_metric_status_null_value() -> Result<()> { async fn test_update_metric_status_null_value() -> Result<()> {
// Initialize lazy static to ensure pools are initialized // Initialize database connection pool
lazy_static::initialize(&_INIT); if let Err(e) = init_pools().await {
panic!("Failed to initialize test pools: {}", e);
}
// Set up test environment with admin user // Create a test ID for unique naming
let setup = TestSetup::new(Some(UserOrganizationRole::WorkspaceAdmin)).await?; let test_id = format!("test-{}", Uuid::new_v4());
// Create organization and user IDs
let organization_id = Uuid::new_v4();
let user_id = Uuid::new_v4();
// Create mock user and organization
let user = AuthenticatedUser {
id: user_id,
email: format!("test-{}@example.com", test_id),
name: Some(format!("Test User {}", test_id)),
config: json!({"preferences": {"theme": "light"}}),
created_at: Utc::now(),
updated_at: Utc::now(),
attributes: json!({}),
avatar_url: None,
organizations: vec![OrganizationMembership {
id: organization_id,
role: UserOrganizationRole::WorkspaceAdmin,
}],
teams: vec![],
};
let organization = Organization {
id: organization_id,
name: format!("Test Organization {}", test_id),
domain: Some(format!("test-{}.org", test_id)),
created_at: Utc::now(),
updated_at: Utc::now(),
deleted_at: None,
};
// Create our simplified test setup
let setup = TestSetup {
user,
organization,
test_id,
};
// Create a test metric file // Create a test metric file
let metric_id = Uuid::new_v4(); let metric_id = Uuid::new_v4();