31 lines
1.1 KiB
Rust
31 lines
1.1 KiB
Rust
use futures_util::{SinkExt, StreamExt};
|
|
use serde_json::json;
|
|
use tokio_tungstenite::connect_async;
|
|
|
|
#[tokio::test]
|
|
async fn websocket_handshake_should_be_accepted() {
|
|
let url = std::env::var("SDK_RELAY_WS").unwrap_or_else(|_| "ws://localhost:8090".to_string());
|
|
|
|
let (mut ws, _resp) = connect_async(url).await.expect("cannot connect ws");
|
|
|
|
let handshake = json!({
|
|
"type": "handshake",
|
|
"client_id": "test-client",
|
|
"version": "1.0.0",
|
|
"capabilities": ["sync", "notifications", "health"],
|
|
"timestamp": 1703001600u64
|
|
})
|
|
.to_string();
|
|
|
|
ws.send(tokio_tungstenite::tungstenite::Message::Text(handshake))
|
|
.await
|
|
.expect("cannot send handshake");
|
|
|
|
let msg = ws.next().await.expect("no response").expect("ws error");
|
|
let txt = msg.into_text().expect("not text");
|
|
let json: serde_json::Value = serde_json::from_str(&txt).expect("invalid json");
|
|
|
|
assert_eq!(json.get("type").and_then(|v| v.as_str()).unwrap_or(""), "handshake_response");
|
|
assert_eq!(json.get("status").and_then(|v| v.as_str()).unwrap_or(""), "accepted");
|
|
}
|