//! Integration tests for gates SQL queries //! //! These tests verify that all SQL queries in db::gates::queries are valid //! by executing them against a real PostgreSQL test database. mod common; use common::*; use consumer::db::gates::queries; use eyre::WrapErr; /// Test that check_follow_relationship query is valid SQL #[tokio::test] async fn test_check_follow_relationship_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; // Test with non-existent DIDs - should return None (no actors found) let result = queries::check_follow_relationship(&conn, "did:plc:test_root", "did:plc:test_post").await; assert!( result.is_ok(), "check_follow_relationship query should be valid SQL: {:?}", result.err() ); Ok(()) } /// Test that get_post_mentions query is valid SQL #[tokio::test] async fn test_get_post_mentions_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; // Test with non-existent post URI let result = queries::get_post_mentions(&conn, "at://did:plc:test/app.bsky.feed.post/3m4fsspghex2n") .await; assert!( result.is_ok(), "get_post_mentions query should be valid SQL: {:?}", result.err() ); // Should return empty vec for non-existent post let mentions = result.unwrap(); assert_eq!(mentions.len(), 0); Ok(()) } /// Test that check_list_membership query is valid SQL #[tokio::test] async fn test_check_list_membership_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; // Test with non-existent list URIs let allow_lists = vec!["at://did:plc:listowner/app.bsky.graph.list/3m4fsspghex2n".to_string()]; let result = queries::check_list_membership(&conn, &allow_lists, "did:plc:test").await; assert!( result.is_ok(), "check_list_membership query should be valid SQL: {:?}", result.err() ); // Should return 0 for non-existent lists/actors let count = result.unwrap(); assert_eq!(count, 0); Ok(()) } /// Test that maintain_postgates query is valid SQL #[tokio::test] async fn test_maintain_postgates_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; // Test with non-existent post URI let detached = vec!["at://did:plc:test/app.bsky.feed.post/3m4fsspghex2n".to_string()]; let result = queries::maintain_postgates_cached( &conn, "at://did:plc:test/app.bsky.feed.post/3m4fsspghex2n", &detached, None, ) .await; assert!( result.is_ok(), "maintain_postgates query should be valid SQL: {:?}", result.err() ); Ok(()) }