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