use crate::{json, schema, test, warning};
const TARIFF: &str = r#"{
"country_code": "NLD",
"party_id": "ENE",
"currency": "EUR"
}"#;
#[test]
fn should_list_every_id_once() {
test::setup();
let doc = json::parse_object(TARIFF).unwrap();
let root = doc.root();
let country_code = root.find_field("country_code").unwrap().element();
let currency = root.find_field("currency").unwrap().element();
let mut warnings = warning::Set::<schema::Warning>::new();
warnings.insert(country_code, schema::Warning::NonSpecField);
warnings.insert(country_code, schema::Warning::UnexpectedField);
warnings.insert(currency, schema::Warning::NullField);
warnings.insert(currency, schema::Warning::UnexpectedField);
let ids = warnings.ids();
let ids: Vec<&str> = ids.iter().map(warning::Id::as_str).collect();
assert_eq!(ids, ["non_spec_field", "null_field", "unexpected_field"]);
}
#[test]
fn should_list_one_id_for_each_missing_field() {
test::setup();
let doc = json::parse_object(TARIFF).unwrap();
let root = doc.root();
let mut warnings = warning::Set::<schema::Warning>::new();
warnings.insert(
root,
schema::Warning::MissingField {
name: "start_date_time",
},
);
warnings.insert(
root,
schema::Warning::MissingField {
name: "last_updated",
},
);
let ids = warnings.ids();
let ids: Vec<&str> = ids.iter().map(warning::Id::as_str).collect();
assert_eq!(
ids,
[
"missing_field(last_updated)",
"missing_field(start_date_time)"
]
);
}