hevy 0.1.0

An async Rust client library for the Hevy public API (https://api.hevyapp.com/docs/)
Documentation
mod common;

use common::{TEST_API_KEY, client_for, mock_server};
use serde_json::json;
use wiremock::matchers::{header, method, path};
use wiremock::{Mock, ResponseTemplate};

#[tokio::test]
async fn get_user_info_unwraps_data_envelope() {
    let server = mock_server().await;
    let client = client_for(&server);

    Mock::given(method("GET"))
        .and(path("/v1/user/info"))
        .and(header("api-key", TEST_API_KEY))
        .respond_with(ResponseTemplate::new(200).set_body_json(json!({
            "data": {
                "id": "9c465af3-de7d-42bc-9c7c-f0170396358b",
                "name": "John doe",
                "url": "https://hevy.com/user/jhon"
            }
        })))
        .mount(&server)
        .await;

    let user = client.get_user_info().await.unwrap();
    assert_eq!(user.id, "9c465af3-de7d-42bc-9c7c-f0170396358b");
    assert_eq!(user.name, "John doe");
    assert_eq!(user.url, "https://hevy.com/user/jhon");
}

#[tokio::test]
async fn get_user_info_not_found_returns_error() {
    let server = mock_server().await;
    let client = client_for(&server);

    Mock::given(method("GET"))
        .and(path("/v1/user/info"))
        .respond_with(ResponseTemplate::new(404))
        .mount(&server)
        .await;

    let err = client.get_user_info().await.unwrap_err();
    assert!(matches!(err, hevy::HevyError::Api { status: 404, .. }));
}