//! Days' Google group, shaped from the object's status (`google.status`), against a made-up object. use serde_json::json; use super::*; /// 22 Nov 2026, 10:30 in Kolkata. const NOW: i64 = 1_795_323_600_000; fn at() -> At { At::of(&json!({ "timezone": "Asia/Kolkata", "now": NOW })).unwrap() } fn status(accounts: serde_json::Value) -> serde_json::Value { json!({ "available": true, "accounts": accounts }) } fn one(calendar: serde_json::Value) -> serde_json::Value { shape(Some(&status(json!([{ "googleEmail": "walk@example.test", "calendar": calendar }]))), &at()).unwrap() } // RULE: with no account connected, Days offers Connect Google Calendar as the Calendar tool's act, with the notice // the phone shows before Google's page (GOOGLE.md §4), and lists none. #[test] fn nothing_connected_offers_connect_with_its_notice() { let shaped = shape(Some(&status(json!([]))), &at()).unwrap(); assert_eq!(shaped["accounts"], json!([])); let connect = &shaped["connect"]; assert_eq!((connect["id"].as_str(), connect["tool"].as_str(), connect["label"].as_str()), (Some("google_connect"), Some("calendar"), Some("Connect Google Calendar"))); let notice = &connect["notice"]; assert_eq!(notice["go"], "Continue to Google"); assert_eq!(notice["notNow"], "Not now"); let body = notice["body"].as_str().unwrap(); assert!(body.contains("main calendar") && body.contains("assistant") && body.contains("disconnect"), "{body}"); assert!(shaped["unavailable"].is_null()); } // RULE: a connected account stands by its address with when its events were last brought in and how many; Connect is // not drawn beside it; its Disconnect asks first, saying the events from Google leave and the person's own stay. #[test] fn a_connected_account_says_its_last_sync_and_offers_disconnect() { // Brought in at 10:05 Kolkata time, 25 minutes before now. let shaped = one(json!({ "phase": "synced", "syncedAt": "2026-11-22T04:35:00.000Z", "eventCount": 312, "lastError": null })); assert!(shaped["connect"].is_null()); let account = &shaped["accounts"][0]; assert_eq!(account["email"], "walk@example.test"); assert_eq!(account["says"], "Last brought in today at 10:05 · 312 events"); assert_eq!(account["trouble"], false); let disconnect = &account["disconnect"]; assert_eq!((disconnect["id"].as_str(), disconnect["account"].as_str(), disconnect["label"].as_str()), (Some("google_disconnect"), Some("walk@example.test"), Some("Disconnect"))); assert_eq!(disconnect["asks"], "Disconnect walk@example.test? Days stops bringing in its events, and the 312 events from Google leave Days. Your own stay."); } // RULE: the last sync reads yesterday, a weekday within the week, or the date further back, in the phone's zone. #[test] fn the_last_sync_reads_by_how_long_ago() { let says = |iso: &str| one(json!({ "phase": "synced", "syncedAt": iso, "eventCount": 1 }))["accounts"][0]["says"].as_str().unwrap().to_string(); assert_eq!(says("2026-11-21T16:10:00.000Z"), "Last brought in yesterday at 21:40 · 1 event"); assert!(says("2026-11-18T03:30:00.000Z").starts_with("Last brought in on "), "a weekday"); assert_eq!(says("2026-11-01T03:30:00.000Z"), "Last brought in on 1 Nov at 9:00 · 1 event"); } // RULE: each other phase in words: still coming, Google stopped (Connect again stands), a pass that failed. #[test] fn each_phase_has_its_words() { assert_eq!(one(json!({ "phase": "waiting" }))["accounts"][0]["says"], "Bringing in its events…"); assert_eq!(one(json!({ "phase": "syncing" }))["accounts"][0]["says"], "Bringing in its events…"); let stopped = one(json!({ "phase": "reconnect", "lastError": "reconnect_required" })); assert_eq!(stopped["accounts"][0]["trouble"], true); assert_eq!(stopped["connect"]["label"], "Connect again"); let failed = one(json!({ "phase": "synced", "syncedAt": "2026-11-22T04:35:00.000Z", "eventCount": 4, "lastError": "google_unreachable" })); assert_eq!(failed["accounts"][0]["trouble"], true); assert!(failed["connect"].is_null()); } // RULE: Disconnect's ask fits how many events came from Google: one, or none. #[test] fn the_ask_fits_the_count() { let asks = |count: u64| one(json!({ "phase": "synced", "syncedAt": "2026-11-22T04:35:00.000Z", "eventCount": count }))["accounts"][0]["disconnect"]["asks"].as_str().unwrap().to_string(); assert!(asks(1).contains("the one event from Google leaves Days")); assert_eq!(asks(0), "Disconnect walk@example.test? Days stops bringing in its events."); } // RULE: a server that cannot connect Google, or a phone not signed in, offers no Connect and says why. #[test] fn nothing_to_connect_says_why() { let server = shape(Some(&json!({ "available": false, "accounts": [] })), &at()).unwrap(); assert!(server["connect"].is_null()); assert!(server["unavailable"].as_str().unwrap().contains("Google")); let signed_out = shape(None, &at()).unwrap(); assert!(signed_out["connect"].is_null()); assert!(signed_out["unavailable"].as_str().unwrap().starts_with("Sign in")); // Signed out, Sign in stands on the page (store pass, 24 Nov 2026); a server without Google offers none. assert_eq!(signed_out["signIn"], "Sign in"); assert!(server.get("signIn").is_none()); } // RULE: a disconnect is said by the account the object forgot and the events that left with it. #[test] fn a_disconnect_is_said_with_the_events_that_left() { assert_eq!( disconnected(&json!({ "ok": true, "account": "walk@example.test", "removed": 312 }), "Walk@example.test").unwrap(), json!({ "account": "walk@example.test", "removed": 312, "said": "walk@example.test is disconnected. Its 312 events left Days." }) ); assert_eq!(disconnected(&json!({ "ok": true, "account": "a@example.test", "removed": 1 }), "a@example.test").unwrap()["said"], "a@example.test is disconnected. Its one event left Days."); assert_eq!(disconnected(&json!({ "ok": true, "account": "a@example.test" }), "a@example.test").unwrap()["said"], "a@example.test is disconnected."); } // RULE: the phone's zone is asked for, as every Days read asks it. #[test] fn the_zone_is_required() { assert_eq!(At::of(&json!({})).err().unwrap().code, "bad_request"); }