feat(domain): sheet.empty free op for a new sheet's document (V1-2.5 C)
Wraps create_empty_sheet_document; refusals invalid_shape / invalid_json; ts-rs SheetEmptyInput, core-wasm proof, app wrapper emptySheetDocument.
This commit is contained in:
1 parent
b0a4cbe588
commit
bbab0e61cb
8 files changed
+159
-4
No files matched your search
@@ -10,6 +10,7 @@ use faunosteo_core::domain::sheet::{
|
||||
SheetIssueSeverity, SheetView, check_sheet_document, create_empty_sheet_document,
|
||||
is_publishable, validate_sheet_document,
|
||||
};
|
||||
use faunosteo_core::facade::call;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
const MAIN_ASSET: &str = "3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8";
|
||||
@@ -476,6 +477,49 @@ fn the_empty_document_is_shape_valid_but_not_publishable() {
|
||||
assert!(create_empty_sheet_document("Not An Id", &name).is_err());
|
||||
}
|
||||
|
||||
fn sheet_empty(input: Value) -> Value {
|
||||
serde_json::from_str(&call("sheet.empty", &input.to_string())).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sheet_empty_answers_the_document_sheet_check_reads() {
|
||||
let name = json!({ "fr": "Nouvelle fiche", "en": "New sheet" });
|
||||
let out = sheet_empty(json!({ "species_id": "equine", "name": name }));
|
||||
assert_eq!(out["ok"], json!(true), "{out}");
|
||||
let document = out["value"].clone();
|
||||
assert_eq!(document["species_id"], json!("equine"));
|
||||
assert_eq!(document["name"], name);
|
||||
assert!(document.get("slug").is_none());
|
||||
let check: Value = serde_json::from_str(&call("sheet.check", &document.to_string())).unwrap();
|
||||
assert_eq!(check["ok"], json!(true), "{check}");
|
||||
let codes: Vec<&Value> = check["value"]["issues"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|issue| &issue["code"])
|
||||
.collect();
|
||||
assert_eq!(codes, [&json!("view.asset.missing")]);
|
||||
assert_eq!(check["value"]["publishable"], json!(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sheet_empty_refuses_a_bad_species_an_empty_label_or_an_unknown_field() {
|
||||
let name = json!({ "fr": "Nouvelle fiche", "en": "New sheet" });
|
||||
for input in [
|
||||
json!({ "species_id": "Not An Id", "name": name }),
|
||||
json!({ "species_id": "equine", "name": { "fr": "", "en": "New sheet" } }),
|
||||
json!({ "species_id": "equine", "name": { "fr": "Nouvelle fiche" } }),
|
||||
json!({ "species_id": "equine", "name": name, "slug": "equine" }),
|
||||
json!({ "name": name }),
|
||||
] {
|
||||
let out = sheet_empty(input.clone());
|
||||
assert_eq!(out["ok"], json!(false), "{input}");
|
||||
assert_eq!(out["kind"], json!("invalid_shape"), "{input}");
|
||||
}
|
||||
let out: Value = serde_json::from_str(&call("sheet.empty", "{ not json")).unwrap();
|
||||
assert_eq!(out["kind"], json!("invalid_json"));
|
||||
}
|
||||
|
||||
/// True for a `{ fr?, en? }` label object, the only thing a translator edits.
|
||||
fn is_label(value: &Value) -> bool {
|
||||
value
|
||||
|
||||
Reference in new issue
Block a user