Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions tests/snapshots/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn with_queued_repo() {
}

#[test]
fn find_with_snapshots() {
fn get_all_with_snapshots() {
let repo = HashMapRepository::new()
.aggregate::<Todo>()
.with_snapshots(2);
Expand All @@ -212,14 +212,13 @@ fn find_with_snapshots() {
todo2.complete().unwrap();
repo.commit(&mut todo2).unwrap();

// Find all completed
let completed = repo.find(|t| t.snapshot().completed).unwrap();
assert_eq!(completed.len(), 2);
let todos = repo.get_all(&["t1", "t2"]).unwrap();
assert_eq!(todos.len(), 2);
assert!(todos.iter().all(|todo| todo.snapshot().completed));

// Find alice's todos
let alice = repo.find(|t| t.snapshot().user_id == "alice").unwrap();
assert_eq!(alice.len(), 1);
assert_eq!(alice[0].snapshot().task, "Buy milk");
let alice = repo.get("t1").unwrap().unwrap();
assert_eq!(alice.snapshot().user_id, "alice");
assert_eq!(alice.snapshot().task, "Buy milk");
}

#[test]
Expand Down
155 changes: 0 additions & 155 deletions tests/todos/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,161 +589,6 @@ fn outbox_worker_process_next_with_commit() {
assert_eq!(lines.len(), 3);
}

#[test]
fn find_returns_matching_aggregates() {
let repo = HashMapRepository::new().aggregate::<Todo>();

// Create todos for different users
let mut todo1 = Todo::new();
let id1 = next_id();
todo1
.initialize(
id1.clone(),
"alice".to_string(),
"Buy groceries".to_string(),
)
.unwrap();

let mut todo2 = Todo::new();
let id2 = next_id();
todo2
.initialize(id2.clone(), "alice".to_string(), "Walk the dog".to_string())
.unwrap();

let mut todo3 = Todo::new();
let id3 = next_id();
todo3
.initialize(id3.clone(), "bob".to_string(), "Write code".to_string())
.unwrap();

repo.commit_all(&mut [&mut todo1, &mut todo2, &mut todo3])
.unwrap();

// Find all todos for alice
let alice_todos = repo.find(|t| t.snapshot().user_id == "alice").unwrap();
assert_eq!(alice_todos.len(), 2);

// Find all todos for bob
let bob_todos = repo.find(|t| t.snapshot().user_id == "bob").unwrap();
assert_eq!(bob_todos.len(), 1);
assert_eq!(bob_todos[0].snapshot().task, "Write code");

// Find with no matches
let charlie_todos = repo.find(|t| t.snapshot().user_id == "charlie").unwrap();
assert!(charlie_todos.is_empty());
}

#[test]
fn find_one_returns_first_matching_aggregate() {
let repo = HashMapRepository::new().aggregate::<Todo>();

let mut todo1 = Todo::new();
let id1 = next_id();
todo1
.initialize(id1.clone(), "alice".to_string(), "First task".to_string())
.unwrap();

let mut todo2 = Todo::new();
let id2 = next_id();
todo2
.initialize(id2.clone(), "alice".to_string(), "Second task".to_string())
.unwrap();

repo.commit_all(&mut [&mut todo1, &mut todo2]).unwrap();

// Find one for alice
let found = repo.find_one(|t| t.snapshot().user_id == "alice").unwrap();
assert!(found.is_some());
let todo = found.unwrap();
assert_eq!(todo.snapshot().user_id, "alice");

// Find one with no match
let not_found = repo.find_one(|t| t.snapshot().user_id == "nobody").unwrap();
assert!(not_found.is_none());
}

#[test]
fn exists_returns_true_when_aggregate_matches() {
let repo = HashMapRepository::new().aggregate::<Todo>();

let mut todo = Todo::new();
let id = next_id();
todo.initialize(id.clone(), "alice".to_string(), "Test task".to_string())
.unwrap();
repo.commit(&mut todo).unwrap();

assert!(repo.exists(|t| t.snapshot().user_id == "alice").unwrap());
assert!(!repo.exists(|t| t.snapshot().user_id == "bob").unwrap());
}

#[test]
fn count_returns_matching_aggregate_count() {
let repo = HashMapRepository::new().aggregate::<Todo>();

let mut todo1 = Todo::new();
let id1 = next_id();
todo1
.initialize(id1.clone(), "alice".to_string(), "Task 1".to_string())
.unwrap();

let mut todo2 = Todo::new();
let id2 = next_id();
todo2
.initialize(id2.clone(), "alice".to_string(), "Task 2".to_string())
.unwrap();

let mut todo3 = Todo::new();
let id3 = next_id();
todo3
.initialize(id3.clone(), "bob".to_string(), "Task 3".to_string())
.unwrap();

repo.commit_all(&mut [&mut todo1, &mut todo2, &mut todo3])
.unwrap();

assert_eq!(repo.count(|t| t.snapshot().user_id == "alice").unwrap(), 2);
assert_eq!(repo.count(|t| t.snapshot().user_id == "bob").unwrap(), 1);
assert_eq!(repo.count(|_| true).unwrap(), 3);
assert_eq!(
repo.count(|t| t.snapshot().user_id == "charlie").unwrap(),
0
);
}

#[test]
fn find_by_completed_status() {
let repo = HashMapRepository::new().aggregate::<Todo>();

let mut todo1 = Todo::new();
let id1 = next_id();
todo1
.initialize(
id1.clone(),
"alice".to_string(),
"Completed task".to_string(),
)
.unwrap();
todo1.complete().unwrap();

let mut todo2 = Todo::new();
let id2 = next_id();
todo2
.initialize(id2.clone(), "alice".to_string(), "Pending task".to_string())
.unwrap();

repo.commit_all(&mut [&mut todo1, &mut todo2]).unwrap();

// Find completed todos
let completed = repo.find(|t| t.snapshot().completed).unwrap();
assert_eq!(completed.len(), 1);
assert_eq!(completed[0].snapshot().task, "Completed task");

// Find pending todos
let pending = repo.find(|t| !t.snapshot().completed).unwrap();
assert_eq!(pending.len(), 1);
assert_eq!(pending[0].snapshot().task, "Pending task");
}

/// Full metadata chain: Entity → EventRecord → OutboxMessage → OutboxWorker → publisher
#[test]
fn metadata_flows_from_entity_through_outbox_to_publisher() {
Expand Down
Loading