ocpi-tariffs 0.44.0

OCPI tariff calculations
Documentation
use assert_matches::assert_matches;

use crate::json::{self, FromJson};

use super::Restrictions;

#[test]
fn should_parse_restrictions_empty_object() {
    const JSON: &str = "{}";

    let elem = json::parse(JSON).unwrap();
    let (restrictions, warnings) = Restrictions::from_json(&elem).unwrap().into_parts();
    assert!(warnings.is_empty(), "{:#?}", warnings.path_id_map());

    assert_matches!(
        restrictions,
        Restrictions {
            start_time: None,
            end_time: None,
            start_date: None,
            end_date: None,
            min_current: None,
            max_current: None,
            min_kwh: None,
            max_kwh: None,
            min_power: None,
            max_power: None,
            min_duration: None,
            max_duration: None,
            day_of_week: None
        }
    );
}

#[test]
fn should_parse_restrictions_all_null() {
    const JSON: &str = r#"{
            "start_time": null,
            "end_time": null,
            "start_date": null,
            "end_date": null,
            "min_current": null,
            "max_current": null,
            "min_kwh": null,
            "max_kwh": null,
            "min_power": null,
            "max_power": null,
            "min_duration": null,
            "max_duration": null,
            "days_of_week": null
        }"#;

    let elem = json::parse(JSON).unwrap();
    let (restrictions, warnings) = Restrictions::from_json(&elem).unwrap().into_parts();
    assert!(warnings.is_empty(), "{:#?}", warnings.path_id_map());

    assert_matches!(
        restrictions,
        Restrictions {
            start_time: None,
            end_time: None,
            start_date: None,
            end_date: None,
            min_current: None,
            max_current: None,
            min_kwh: None,
            max_kwh: None,
            min_power: None,
            max_power: None,
            min_duration: None,
            max_duration: None,
            day_of_week: None
        }
    );
}

#[test]
fn should_parse_restrictions_day_of_week_empty() {
    const JSON: &str = r#"{
            "start_time": null,
            "end_time": null,
            "start_date": null,
            "end_date": null,
            "min_current": null,
            "max_current": null,
            "min_kwh": null,
            "max_kwh": null,
            "min_power": null,
            "max_power": null,
            "min_duration": null,
            "max_duration": null,
            "days_of_week": []
        }"#;

    let elem = json::parse(JSON).unwrap();
    let (restrictions, warnings) = Restrictions::from_json(&elem).unwrap().into_parts();
    assert!(warnings.is_empty(), "{:#?}", warnings.path_id_map());

    assert_matches!(
        restrictions,
        Restrictions {
            start_time: None,
            end_time: None,
            start_date: None,
            end_date: None,
            min_current: None,
            max_current: None,
            min_kwh: None,
            max_kwh: None,
            min_power: None,
            max_power: None,
            min_duration: None,
            max_duration: None,
            day_of_week: None
        }
    );
}