use super::*;
#[test]
fn a_credential_reports_its_expiry_and_whether_it_can_renew() {
let now = chrono::Utc::now().timestamp_millis();
let live = link_assistant_router::subscription::SubscriptionToken {
access_token: "a".into(),
refresh_token: Some("r".into()),
expires_at_ms: Some(now + 3 * 3_600_000),
account_id: None,
resource_url: None,
};
let report = describe_credential(&live);
assert!(report.contains("expires in"), "{report}");
assert!(report.contains("refresh token present"), "{report}");
}
#[test]
fn an_expired_credential_is_named_as_expired() {
let now = chrono::Utc::now().timestamp_millis();
let dead = link_assistant_router::subscription::SubscriptionToken {
access_token: "a".into(),
refresh_token: None,
expires_at_ms: Some(now - 3 * 3_600_000),
account_id: None,
resource_url: None,
};
let report = describe_credential(&dead);
assert!(report.contains("EXPIRED"), "{report}");
assert!(
report.contains("NO refresh token"),
"a credential that cannot be renewed must say so: {report}"
);
}
#[test]
fn an_unrecorded_expiry_is_not_reported_as_expired() {
let unknown = link_assistant_router::subscription::SubscriptionToken {
access_token: "a".into(),
refresh_token: Some("r".into()),
expires_at_ms: None,
account_id: None,
resource_url: None,
};
let report = describe_credential(&unknown);
assert!(report.contains("no recorded expiry"), "{report}");
assert!(!report.contains("EXPIRED"), "{report}");
}
#[test]
fn durations_read_at_a_glance_at_each_threshold() {
assert_eq!(humanize_minutes(45), "45 minutes");
assert_eq!(
humanize_minutes(89),
"89 minutes",
"the last minute reading"
);
assert_eq!(humanize_minutes(90), "1 hours", "the first hour reading");
assert_eq!(
humanize_minutes(119),
"1 hours",
"truncation the doc comment claims to have removed still applies here"
);
assert_eq!(humanize_minutes(120), "2 hours");
assert_eq!(
humanize_minutes(60 * 47),
"47 hours",
"the last hour reading"
);
assert_eq!(humanize_minutes(60 * 48), "2 days", "the first day reading");
}