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