atproto-devtool 0.1.1

A multitool for the atproto developer ecosystem
Documentation
//! Smoke tests for shared fake test helpers.

mod common;

use atproto_devtool::commands::test::labeler::create_report::CreateReportTee;
use common::*;
use reqwest::StatusCode;

#[tokio::test]
async fn fake_create_report_tee_serves_scripted_responses_and_records_requests() {
    let fake = FakeCreateReportTee::new();
    fake.enqueue(FakeCreateReportResponse::unauthorized(
        "AuthenticationRequired",
        "jwt required",
    ));
    fake.enqueue(FakeCreateReportResponse::ok_empty());

    let body1 = serde_json::json!({"a": 1});
    let resp1 = fake
        .post_create_report(None, &body1)
        .await
        .expect("fake returns Ok");
    assert_eq!(resp1.status, StatusCode::UNAUTHORIZED);
    let envelope: serde_json::Value = serde_json::from_slice(&resp1.raw_body).unwrap();
    assert_eq!(envelope["error"], "AuthenticationRequired");

    let body2 = serde_json::json!({"b": 2});
    let resp2 = fake
        .post_create_report(Some("abc.def.ghi"), &body2)
        .await
        .expect("fake returns Ok");
    assert_eq!(resp2.status, StatusCode::OK);

    let recorded = fake.recorded_requests();
    assert_eq!(recorded.len(), 2);
    assert_eq!(recorded[0].auth, None);
    assert_eq!(recorded[0].body, body1);
    assert_eq!(recorded[1].auth.as_deref(), Some("abc.def.ghi"));
    assert_eq!(recorded[1].body, body2);
}

#[tokio::test]
#[should_panic(expected = "no script queued")]
async fn fake_create_report_tee_panics_on_unscripted_call() {
    let fake = FakeCreateReportTee::new();
    let _ = fake.post_create_report(None, &serde_json::json!({})).await;
}