usesuper::*;use serde_json::json;/// RULE: A published read is one POST to the table's search route, the ask in the body (never in the URL), answered by the version and its rows.#[test]fn a_read_is_the_tables_search_route_and_its_rows() { assert_eq!(path("cotton", "places", "places"), "/v1/published/cotton/places/places/search");let answer = answer_of(Ok(json!({"publisher": "cotton", "name": "places", "table": "places", "version": "v1", "rows": [{"id": "geonames:1"}]}))).unwrap(); assert_eq!(answer, Answer { version: "v1".into(), rows: vec![json!({"id": "geonames:1"})] });}/// RULE: Nothing answering is offline, a credential the server no longer takes is signed out, and any other refusal keeps the server's own code and words.#[test]fn offline_signed_out_and_refused_are_told_apart() { assert_eq!(answer_of(Err(ObjectRefusal { status: 0, code: "offline".into(), message: "no route".into() })).unwrap_err(), Unread::Offline("no route".into())); assert_eq!(answer_of(Err(ObjectRefusal { status: 401, code: "invalid_credential".into(), message: "sign in again".into() })).unwrap_err(), Unread::SignedOut);let slow = answer_of(Err(ObjectRefusal { status: 429, code: "slow_down".into(), message: "too many reads".into() })).unwrap_err(); assert_eq!(slow, Unread::Refused { code: "slow_down".into(), message: "too many reads".into() });}/// RULE: A phone that is not signed in to its database reads nothing and says so; it never invents an empty answer.#[test]fn no_door_is_signed_out() {let root = tempfile::tempdir().unwrap();let layout = cotton_client::layout::Layout::new(root.path());let client = Arc::new(crate::shell::client::ClientController::new(layout, Arc::new(crate::events::EventBus::new()), Some("UTC".into()), None));let reader = PhoneReader::new(&client);let asked = reader.read("cotton", "places", "places", &Ask::Search { q: "hyd".into(), prefer: None, limit: 8 }); assert_eq!(asked, Err(Unread::SignedOut));}