#![allow(unused_imports)]
use crate::sdk::{self, types};
use crate::support;
#[tokio::test]
async fn reports_api_errors() {
let body = support::json(r#"{"code":"not_found","message":"No such resource.","details":{"field":"id"}}"#);
let reply = support::Reply::json(404, body).header("x-request-id", "req_test");
let api = support::MockApi::start(vec![reply]).await;
let params: types::OrdersGetParams = support::from_json(r#"{"token":"token 1"}"#);
let error = api.client().orders().get("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "1234567890123456", params).await.unwrap_err();
assert!(matches!(error, sdk::Error::Api { .. }), "{error:?}");
assert_eq!(error.status(), Some(404));
assert_eq!(error.code(), "not_found");
assert_eq!(error.request_id(), Some("req_test"));
assert_eq!(error.details().and_then(|d| d.get("field")), Some(&"id".into()));
assert_eq!(error.to_string(), "No such resource. (404 not_found, request req_test)");
assert_eq!(api.calls().await.len(), 1);
}
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "order",
"id": "id 1",
"currency": "currency 1",
"subtotalCents": 1,
"totalCents": 1,
"products": [
{
"id": "id 1",
"name": "name 1",
"quantity": 1,
"priceCents": 1,
"currency": "currency 1",
"imageUrl": "imageUrl 1"
}
],
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::OrdersGetParams = support::from_json(r#"{"token":"token 1"}"#);
let result = api.client().orders().get("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "1234567890123456", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/orders/1234567890123456");
assert_eq!(calls[0].query, support::pairs(&[("token", "token 1")]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}