//! Tests for record existence SQL queries //! //! These tests validate that the SQL queries used to check if records exist //! are syntactically correct against the current database schema. mod common; use common::*; use consumer::db::record_exists::queries; use parakeet_db::utils::tid::decode_tid; use eyre::WrapErr; // Valid test TID that can be decoded to i64 const TEST_TID: &str = "3m4fsspghex2n"; #[tokio::test] async fn test_post_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let rkey_i64 = decode_tid(TEST_TID).unwrap(); let result = queries::post_exists(&**conn, "did:plc:test", rkey_i64).await; assert!( result.is_ok(), "post_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_like_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let rkey_i64 = decode_tid(TEST_TID).unwrap(); let result = queries::like_exists(&**conn, "did:plc:test", rkey_i64).await; assert!( result.is_ok(), "like_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_repost_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let rkey_i64 = decode_tid(TEST_TID).unwrap(); let result = queries::repost_exists(&**conn, "did:plc:test", rkey_i64).await; assert!( result.is_ok(), "repost_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_follow_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let rkey_i64 = decode_tid(TEST_TID).unwrap(); let result = queries::follow_exists(&**conn, "did:plc:test", rkey_i64).await; assert!( result.is_ok(), "follow_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_block_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let rkey_i64 = decode_tid(TEST_TID).unwrap(); let result = queries::block_exists(&**conn, "did:plc:test", rkey_i64).await; assert!( result.is_ok(), "block_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_profile_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let result = queries::profile_exists(&**conn, "did:plc:test").await; assert!( result.is_ok(), "profile_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_feedgen_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let result = queries::feedgen_exists(&**conn, "did:plc:test", "test_rkey").await; assert!( result.is_ok(), "feedgen_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_list_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let result = queries::list_exists(&**conn, "did:plc:test", TEST_TID).await; assert!( result.is_ok(), "list_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_list_item_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let rkey_i64 = decode_tid(TEST_TID).unwrap(); let result = queries::list_item_exists(&**conn, "did:plc:test", rkey_i64).await; assert!( result.is_ok(), "list_item_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_list_block_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let rkey_i64 = decode_tid(TEST_TID).unwrap(); let result = queries::list_block_exists(&**conn, "did:plc:test", rkey_i64).await; assert!( result.is_ok(), "list_block_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_threadgate_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let rkey_i64 = decode_tid(TEST_TID).unwrap(); let result = queries::threadgate_exists(&**conn, "did:plc:test", rkey_i64).await; assert!( result.is_ok(), "threadgate_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_postgate_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let rkey_i64 = decode_tid(TEST_TID).unwrap(); let result = queries::postgate_exists(&**conn, "did:plc:test", rkey_i64).await; assert!( result.is_ok(), "postgate_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_starterpack_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let rkey_i64 = decode_tid(TEST_TID).unwrap(); let result = queries::starterpack_exists(&**conn, "did:plc:test", rkey_i64).await; assert!( result.is_ok(), "starterpack_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_verification_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let rkey_i64 = decode_tid(TEST_TID).unwrap(); let result = queries::verification_exists(&**conn, "did:plc:test", rkey_i64).await; assert!( result.is_ok(), "verification_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_labeler_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let result = queries::labeler_exists(&**conn, "did:plc:test").await; assert!( result.is_ok(), "labeler_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_status_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let result = queries::status_exists(&**conn, "did:plc:test").await; assert!( result.is_ok(), "status_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_bookmark_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let rkey_i64 = decode_tid(TEST_TID).unwrap(); let result = queries::bookmark_exists(&**conn, "did:plc:test", rkey_i64).await; assert!( result.is_ok(), "bookmark_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_chat_decl_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let result = queries::chat_decl_exists(&**conn, "did:plc:test").await; assert!( result.is_ok(), "chat_decl_exists query should be valid SQL: {:?}", result.err() ); Ok(()) } #[tokio::test] async fn test_notif_decl_exists_query() -> eyre::Result<()> { let pool = test_pool(); let conn = pool.get().await.wrap_err("Failed to get connection")?; let result = queries::notif_decl_exists(&**conn, "did:plc:test").await; assert!( result.is_ok(), "notif_decl_exists query should be valid SQL: {:?}", result.err() ); Ok(()) }