forked from
lewis.moe/bspds-sandbox
PDS software with bells & whistles you didn’t even know you needed. will move this to its own account when ready.
1mod common;
2use common::*;
3use reqwest::StatusCode;
4use reqwest::header;
5use serde_json::Value;
6
7#[tokio::test]
8async fn test_list_blobs_success() {
9 let client = client();
10 let (access_jwt, did) = create_account_and_login(&client).await;
11 let unique_content = format!("test blob content {}", uuid::Uuid::new_v4());
12 let blob_res = client
13 .post(format!(
14 "{}/xrpc/com.atproto.repo.uploadBlob",
15 base_url().await
16 ))
17 .header(header::CONTENT_TYPE, "text/plain")
18 .bearer_auth(&access_jwt)
19 .body(unique_content)
20 .send()
21 .await
22 .expect("Failed to upload blob");
23 assert_eq!(blob_res.status(), StatusCode::OK);
24 let params = [("did", did.as_str())];
25 let res = client
26 .get(format!(
27 "{}/xrpc/com.atproto.sync.listBlobs",
28 base_url().await
29 ))
30 .query(¶ms)
31 .send()
32 .await
33 .expect("Failed to send request");
34 assert_eq!(res.status(), StatusCode::OK);
35 let body: Value = res.json().await.expect("Response was not valid JSON");
36 assert!(body["cids"].is_array());
37 let cids = body["cids"].as_array().unwrap();
38 assert!(!cids.is_empty());
39}
40
41#[tokio::test]
42async fn test_list_blobs_not_found() {
43 let client = client();
44 let params = [("did", "did:plc:nonexistent12345")];
45 let res = client
46 .get(format!(
47 "{}/xrpc/com.atproto.sync.listBlobs",
48 base_url().await
49 ))
50 .query(¶ms)
51 .send()
52 .await
53 .expect("Failed to send request");
54 assert_eq!(res.status(), StatusCode::BAD_REQUEST);
55 let body: Value = res.json().await.expect("Response was not valid JSON");
56 assert_eq!(body["error"], "RepoNotFound");
57}
58
59#[tokio::test]
60async fn test_get_blob_success() {
61 let client = client();
62 let (access_jwt, did) = create_account_and_login(&client).await;
63 let blob_content = "test blob for get_blob";
64 let blob_res = client
65 .post(format!(
66 "{}/xrpc/com.atproto.repo.uploadBlob",
67 base_url().await
68 ))
69 .header(header::CONTENT_TYPE, "text/plain")
70 .bearer_auth(&access_jwt)
71 .body(blob_content)
72 .send()
73 .await
74 .expect("Failed to upload blob");
75 assert_eq!(blob_res.status(), StatusCode::OK);
76 let blob_body: Value = blob_res.json().await.expect("Response was not valid JSON");
77 let cid = blob_body["blob"]["ref"]["$link"].as_str().expect("No CID");
78 let params = [("did", did.as_str()), ("cid", cid)];
79 let res = client
80 .get(format!(
81 "{}/xrpc/com.atproto.sync.getBlob",
82 base_url().await
83 ))
84 .query(¶ms)
85 .send()
86 .await
87 .expect("Failed to send request");
88 assert_eq!(res.status(), StatusCode::OK);
89 assert_eq!(
90 res.headers()
91 .get("content-type")
92 .and_then(|h| h.to_str().ok()),
93 Some("text/plain")
94 );
95 let body = res.text().await.expect("Failed to get body");
96 assert_eq!(body, blob_content);
97}
98
99#[tokio::test]
100async fn test_get_blob_not_found() {
101 let client = client();
102 let (_, did) = create_account_and_login(&client).await;
103 let params = [
104 ("did", did.as_str()),
105 (
106 "cid",
107 "bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku",
108 ),
109 ];
110 let res = client
111 .get(format!(
112 "{}/xrpc/com.atproto.sync.getBlob",
113 base_url().await
114 ))
115 .query(¶ms)
116 .send()
117 .await
118 .expect("Failed to send request");
119 assert_eq!(res.status(), StatusCode::NOT_FOUND);
120 let body: Value = res.json().await.expect("Response was not valid JSON");
121 assert_eq!(body["error"], "BlobNotFound");
122}