videosdk-server-sdk 0.1.0

Rust server SDK for the VideoSDK v2 REST APIs
Documentation
//! Helpers shared by the crate's tests.

use std::time::Duration;

use wiremock::{MockServer, Request};

use crate::client::Client;

/// A client pointed at the mock server, with backoff removed so retry tests
/// don't actually sleep.
pub(crate) fn client(server: &MockServer) -> Client {
    Client::builder()
        .api_key("test-key")
        .secret("test-secret")
        .base_url(server.uri())
        .backoff(|_| Duration::ZERO)
        .build()
        .expect("client builds")
}

/// Every request the mock server received, in order.
pub(crate) async fn requests(server: &MockServer) -> Vec<Request> {
    server.received_requests().await.expect("recording enabled")
}

/// The single request the mock server received.
pub(crate) async fn only_request(server: &MockServer) -> Request {
    let mut received = requests(server).await;
    assert_eq!(received.len(), 1, "expected exactly one request");
    received.remove(0)
}

/// Reads a header off a recorded request.
pub(crate) fn header(request: &Request, name: &str) -> Option<String> {
    request
        .headers
        .get(name)
        .and_then(|value| value.to_str().ok())
        .map(str::to_string)
}

/// The JSON body of a recorded request.
pub(crate) fn body(request: &Request) -> serde_json::Value {
    serde_json::from_slice(&request.body).expect("a JSON body")
}