tiny-counter 0.1.0

Track event counts across time windows with fixed memory and fast queries
Documentation
//! Import operation tests - loading counters into EventStore.
//!
//! Tests import_event() and import_all() for restore scenarios.

use tiny_counter::EventStore;

#[test]
fn import_event_adds_to_store() {
    let source_store = EventStore::new();
    source_store.record_count("event", 50);

    let exported = source_store.export_all().unwrap();
    let counter = exported.get("event").unwrap().clone();

    let target_store = EventStore::new();
    target_store.import_event("event", counter).unwrap();

    assert_eq!(target_store.query("event").last_days(1).sum(), Some(50));
}

#[test]
fn import_all_adds_multiple_events() {
    let source_store = EventStore::new();
    source_store.record_count("event1", 10);
    source_store.record_count("event2", 20);
    source_store.record_count("event3", 30);

    let exported = source_store.export_all().unwrap();

    let target_store = EventStore::new();
    target_store.import_all(exported).unwrap();

    assert_eq!(target_store.query("event1").last_days(1).sum(), Some(10));
    assert_eq!(target_store.query("event2").last_days(1).sum(), Some(20));
    assert_eq!(target_store.query("event3").last_days(1).sum(), Some(30));
}

#[test]
fn import_overwrites_existing_event() {
    let target_store = EventStore::new();
    target_store.record_count("event", 100);

    let source_store = EventStore::new();
    source_store.record_count("event", 50);

    let exported = source_store.export_all().unwrap();
    target_store.import_all(exported).unwrap();

    // Import overwrites, so should be 50
    assert_eq!(target_store.query("event").last_days(1).sum(), Some(50));
}