use chrono::NaiveDate;
use ramadan_cli::commands::ramadan::{
RamadanOutput, get_json_error_code, get_roza_number_from_start_date, normalize_city_alias,
to_12_hour_time,
};
#[test]
fn json_contract_uses_expected_error_codes() {
assert_eq!(
get_json_error_code("Could not fetch Ramadan calendar. failed"),
"RAMADAN_CALENDAR_FETCH_FAILED"
);
assert_eq!(
get_json_error_code("Could not detect location. Pass a city."),
"LOCATION_DETECTION_FAILED"
);
}
#[test]
fn json_contract_has_hijri_year_field() {
let output = RamadanOutput {
mode: "all".to_string(),
location: "San Francisco, United States".to_string(),
hijri_year: 1447,
rows: vec![],
};
let value = serde_json::to_value(output).expect("output should serialize");
assert!(value.get("hijriYear").is_some());
assert!(value.get("hijri_year").is_none());
}
#[test]
fn contract_core_helpers_match_expected() {
assert_eq!(normalize_city_alias("sf"), "San Francisco");
assert_eq!(to_12_hour_time("17:38"), "5:38 PM");
let first = NaiveDate::from_ymd_opt(2026, 2, 18).expect("valid date");
let target = NaiveDate::from_ymd_opt(2026, 2, 20).expect("valid date");
assert_eq!(get_roza_number_from_start_date(first, target), 3);
}