//! The sheet document contract against the Zod oracles: the reference documents parse and //! print byte for byte as `JSON.stringify(AnatomicalSheetDocumentSchema.parse(x), null, 2)`. #![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)] mod common; use faunosteo_core::domain::js::parse_json; use faunosteo_core::domain::sheet::AnatomicalSheetDocument; use faunosteo_core::json::to_js_pretty; fn assert_like_zod(oracle: &str) { let (source, expected) = common::zod_oracle(oracle); let document: AnatomicalSheetDocument = serde_json::from_value(parse_json(&source).unwrap()).unwrap(); assert_eq!(to_js_pretty(&document).unwrap(), expected, "{oracle}"); } #[test] fn the_curated_draft_prints_as_zod_outputs_it() { assert_like_zod("sheet.draft.json"); } #[test] fn the_legacy_import_baseline_prints_as_zod_outputs_it() { assert_like_zod("sheet.legacy-import.json"); } #[test] fn the_bundled_payload_loads_and_indexes_the_draft() { use faunosteo_core::domain::sheet::{BundledSheetData, LoadedSheet}; let seed = "supabase/seed/anatomical-sheets/equine/draft"; let payload = serde_json::json!({ "status": "draft", "ref": { "sheet_id": "s", "version_id": null, "document_sha256": "0".repeat(64), "schema_version": 2, "species_id": "equine" }, "document": parse_json(&common::repo_file(&format!("{seed}/document.json"))).unwrap(), "migrationMap": parse_json(&common::repo_file(&format!("{seed}/report-migration-map.json"))).unwrap(), "assets": {}, "assetHashes": {} }); let data: BundledSheetData = serde_json::from_value(payload).unwrap(); let sheet = LoadedSheet::from_bundle(data).unwrap(); let indexed = sheet.indexed(); assert_eq!(indexed.main_view().id(), "main"); assert!( indexed.is_spine("c7-t1") || indexed .document .annotations .iter() .any(|a| indexed.is_spine(a.id())) ); assert!(indexed.annotation("hip").is_some()); }