sdk_relay/tests/functional_sync.rs
Nicolas Cantu e0b37fde63
Some checks failed
CI - sdk_relay / build-test (push) Failing after 33s
CI - sdk_relay / security (push) Successful in 2m2s
test(sdk_relay): tests fonctionnels sync (/relays, /sync/status, /sync/force) et WS (ping, subscribe)
2025-08-25 15:41:01 +02:00

45 lines
1.9 KiB
Rust

use std::time::Duration;
#[tokio::test]
async fn relays_listing_should_return_array() {
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(5))
.build()
.expect("client");
let base = std::env::var("SDK_RELAY_HTTP").unwrap_or_else(|_| "http://localhost:8091".to_string());
let res = client.get(format!("{}/relays", base)).send().await.expect("/relays call");
assert!(res.status().is_success());
let json: serde_json::Value = res.json().await.expect("json");
assert!(json.get("relays").and_then(|v| v.as_array()).is_some(), "relays should be array");
}
#[tokio::test]
async fn sync_status_should_contain_sync_types() {
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(5))
.build()
.expect("client");
let base = std::env::var("SDK_RELAY_HTTP").unwrap_or_else(|_| "http://localhost:8091".to_string());
let res = client.get(format!("{}/sync/status", base)).send().await.expect("/sync/status call");
assert!(res.status().is_success());
let json: serde_json::Value = res.json().await.expect("json");
assert!(json.get("sync_types").and_then(|v| v.as_array()).is_some(), "sync_types should be array");
}
#[tokio::test]
async fn forcing_sync_should_return_sync_triggered() {
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(5))
.build()
.expect("client");
let base = std::env::var("SDK_RELAY_HTTP").unwrap_or_else(|_| "http://localhost:8091".to_string());
let body = serde_json::json!({"sync_types":["StateSync"]});
let res = client.post(format!("{}/sync/force", base))
.json(&body)
.send().await.expect("/sync/force call");
assert!(res.status().is_success());
let json: serde_json::Value = res.json().await.expect("json");
let status = json.get("status").and_then(|v| v.as_str()).unwrap_or("");
assert_eq!(status, "sync_triggered");
}