this repo has no description
1mod common;
2mod helpers;
3use common::*;
4use helpers::*;
5use reqwest::StatusCode;
6use serde_json::Value;
7
8#[tokio::test]
9async fn test_get_head_comprehensive() {
10 let client = client();
11 let (did, jwt) = setup_new_user("gethead").await;
12 let res = client
13 .get(format!("{}/xrpc/com.atproto.sync.getHead", base_url().await))
14 .query(&[("did", did.as_str())])
15 .send().await.expect("Failed to send request");
16 assert_eq!(res.status(), StatusCode::OK);
17 let body: Value = res.json().await.expect("Response was not valid JSON");
18 assert!(body["root"].is_string());
19 let root1 = body["root"].as_str().unwrap().to_string();
20 assert!(root1.starts_with("bafy"), "Root CID should be a CID");
21 let latest_res = client
22 .get(format!("{}/xrpc/com.atproto.sync.getLatestCommit", base_url().await))
23 .query(&[("did", did.as_str())])
24 .send().await.expect("Failed to get latest commit");
25 let latest_body: Value = latest_res.json().await.unwrap();
26 let latest_cid = latest_body["cid"].as_str().unwrap();
27 assert_eq!(root1, latest_cid, "getHead root should match getLatestCommit cid");
28 create_post(&client, &did, &jwt, "Post to change head").await;
29 let res2 = client
30 .get(format!("{}/xrpc/com.atproto.sync.getHead", base_url().await))
31 .query(&[("did", did.as_str())])
32 .send().await.expect("Failed to get head after record");
33 let body2: Value = res2.json().await.unwrap();
34 let root2 = body2["root"].as_str().unwrap().to_string();
35 assert_ne!(root1, root2, "Head CID should change after record creation");
36 let not_found_res = client
37 .get(format!("{}/xrpc/com.atproto.sync.getHead", base_url().await))
38 .query(&[("did", "did:plc:nonexistent12345")])
39 .send().await.expect("Failed to send request");
40 assert_eq!(not_found_res.status(), StatusCode::BAD_REQUEST);
41 let error_body: Value = not_found_res.json().await.unwrap();
42 assert_eq!(error_body["error"], "HeadNotFound");
43 let missing_res = client
44 .get(format!("{}/xrpc/com.atproto.sync.getHead", base_url().await))
45 .send().await.expect("Failed to send request");
46 assert_eq!(missing_res.status(), StatusCode::BAD_REQUEST);
47 let empty_res = client
48 .get(format!("{}/xrpc/com.atproto.sync.getHead", base_url().await))
49 .query(&[("did", "")])
50 .send().await.expect("Failed to send request");
51 assert_eq!(empty_res.status(), StatusCode::BAD_REQUEST);
52 let whitespace_res = client
53 .get(format!("{}/xrpc/com.atproto.sync.getHead", base_url().await))
54 .query(&[("did", " ")])
55 .send().await.expect("Failed to send request");
56 assert_eq!(whitespace_res.status(), StatusCode::BAD_REQUEST);
57}
58
59#[tokio::test]
60async fn test_get_checkout_comprehensive() {
61 let client = client();
62 let (did, jwt) = setup_new_user("getcheckout").await;
63 let empty_res = client
64 .get(format!("{}/xrpc/com.atproto.sync.getCheckout", base_url().await))
65 .query(&[("did", did.as_str())])
66 .send().await.expect("Failed to send request");
67 assert_eq!(empty_res.status(), StatusCode::OK);
68 let empty_body = empty_res.bytes().await.expect("Failed to get body");
69 assert!(!empty_body.is_empty(), "Even empty repo should return CAR header");
70 create_post(&client, &did, &jwt, "Post for checkout test").await;
71 let res = client
72 .get(format!("{}/xrpc/com.atproto.sync.getCheckout", base_url().await))
73 .query(&[("did", did.as_str())])
74 .send().await.expect("Failed to send request");
75 assert_eq!(res.status(), StatusCode::OK);
76 assert_eq!(res.headers().get("content-type").and_then(|h| h.to_str().ok()), Some("application/vnd.ipld.car"));
77 let body = res.bytes().await.expect("Failed to get body");
78 assert!(!body.is_empty(), "CAR file should not be empty");
79 assert!(body.len() > 50, "CAR file should contain actual data");
80 assert!(body.len() >= 2, "CAR file should have at least header length");
81 for i in 0..4 {
82 tokio::time::sleep(std::time::Duration::from_millis(50)).await;
83 create_post(&client, &did, &jwt, &format!("Checkout post {}", i)).await;
84 }
85 let multi_res = client
86 .get(format!("{}/xrpc/com.atproto.sync.getCheckout", base_url().await))
87 .query(&[("did", did.as_str())])
88 .send().await.expect("Failed to send request");
89 assert_eq!(multi_res.status(), StatusCode::OK);
90 let multi_body = multi_res.bytes().await.expect("Failed to get body");
91 assert!(multi_body.len() > 500, "CAR file with 5 records should be larger");
92 let not_found_res = client
93 .get(format!("{}/xrpc/com.atproto.sync.getCheckout", base_url().await))
94 .query(&[("did", "did:plc:nonexistent12345")])
95 .send().await.expect("Failed to send request");
96 assert_eq!(not_found_res.status(), StatusCode::NOT_FOUND);
97 let error_body: Value = not_found_res.json().await.unwrap();
98 assert_eq!(error_body["error"], "RepoNotFound");
99 let missing_res = client
100 .get(format!("{}/xrpc/com.atproto.sync.getCheckout", base_url().await))
101 .send().await.expect("Failed to send request");
102 assert_eq!(missing_res.status(), StatusCode::BAD_REQUEST);
103 let empty_did_res = client
104 .get(format!("{}/xrpc/com.atproto.sync.getCheckout", base_url().await))
105 .query(&[("did", "")])
106 .send().await.expect("Failed to send request");
107 assert_eq!(empty_did_res.status(), StatusCode::BAD_REQUEST);
108}