use chrono::Duration;
use std::sync::Arc;
use tiny_counter::{EventStore, TestClock};
#[test]
fn cooldown_enforces_wait_period() {
let store = EventStore::new();
let result = store
.limit()
.cooldown("action", Duration::hours(1))
.check_and_record("action");
assert!(result.is_ok());
let result = store
.limit()
.cooldown("action", Duration::hours(1))
.check_and_record("action");
assert!(result.is_err());
}
#[test]
fn cooldown_allows_after_duration() {
let fixed_time = chrono::Utc::now();
let clock = TestClock::build_for_testing_at(fixed_time);
let store = EventStore::builder()
.with_clock(Arc::new(clock.clone()))
.build()
.unwrap();
store.record("action");
clock.advance(Duration::hours(2));
let result = store
.limit()
.cooldown("action", Duration::hours(1))
.check_and_record("action");
assert!(result.is_ok());
}