use std::assert_matches;
use crate::{Version, country, json, tariff};
#[test]
fn a_rejected_tariff_keeps_the_earlier_warnings() {
const TARIFF_JSON: &str = r#"{
"country_code": "de",
"party_id": "ALL",
"id": "1",
"currency": "EUR",
"type": "REGULAR",
"elements": [],
"last_updated": "2018-12-05T12:01:09Z"
}
"#;
let doc = json::parse_object(TARIFF_JSON).unwrap();
let tariff = tariff::check(doc, Version::V221).ignore_warnings();
let failure = tariff::build(tariff).unwrap_err();
let (error, warnings) = failure.into_parts();
assert_matches!(error.into_warning(), tariff::Warning::NoElements);
let (element, _warning) = warnings
.find(|warning| {
matches!(
warning,
tariff::Warning::Country(country::Warning::IncorrectCase)
)
})
.expect("the rejection should keep the tariff's warning");
assert_eq!(element.path.as_str(), "$.country_code");
}