ocpi-tariffs 0.52.0

OCPI tariff calculations
Documentation
use crate::{json, tariff, test};

/// Read a tariff that sets every `v2.2.1` field against the `v2.1.1` schema, and assert
/// everything the walk reports about the version difference.
#[test]
fn should_parse_v221_tariff_json_as_v211_with_warnings() {
    const TARIFF_JSON: &str = include_str!("../../../test_data/v221/every_field_set/tariff.json");

    test::setup();
    let (tariff, warnings) = tariff::from_json(
        json::parse_object(TARIFF_JSON).unwrap(),
        crate::Version::V211,
    )
    .into_parts();

    test::assert_schema_warnings(
        &warnings,
        &[
            // Fields `v2.2.1` added, which `v2.1.1` does not define.
            ("$.country_code", &["unexpected_field"]),
            ("$.party_id", &["unexpected_field"]),
            ("$.type", &["unexpected_field"]),
            ("$.end_date_time", &["unexpected_field"]),
            ("$.max_price", &["unexpected_field"]),
            ("$.min_price", &["unexpected_field"]),
            (
                "$.elements[0].price_components[0].vat",
                &["unexpected_field"],
            ),
            (
                "$.elements[1].price_components[0].vat",
                &["unexpected_field"],
            ),
            (
                "$.elements[2].price_components[0].vat",
                &["unexpected_field"],
            ),
            (
                "$.elements[0].restrictions.max_current",
                &["unexpected_field"],
            ),
            (
                "$.elements[0].restrictions.min_current",
                &["unexpected_field"],
            ),
            (
                "$.elements[0].restrictions.reservation",
                &["unexpected_field"],
            ),
            // `EnvironmentalImpact` names its required category field `source` in `v2.1.1` and
            // `category` in `v2.2.1`, so each entry reports the rename from both sides.
            (
                "$.energy_mix.environ_impact[0].category",
                &["unexpected_field"],
            ),
            (
                "$.energy_mix.environ_impact[1].category",
                &["unexpected_field"],
            ),
            ("$.energy_mix.environ_impact[0]", &["missing_field(source)"]),
            ("$.energy_mix.environ_impact[1]", &["missing_field(source)"]),
        ],
    );

    let tariff = tariff.to_v221().unwrap();
    let (_tariff, warnings) = tariff.into_parts();
    assert!(warnings.is_empty());
}