this repo has no description
1mod common; 2 3use common::{base_url, client, create_account_and_login}; 4use reqwest::StatusCode; 5use serde_json::{json, Value}; 6 7#[tokio::test] 8async fn test_get_author_feed_returns_appview_data() { 9 let client = client(); 10 let base = base_url().await; 11 let (jwt, did) = create_account_and_login(&client).await; 12 13 let res = client 14 .get(format!( 15 "{}/xrpc/app.bsky.feed.getAuthorFeed?actor={}", 16 base, did 17 )) 18 .header("Authorization", format!("Bearer {}", jwt)) 19 .send() 20 .await 21 .unwrap(); 22 23 assert_eq!(res.status(), StatusCode::OK); 24 25 let body: Value = res.json().await.unwrap(); 26 assert!(body["feed"].is_array(), "Response should have feed array"); 27 let feed = body["feed"].as_array().unwrap(); 28 assert_eq!(feed.len(), 1, "Feed should have 1 post from appview"); 29 assert_eq!( 30 feed[0]["post"]["record"]["text"].as_str(), 31 Some("Author feed post from appview"), 32 "Post text should match appview response" 33 ); 34} 35 36#[tokio::test] 37async fn test_get_actor_likes_returns_appview_data() { 38 let client = client(); 39 let base = base_url().await; 40 let (jwt, did) = create_account_and_login(&client).await; 41 42 let res = client 43 .get(format!( 44 "{}/xrpc/app.bsky.feed.getActorLikes?actor={}", 45 base, did 46 )) 47 .header("Authorization", format!("Bearer {}", jwt)) 48 .send() 49 .await 50 .unwrap(); 51 52 assert_eq!(res.status(), StatusCode::OK); 53 54 let body: Value = res.json().await.unwrap(); 55 assert!(body["feed"].is_array(), "Response should have feed array"); 56 let feed = body["feed"].as_array().unwrap(); 57 assert_eq!(feed.len(), 1, "Feed should have 1 liked post from appview"); 58 assert_eq!( 59 feed[0]["post"]["record"]["text"].as_str(), 60 Some("Liked post from appview"), 61 "Post text should match appview response" 62 ); 63} 64 65#[tokio::test] 66async fn test_get_post_thread_returns_appview_data() { 67 let client = client(); 68 let base = base_url().await; 69 let (jwt, did) = create_account_and_login(&client).await; 70 71 let res = client 72 .get(format!( 73 "{}/xrpc/app.bsky.feed.getPostThread?uri=at://{}/app.bsky.feed.post/test123", 74 base, did 75 )) 76 .header("Authorization", format!("Bearer {}", jwt)) 77 .send() 78 .await 79 .unwrap(); 80 81 assert_eq!(res.status(), StatusCode::OK); 82 83 let body: Value = res.json().await.unwrap(); 84 assert!(body["thread"].is_object(), "Response should have thread object"); 85 assert_eq!( 86 body["thread"]["$type"].as_str(), 87 Some("app.bsky.feed.defs#threadViewPost"), 88 "Thread should be a threadViewPost" 89 ); 90 assert_eq!( 91 body["thread"]["post"]["record"]["text"].as_str(), 92 Some("Thread post from appview"), 93 "Post text should match appview response" 94 ); 95} 96 97#[tokio::test] 98async fn test_get_feed_returns_appview_data() { 99 let client = client(); 100 let base = base_url().await; 101 let (jwt, _did) = create_account_and_login(&client).await; 102 103 let res = client 104 .get(format!( 105 "{}/xrpc/app.bsky.feed.getFeed?feed=at://did:plc:test/app.bsky.feed.generator/test", 106 base 107 )) 108 .header("Authorization", format!("Bearer {}", jwt)) 109 .send() 110 .await 111 .unwrap(); 112 113 assert_eq!(res.status(), StatusCode::OK); 114 115 let body: Value = res.json().await.unwrap(); 116 assert!(body["feed"].is_array(), "Response should have feed array"); 117 let feed = body["feed"].as_array().unwrap(); 118 assert_eq!(feed.len(), 1, "Feed should have 1 post from appview"); 119 assert_eq!( 120 feed[0]["post"]["record"]["text"].as_str(), 121 Some("Custom feed post from appview"), 122 "Post text should match appview response" 123 ); 124} 125 126#[tokio::test] 127async fn test_register_push_proxies_to_appview() { 128 let client = client(); 129 let base = base_url().await; 130 let (jwt, _did) = create_account_and_login(&client).await; 131 132 let res = client 133 .post(format!( 134 "{}/xrpc/app.bsky.notification.registerPush", 135 base 136 )) 137 .header("Authorization", format!("Bearer {}", jwt)) 138 .json(&json!({ 139 "serviceDid": "did:web:example.com", 140 "token": "test-push-token", 141 "platform": "ios", 142 "appId": "xyz.bsky.app" 143 })) 144 .send() 145 .await 146 .unwrap(); 147 148 assert_eq!(res.status(), StatusCode::OK); 149}