ocpi-tariffs 0.54.0

OCPI tariff calculations
Documentation
//! The linter reads each restriction bound once and hands the value to every check that needs it.
//! `warning::test::assert_warnings`, which checks the fixtures under `test_data/v221/lint/`,
//! collects the ids at each path into a set, so a fixture can't show a warning raised twice. These
//! tests compare the list of ids at each path instead.

use std::collections::BTreeMap;

use crate::{Version, json, tariff, test, warning};

#[test]
fn a_bound_that_cannot_be_read_is_reported_once() {
    test::setup();

    // `lint_zero` and the pair check against `min_duration` both use `max_duration`. A duration
    // can't be negative, so the linter can't read this one.
    let source = r#"{
        "country_code": "NL",
        "party_id": "TDR",
        "currency": "EUR",
        "id": "ID",
        "last_updated": "2024-01-01T00:00:00Z",
        "elements": [
            {
                "price_components": [{"price": 0.25, "step_size": 1, "type": "ENERGY"}],
                "restrictions": {"min_duration": 10, "max_duration": -5}
            }
        ]
    }"#;

    let doc = json::parse_object(source).unwrap();
    let tariff = tariff::from_json(doc, Version::V221).ignore_warnings();
    let warnings = tariff::lint(&tariff).warnings;

    assert_eq!(
        warnings.path_id_map(),
        BTreeMap::from([(
            "$.elements[0].restrictions.max_duration",
            vec![warning::Id::from_static("invalid")],
        )]),
    );
}