2026-03-25 13:35:52 -05:00
|
|
|
mod common;
|
|
|
|
|
|
|
|
|
|
use wiremock::matchers::{header, method, path};
|
|
|
|
|
use wiremock::{Mock, ResponseTemplate};
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn test_ping_success() {
|
2026-03-25 14:11:08 -05:00
|
|
|
let (mock_server, client) = common::setup().await;
|
2026-03-25 13:35:52 -05:00
|
|
|
|
2026-03-25 14:11:08 -05:00
|
|
|
Mock::given(method("GET"))
|
|
|
|
|
.and(path("/Ping"))
|
|
|
|
|
.and(header("x-apikey", "test-api-key"))
|
|
|
|
|
.and(header("x-api-version", "2"))
|
|
|
|
|
.respond_with(ResponseTemplate::new(200))
|
|
|
|
|
.mount(&mock_server)
|
|
|
|
|
.await;
|
2026-03-25 13:35:52 -05:00
|
|
|
|
2026-03-25 14:11:08 -05:00
|
|
|
let result = client.ping().await;
|
|
|
|
|
assert!(result.is_ok());
|
2026-03-25 13:35:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn test_ping_unauthorized() {
|
2026-03-25 14:11:08 -05:00
|
|
|
let (mock_server, client) = common::setup().await;
|
2026-03-25 13:35:52 -05:00
|
|
|
|
2026-03-25 14:11:08 -05:00
|
|
|
Mock::given(method("GET"))
|
|
|
|
|
.and(path("/Ping"))
|
|
|
|
|
.respond_with(ResponseTemplate::new(401))
|
|
|
|
|
.mount(&mock_server)
|
|
|
|
|
.await;
|
2026-03-25 13:35:52 -05:00
|
|
|
|
2026-03-25 14:11:08 -05:00
|
|
|
let result = client.ping().await;
|
|
|
|
|
assert!(result.is_err());
|
2026-03-25 13:35:52 -05:00
|
|
|
|
2026-03-25 14:11:08 -05:00
|
|
|
if let Err(onspring::OnspringError::Api { status_code, .. }) = result {
|
|
|
|
|
assert_eq!(status_code, 401);
|
|
|
|
|
} else {
|
|
|
|
|
panic!("Expected Api error");
|
|
|
|
|
}
|
2026-03-25 13:35:52 -05:00
|
|
|
}
|