Cotton code
54 lines · 2.4 KB · RustRaw
//! A person's languages (v109, the Me card) through the generic verbs the//! person page uses.mod support;use serde_json::json;use support::harness::Harness;use support::mcp::{call_tool, call_tool_raw, mint_token};// A language is one row per language with how well, written, corrected and// removed on its own; a value the table cannot hold is refused by name.#[test]fn a_persons_languages_are_added_corrected_and_removed() {    let mut h = Harness::new();    let token = mint_token(&mut h, &["read", "write"], "Synthetic languages agent");    let person = call_tool(&h, &token, "create_person", json!({"fullName":"Invented Mira"}))["id"]        .as_str()        .unwrap()        .to_owned();    let added = call_tool(        &h,        &token,        "create_record",        json!({"table":"person_language","data":{"person_id":person,"language":" Portuguese ","proficiency":"native"}}),    );    let id = added["record"]["id"].as_str().unwrap().to_owned();    assert_eq!(added["record"]["data"]["language"], "Portuguese");    assert_eq!(added["record"]["data"]["proficiency"], "native");    let second = call_tool(        &h,        &token,        "create_record",        json!({"table":"person_language","data":{"person_id":person,"language":"Hindi"}}),    );    assert_eq!(second["record"]["data"]["proficiency"], "fluent", "how well defaults to fluent");    assert_eq!(second["record"]["data"]["position"], 1, "a new language goes last");    let refused = call_tool_raw(        &h,        &token,        "create_record",        json!({"table":"person_language","data":{"person_id":person,"language":"Hindi","proficiency":"bilingual"}}),    );    assert!(refused.is_error, "{}", refused.text);    call_tool(&h, &token, "update_record", json!({"table":"person_language","id":id,"patch":{"proficiency":"conversational"}}));    let listed = call_tool(&h, &token, "list_records", json!({"table":"person_language","where":{"person_id":person}}));    let rows = listed["records"].as_array().unwrap();    assert_eq!(rows.len(), 2);    assert!(rows.iter().any(|row| row["id"] == id.as_str() && row["data"]["proficiency"] == "conversational"));    call_tool(&h, &token, "delete_record", json!({"table":"person_language","id":id}));    let after = call_tool(&h, &token, "list_records", json!({"table":"person_language","where":{"person_id":person}}));    assert_eq!(after["records"].as_array().unwrap().len(), 1);}