Rust AppView - highly experimental!
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at experiments 320 lines 8.5 kB view raw
1//! Tests for record existence SQL queries 2//! 3//! These tests validate that the SQL queries used to check if records exist 4//! are syntactically correct against the current database schema. 5 6mod common; 7use common::*; 8use consumer::db::record_exists::queries; 9use parakeet_db::utils::tid::decode_tid; 10use eyre::WrapErr; 11 12// Valid test TID that can be decoded to i64 13const TEST_TID: &str = "3m4fsspghex2n"; 14 15#[tokio::test] 16async fn test_post_exists_query() -> eyre::Result<()> { 17 let pool = test_pool(); 18 let conn = pool.get().await.wrap_err("Failed to get connection")?; 19 let rkey_i64 = decode_tid(TEST_TID).unwrap(); 20 21 let result = queries::post_exists(&**conn, "did:plc:test", rkey_i64).await; 22 23 assert!( 24 result.is_ok(), 25 "post_exists query should be valid SQL: {:?}", 26 result.err() 27 ); 28 Ok(()) 29} 30 31#[tokio::test] 32async fn test_like_exists_query() -> eyre::Result<()> { 33 let pool = test_pool(); 34 let conn = pool.get().await.wrap_err("Failed to get connection")?; 35 let rkey_i64 = decode_tid(TEST_TID).unwrap(); 36 37 let result = queries::like_exists(&**conn, "did:plc:test", rkey_i64).await; 38 39 assert!( 40 result.is_ok(), 41 "like_exists query should be valid SQL: {:?}", 42 result.err() 43 ); 44 Ok(()) 45} 46 47#[tokio::test] 48async fn test_repost_exists_query() -> eyre::Result<()> { 49 let pool = test_pool(); 50 let conn = pool.get().await.wrap_err("Failed to get connection")?; 51 52 let rkey_i64 = decode_tid(TEST_TID).unwrap(); 53 54 let result = queries::repost_exists(&**conn, "did:plc:test", rkey_i64).await; 55 56 assert!( 57 result.is_ok(), 58 "repost_exists query should be valid SQL: {:?}", 59 result.err() 60 ); 61 Ok(()) 62} 63 64#[tokio::test] 65async fn test_follow_exists_query() -> eyre::Result<()> { 66 let pool = test_pool(); 67 let conn = pool.get().await.wrap_err("Failed to get connection")?; 68 69 let rkey_i64 = decode_tid(TEST_TID).unwrap(); 70 71 let result = queries::follow_exists(&**conn, "did:plc:test", rkey_i64).await; 72 73 assert!( 74 result.is_ok(), 75 "follow_exists query should be valid SQL: {:?}", 76 result.err() 77 ); 78 Ok(()) 79} 80 81#[tokio::test] 82async fn test_block_exists_query() -> eyre::Result<()> { 83 let pool = test_pool(); 84 let conn = pool.get().await.wrap_err("Failed to get connection")?; 85 86 let rkey_i64 = decode_tid(TEST_TID).unwrap(); 87 88 let result = queries::block_exists(&**conn, "did:plc:test", rkey_i64).await; 89 90 assert!( 91 result.is_ok(), 92 "block_exists query should be valid SQL: {:?}", 93 result.err() 94 ); 95 Ok(()) 96} 97 98#[tokio::test] 99async fn test_profile_exists_query() -> eyre::Result<()> { 100 let pool = test_pool(); 101 let conn = pool.get().await.wrap_err("Failed to get connection")?; 102 103 let result = queries::profile_exists(&**conn, "did:plc:test").await; 104 105 assert!( 106 result.is_ok(), 107 "profile_exists query should be valid SQL: {:?}", 108 result.err() 109 ); 110 Ok(()) 111} 112 113#[tokio::test] 114async fn test_feedgen_exists_query() -> eyre::Result<()> { 115 let pool = test_pool(); 116 let conn = pool.get().await.wrap_err("Failed to get connection")?; 117 118 let result = queries::feedgen_exists(&**conn, "did:plc:test", "test_rkey").await; 119 120 assert!( 121 result.is_ok(), 122 "feedgen_exists query should be valid SQL: {:?}", 123 result.err() 124 ); 125 Ok(()) 126} 127 128#[tokio::test] 129async fn test_list_exists_query() -> eyre::Result<()> { 130 let pool = test_pool(); 131 let conn = pool.get().await.wrap_err("Failed to get connection")?; 132 133 let result = queries::list_exists(&**conn, "did:plc:test", TEST_TID).await; 134 135 assert!( 136 result.is_ok(), 137 "list_exists query should be valid SQL: {:?}", 138 result.err() 139 ); 140 Ok(()) 141} 142 143#[tokio::test] 144async fn test_list_item_exists_query() -> eyre::Result<()> { 145 let pool = test_pool(); 146 let conn = pool.get().await.wrap_err("Failed to get connection")?; 147 148 let rkey_i64 = decode_tid(TEST_TID).unwrap(); 149 150 let result = queries::list_item_exists(&**conn, "did:plc:test", rkey_i64).await; 151 152 assert!( 153 result.is_ok(), 154 "list_item_exists query should be valid SQL: {:?}", 155 result.err() 156 ); 157 Ok(()) 158} 159 160#[tokio::test] 161async fn test_list_block_exists_query() -> eyre::Result<()> { 162 let pool = test_pool(); 163 let conn = pool.get().await.wrap_err("Failed to get connection")?; 164 165 let rkey_i64 = decode_tid(TEST_TID).unwrap(); 166 167 let result = queries::list_block_exists(&**conn, "did:plc:test", rkey_i64).await; 168 169 assert!( 170 result.is_ok(), 171 "list_block_exists query should be valid SQL: {:?}", 172 result.err() 173 ); 174 Ok(()) 175} 176 177#[tokio::test] 178async fn test_threadgate_exists_query() -> eyre::Result<()> { 179 let pool = test_pool(); 180 let conn = pool.get().await.wrap_err("Failed to get connection")?; 181 182 let rkey_i64 = decode_tid(TEST_TID).unwrap(); 183 184 let result = queries::threadgate_exists(&**conn, "did:plc:test", rkey_i64).await; 185 186 assert!( 187 result.is_ok(), 188 "threadgate_exists query should be valid SQL: {:?}", 189 result.err() 190 ); 191 Ok(()) 192} 193 194#[tokio::test] 195async fn test_postgate_exists_query() -> eyre::Result<()> { 196 let pool = test_pool(); 197 let conn = pool.get().await.wrap_err("Failed to get connection")?; 198 199 let rkey_i64 = decode_tid(TEST_TID).unwrap(); 200 201 let result = queries::postgate_exists(&**conn, "did:plc:test", rkey_i64).await; 202 203 assert!( 204 result.is_ok(), 205 "postgate_exists query should be valid SQL: {:?}", 206 result.err() 207 ); 208 Ok(()) 209} 210 211#[tokio::test] 212async fn test_starterpack_exists_query() -> eyre::Result<()> { 213 let pool = test_pool(); 214 let conn = pool.get().await.wrap_err("Failed to get connection")?; 215 216 let rkey_i64 = decode_tid(TEST_TID).unwrap(); 217 218 let result = queries::starterpack_exists(&**conn, "did:plc:test", rkey_i64).await; 219 220 assert!( 221 result.is_ok(), 222 "starterpack_exists query should be valid SQL: {:?}", 223 result.err() 224 ); 225 Ok(()) 226} 227 228#[tokio::test] 229async fn test_verification_exists_query() -> eyre::Result<()> { 230 let pool = test_pool(); 231 let conn = pool.get().await.wrap_err("Failed to get connection")?; 232 233 let rkey_i64 = decode_tid(TEST_TID).unwrap(); 234 235 let result = queries::verification_exists(&**conn, "did:plc:test", rkey_i64).await; 236 237 assert!( 238 result.is_ok(), 239 "verification_exists query should be valid SQL: {:?}", 240 result.err() 241 ); 242 Ok(()) 243} 244 245#[tokio::test] 246async fn test_labeler_exists_query() -> eyre::Result<()> { 247 let pool = test_pool(); 248 let conn = pool.get().await.wrap_err("Failed to get connection")?; 249 250 let result = queries::labeler_exists(&**conn, "did:plc:test").await; 251 252 assert!( 253 result.is_ok(), 254 "labeler_exists query should be valid SQL: {:?}", 255 result.err() 256 ); 257 Ok(()) 258} 259 260#[tokio::test] 261async fn test_status_exists_query() -> eyre::Result<()> { 262 let pool = test_pool(); 263 let conn = pool.get().await.wrap_err("Failed to get connection")?; 264 265 let result = queries::status_exists(&**conn, "did:plc:test").await; 266 267 assert!( 268 result.is_ok(), 269 "status_exists query should be valid SQL: {:?}", 270 result.err() 271 ); 272 Ok(()) 273} 274 275#[tokio::test] 276async fn test_bookmark_exists_query() -> eyre::Result<()> { 277 let pool = test_pool(); 278 let conn = pool.get().await.wrap_err("Failed to get connection")?; 279 280 let rkey_i64 = decode_tid(TEST_TID).unwrap(); 281 282 let result = queries::bookmark_exists(&**conn, "did:plc:test", rkey_i64).await; 283 284 assert!( 285 result.is_ok(), 286 "bookmark_exists query should be valid SQL: {:?}", 287 result.err() 288 ); 289 Ok(()) 290} 291 292#[tokio::test] 293async fn test_chat_decl_exists_query() -> eyre::Result<()> { 294 let pool = test_pool(); 295 let conn = pool.get().await.wrap_err("Failed to get connection")?; 296 297 let result = queries::chat_decl_exists(&**conn, "did:plc:test").await; 298 299 assert!( 300 result.is_ok(), 301 "chat_decl_exists query should be valid SQL: {:?}", 302 result.err() 303 ); 304 Ok(()) 305} 306 307#[tokio::test] 308async fn test_notif_decl_exists_query() -> eyre::Result<()> { 309 let pool = test_pool(); 310 let conn = pool.get().await.wrap_err("Failed to get connection")?; 311 312 let result = queries::notif_decl_exists(&**conn, "did:plc:test").await; 313 314 assert!( 315 result.is_ok(), 316 "notif_decl_exists query should be valid SQL: {:?}", 317 result.err() 318 ); 319 Ok(()) 320}