Files
faunosteo/crates/core/tests/characterisation_serde_tolerance.rs
T

59 lines
1.9 KiB
Rust

//! Characterisation, not a requirement (owner 2026-10-23, R5.5 brief §7): the serde derives of
//! the R2 contracts read a struct from a positional array and a unit enum from a one-key map,
//! where the frozen Zod reader refused both. These cases pin today's Rust verdict so that any
//! change to the gated readers is visible; they are to be turned around, not extended, if the
//! owner decides a strict deserialisation (`docs/development/RUST.md` §11.16).
#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]
mod common;
use faunosteo_core::domain::report::Report;
use serde::Deserialize;
use serde_json::{Value, json};
fn demo() -> Value {
serde_json::from_str(&common::repo_file(
"apps/app/tests/fixtures/report-v3.demo.json",
))
.unwrap()
}
fn read(value: &Value) -> Result<Report, serde_json::Error> {
Report::deserialize(value)
}
#[test]
fn the_canonical_report_is_read() {
assert!(read(&demo()).is_ok());
}
#[test]
fn a_struct_written_as_a_positional_array_is_accepted_where_zod_refused() {
let mut sheet = demo();
let parts = [
sheet["sheet"]["sheetId"].clone(),
Value::Null,
sheet["sheet"]["documentSha256"].clone(),
];
sheet["sheet"] = json!(parts);
let mut practitioner = demo();
let p = practitioner["practitioner"].clone();
practitioner["practitioner"] = json!([p["name"], p["cabinet"], p["contact"], p["siret"]]);
assert!(read(&sheet).is_ok());
assert!(read(&practitioner).is_ok());
}
#[test]
fn a_unit_enum_written_as_a_one_key_map_is_accepted_where_zod_refused() {
let mut report = demo();
report["observations"][0]["severity"] = json!({ "mild": null });
assert!(read(&report).is_ok());
}
#[test]
fn an_unknown_field_is_accepted_as_the_non_strict_zod_objects_did() {
let mut report = demo();
report["extra"] = json!(1);
assert!(read(&report).is_ok());
}