use crate::common::{ db::TestDb, helpers::{create_authenticated_app, setup_user_with_permissions}, }; use database::{ enums::{AssetPermissionRole, AssetType, IdentityType}, models::{CollectionToAsset, DashboardFile, Collection}, pool::get_pg_pool, schema::{collections_to_assets, collections, dashboard_files}, }; use diesel::{ExpressionMethods, QueryDsl, SelectableHelper}; use diesel_async::RunQueryDsl; use serde_json::json; use uuid::Uuid; #[tokio::test] async fn test_add_dashboards_to_collection() { // This is a placeholder test - would be implemented with actual test setup // and verification in a real implementation assert!(true); // The below code outlines how the test would be structured: /* // Setup test database let test_db = TestDb::new().await.unwrap(); // Create test user with appropriate permissions let (user, auth_token) = setup_user_with_permissions().await.unwrap(); // Create test collection let collection = Collection { id: Uuid::new_v4(), name: "Test Collection".to_string(), description: Some("Test Description".to_string()), created_by: user.id, updated_by: user.id, created_at: chrono::Utc::now(), updated_at: chrono::Utc::now(), deleted_at: None, organization_id: user.organization_id, }; // Create test dashboards let dashboard1 = DashboardFile { id: Uuid::new_v4(), name: "Test Dashboard 1".to_string(), // ...other fields... }; let dashboard2 = DashboardFile { id: Uuid::new_v4(), name: "Test Dashboard 2".to_string(), // ...other fields... }; // Insert test data into database let mut conn = get_pg_pool().get().await.unwrap(); diesel::insert_into(collections::table) .values(&collection) .execute(&mut conn) .await .unwrap(); diesel::insert_into(dashboard_files::table) .values(&[&dashboard1, &dashboard2]) .execute(&mut conn) .await .unwrap(); // Grant permissions to user for collection and dashboards // (Implementation would vary based on your permission system) // Create app with auth middleware let app = create_authenticated_app().await; // Make request to add dashboards to collection let response = app .oneshot( axum::http::Request::builder() .method(axum::http::Method::POST) .uri(format!("/collections/{}/dashboards", collection.id)) .header("Content-Type", "application/json") .header("Authorization", format!("Bearer {}", auth_token)) .body(axum::body::Body::from( serde_json::to_string(&json!({ "dashboard_ids": [dashboard1.id, dashboard2.id] })) .unwrap(), )) .unwrap(), ) .await .unwrap(); // Assert response status assert_eq!(response.status(), axum::http::StatusCode::OK); // Verify dashboards were added to collection let collection_assets = collections_to_assets::table .filter(collections_to_assets::collection_id.eq(collection.id)) .filter(collections_to_assets::deleted_at.is_null()) .select(CollectionToAsset::as_select()) .load::(&mut conn) .await .unwrap(); assert_eq!(collection_assets.len(), 2); // Clean up test data // (Implementation would depend on your test framework) */ }