use super::*; use crate::shell::client::phone_tests::attached; use serde_json::json; #[test] fn the_today_reads_are_reads() { for method in ["cards.birthdays", "cards.moneyDue", "cards.factLabels"] { assert!(crate::methods::read_only(method), "{method}"); } } #[test] fn a_birthday_tomorrow_is_read_and_a_database_without_money_owes_nothing() { let (_dir, client) = attached(); let tomorrow = zoned_clock::local_day(client.clock().now().timestamp_millis(), "Asia/Kolkata").unwrap() + 1; let (_, month, day) = zoned_clock::civil_from_days(tomorrow); let birthday = format!("1990-{month:02}-{day:02}"); crate::phone::records::call(&client, "records.create", &json!({"table":"person","data":{"full_name":"Synthetic Asha","birthday":birthday}})) .unwrap(); let answer = birthdays(&client, &json!({"timezone":"Asia/Kolkata"})).unwrap(); let found = answer["birthdays"].as_array().unwrap(); assert_eq!(found.len(), 1, "{answer}"); assert_eq!(found[0]["name"], "Synthetic Asha"); assert_eq!(found[0]["in_days"], 1); assert_eq!(found[0]["when"], "tomorrow"); assert_eq!(money_due(&client, &json!({"timezone":"Asia/Kolkata"})).unwrap()["due"], json!([])); assert_eq!(birthdays(&client, &json!({"days":-1})).unwrap_err().code, "bad_request"); } // RULE (B1, 6 Nov 2026): Today lists a person whose birthday came whole from the object — the month, day and year empty on a signed-in copy — on their birthday, with the age they turn, as it lists one the phone made. #[test] fn today_lists_a_person_whose_birthday_the_object_keeps_whole_on_their_day() { use cotton_store::schema::package_shape::{add_served, served_column}; let (_dir, client) = attached(); let today = zoned_clock::local_day(client.clock().now().timestamp_millis(), "Asia/Kolkata").unwrap(); let (year, month, day) = zoned_clock::civil_from_days(today); let made = crate::phone::records::call(&client, "records.create", &json!({"table":"person","data":{"full_name":"Synthetic Bela"}})).unwrap(); let id = made["id"].as_str().or_else(|| made["record"]["id"].as_str()).expect("the new person's id").to_string(); client .with_writer(|file| { add_served(file.driver, "cotton_people", &[served_column("birthday", "date", false).map_err(|error| error.to_string())?]) .map_err(|error| error.to_string())?; let whole = format!("{}-{month:02}-{day:02}", year - 30); file.driver .run( "UPDATE cotton_people SET birthday = ?, birth_month = NULL, birth_day = NULL, birth_year = NULL WHERE id = ?", &[rusqlite::types::Value::Text(whole), rusqlite::types::Value::Text(id.clone())], ) .map_err(|error| error.to_string())?; Ok(()) }) .expect("the copy keeps the object's birthday"); let answer = birthdays(&client, &json!({"timezone":"Asia/Kolkata"})).unwrap(); let found = answer["birthdays"].as_array().unwrap(); assert_eq!(found.len(), 1, "{answer}"); assert_eq!(found[0]["id"], json!(id)); assert_eq!(found[0]["name"], "Synthetic Bela"); assert_eq!(found[0]["in_days"], 0); assert!(found[0]["turns"].as_str().is_some_and(|turns| turns.contains("30")), "{answer}"); } #[test] fn the_fact_labels_say_each_slot_and_a_faces_own() { let (_dir, client) = attached(); let labels = fact_labels(&client, &json!({})).unwrap()["labels"].clone(); assert_eq!(labels["slot"]["account"], "Account"); assert_eq!(labels["face"]["subscription"]["next_charge"], "Next charge"); }