mod common;
use wiremock::matchers::{header, method, path};
use wiremock::{Mock, MockServer, ResponseTemplate};
#[tokio::test]
async fn api_key_sent_with_default_http_client() {
let (server, client) = common::mock_client().await;
Mock::given(method("GET"))
.and(path("/v1/exchanges"))
.and(header("X-Api-Key", "key_test.secret"))
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!([])))
.mount(&server)
.await;
let exchanges = client.exchanges().list().await.unwrap();
assert!(exchanges.is_empty());
}
#[tokio::test]
async fn api_key_sent_with_custom_http_client() {
let server = MockServer::start().await;
Mock::given(method("GET"))
.and(path("/v1/exchanges"))
.and(header("X-Api-Key", "key_custom.secret"))
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!([])))
.mount(&server)
.await;
let http = reqwest::Client::builder().build().unwrap();
let client = ticksupply::Client::builder()
.api_key("key_custom.secret")
.base_url(format!("{}/v1", server.uri()))
.http_client(http)
.build()
.unwrap();
let exchanges = client.exchanges().list().await.unwrap();
assert!(exchanges.is_empty());
}