use incident_io::apis::incidents_v2_api::IncidentsV2ListParams;
use incident_io::models::policy_reminder_cadence_v2::Interval;
#[test]
fn a_params_struct_with_no_required_fields_takes_no_arguments() {
let params = IncidentsV2ListParams::new().set_page_size(25);
assert_eq!(params.page_size, Some(25));
}
#[test]
fn a_params_struct_names_its_required_fields() {
use incident_io::apis::incidents_v2_api::IncidentsV2ShowParams;
let params = IncidentsV2ShowParams::new("01ABC");
assert_eq!(params.id, "01ABC");
}
#[test]
fn setters_chain_and_unwrap() {
let params = IncidentsV2ListParams::new()
.set_page_size(100)
.set_after("01ABC");
assert_eq!(params.page_size, Some(100));
assert_eq!(params.after.as_deref(), Some("01ABC"));
}
#[test]
fn a_setter_unwraps_a_boxed_field_too() {
use incident_io::models::{IncidentsListResultV2, PaginationMetaResultWithTotalV2};
let result = IncidentsListResultV2::new()
.set_pagination_meta(PaginationMetaResultWithTotalV2::new().set_page_size(25));
assert_eq!(result.pagination_meta.map(|meta| meta.page_size), Some(25));
}
#[test]
fn a_response_model_constructor_takes_no_arguments() {
use incident_io::models::IncidentV2;
let incident = IncidentV2::new().set_reference("INC-123");
assert_eq!(incident.reference, "INC-123");
}
#[test]
fn a_request_payload_constructor_names_its_required_fields() {
use incident_io::models::incidents_create_payload_v2::Visibility;
use incident_io::models::IncidentsCreatePayloadV2;
let payload = IncidentsCreatePayloadV2::new("once-only", Visibility::Public);
assert_eq!(payload.idempotency_key, "once-only");
}
#[test]
fn a_parameterless_endpoint_still_takes_a_params_struct() {
use incident_io::apis::severities_v1_api::SeveritiesV1ListParams;
let _ = SeveritiesV1ListParams::new();
let _ = SeveritiesV1ListParams::default();
}
#[test]
fn an_unknown_enum_value_deserialises_rather_than_failing() {
let parsed: Interval = serde_json::from_str("\"hourly\"").unwrap();
assert_eq!(parsed, Interval::Unknown("hourly".to_owned()));
}
#[test]
fn an_unknown_enum_value_round_trips_unchanged() {
let parsed: Interval = serde_json::from_str("\"hourly\"").unwrap();
assert_eq!(serde_json::to_string(&parsed).unwrap(), "\"hourly\"");
}
#[test]
fn distinct_unknown_values_stay_distinct() {
let one: Interval = serde_json::from_str("\"hourly\"").unwrap();
let two: Interval = serde_json::from_str("\"fortnightly\"").unwrap();
assert_ne!(one, two);
}
#[test]
fn known_enum_values_are_unaffected() {
let parsed: Interval = serde_json::from_str("\"daily\"").unwrap();
assert_eq!(parsed, Interval::Daily);
assert_eq!(serde_json::to_string(&parsed).unwrap(), "\"daily\"");
}
#[test]
fn the_readme_enum_example_compiles() {
use incident_io::models::incident_v2::Mode;
fn describe(mode: &Mode) -> String {
match mode {
Mode::Standard => "standard".to_owned(),
Mode::Retrospective => "retrospective".to_owned(),
other => format!("unhandled mode: {other:?}"),
}
}
assert_eq!(describe(&Mode::Standard), "standard");
assert_eq!(
describe(&Mode::Unknown("from_the_future".to_owned())),
"unhandled mode: Unknown(\"from_the_future\")"
);
}
#[test]
fn matching_an_operation_error_needs_a_wildcard_arm() {
use incident_io::apis::{incidents_v2_api::IncidentsV2ListError, Error, ResponseContent};
fn describe(error: &Error<IncidentsV2ListError>) -> String {
match error {
Error::ResponseError(response) => match &response.entity {
Some(IncidentsV2ListError::Status401(_)) => "bad API key".to_owned(),
Some(IncidentsV2ListError::Status429(_)) => "rate limited".to_owned(),
_ => format!("HTTP {}: {}", response.status, response.content),
},
other => format!("request failed: {other}"),
}
}
let unknown = Error::ResponseError(ResponseContent::new(
reqwest::StatusCode::IM_A_TEAPOT,
"short and stout".to_owned(),
Some(IncidentsV2ListError::UnknownValue(serde_json::Value::Null)),
));
assert_eq!(describe(&unknown), "HTTP 418 I'm a teapot: short and stout");
}
#[test]
fn the_readme_configuration_example_compiles() {
use incident_io::apis::configuration::Configuration;
use std::time::Duration;
let defaults = Configuration::new();
assert_eq!(defaults.base_path, "https://api.incident.io");
assert!(defaults
.user_agent
.as_deref()
.is_some_and(|agent| agent.starts_with("incident-io-sdk-rust/")));
let mut config = Configuration::new();
config.bearer_access_token = Some("my-api-key".to_owned());
config.user_agent = Some("my-app/1.0.0".to_owned());
config.base_path = "https://api.incident.io".to_owned();
config.client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()
.unwrap();
assert_eq!(config.user_agent.as_deref(), Some("my-app/1.0.0"));
}
#[test]
fn the_readme_alert_ingest_example_compiles() {
use incident_io::apis::configuration::Configuration;
use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION};
let alert_source_secret = "secret-from-the-alert-source";
let mut headers = HeaderMap::new();
headers.insert(
AUTHORIZATION,
HeaderValue::from_str(&format!("Bearer {alert_source_secret}")).unwrap(),
);
let mut config = Configuration::new();
config.client = reqwest::Client::builder()
.default_headers(headers)
.build()
.unwrap();
assert!(config.bearer_access_token.is_none());
}
#[test]
fn the_readme_payload_example_compiles() {
use incident_io::apis::incidents_v2_api::IncidentsV2CreateParams;
use incident_io::models::incidents_create_payload_v2::Visibility;
use incident_io::models::IncidentsCreatePayloadV2;
let idempotency_key = "once-only".to_owned();
let body = IncidentsCreatePayloadV2::new(idempotency_key, Visibility::Public)
.set_name("Checkout is down");
let params = IncidentsV2CreateParams::new(body);
assert_eq!(
params.incidents_create_payload_v2.name.as_deref(),
Some("Checkout is down")
);
}
#[test]
fn the_readme_pagination_example_compiles() {
use incident_io::apis::incidents_v2_api::IncidentsV2ListParams;
let after: Option<String> = Some("01ABC".to_owned());
let mut params = IncidentsV2ListParams::new().set_page_size(100);
if let Some(cursor) = &after {
params = params.set_after(cursor);
}
assert_eq!(params.page_size, Some(100));
assert_eq!(params.after.as_deref(), Some("01ABC"));
}
#[test]
fn string_arguments_accept_a_str() {
use incident_io::apis::incidents_v2_api::IncidentsV2ShowParams;
use incident_io::models::incidents_create_payload_v2::Visibility;
use incident_io::models::IncidentsCreatePayloadV2;
let params = IncidentsV2ShowParams::new("01ABC");
let payload =
IncidentsCreatePayloadV2::new("once-only", Visibility::Public).set_name("Checkout is down");
assert_eq!(params.id, "01ABC");
assert_eq!(payload.idempotency_key, "once-only");
assert_eq!(payload.name.as_deref(), Some("Checkout is down"));
let owned = IncidentsV2ShowParams::new(String::from("01DEF"));
assert_eq!(owned.id, "01DEF");
}
#[test]
fn a_dual_purpose_model_has_no_required_arguments() {
use incident_io::models::AlertSourceJiraOptionsV2;
let _ = AlertSourceJiraOptionsV2::new();
}