automapper-validation 0.1.65

AHB condition expression parsing, evaluation, and EDIFACT validation
Documentation
//! Contract test: ValidationIssue serialization includes instance_index
//! when Some and omits it when None.

use automapper_validation::{Severity, ValidationCategory, ValidationIssue};

#[test]
fn instance_index_serializes_when_some() {
    let issue = ValidationIssue::new(
        Severity::Error,
        ValidationCategory::Ahb,
        "AHB001",
        "required field missing",
    )
    .with_field_path("SG8/SG10/CCI/C240/7037")
    .with_instance_index(2);

    let json = serde_json::to_value(&issue).expect("serialize");
    assert_eq!(
        json.get("instance_index").and_then(|v| v.as_u64()),
        Some(2),
        "JSON should include instance_index=2 when set; got: {}",
        json,
    );
}

#[test]
fn instance_index_omitted_when_none() {
    let issue = ValidationIssue::new(
        Severity::Error,
        ValidationCategory::Ahb,
        "AHB001",
        "required field missing",
    )
    .with_field_path("SG8/SG10/CCI/C240/7037");

    let json = serde_json::to_value(&issue).expect("serialize");
    assert!(
        json.get("instance_index").is_none(),
        "JSON should omit instance_index when None; got: {}",
        json,
    );
}

#[test]
fn instance_index_round_trips_through_json() {
    let issue = ValidationIssue::new(
        Severity::Error,
        ValidationCategory::Ahb,
        "AHB001",
        "x",
    )
    .with_instance_index(5);

    let json = serde_json::to_string(&issue).unwrap();
    let parsed: ValidationIssue = serde_json::from_str(&json).unwrap();
    assert_eq!(parsed.instance_index, Some(5));
}