chatdatabase: implements all_conversations with participant zippering
This commit is contained in:
@@ -83,4 +83,42 @@ mod tests {
|
||||
|
||||
assert_eq!(participants, read_participants);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_all_conversations_with_participants() {
|
||||
let mut db = ChatDatabase::new_in_memory().unwrap();
|
||||
|
||||
// Create two conversations with different participants
|
||||
let participants1: Vec<Participant> = vec!["one".into(), "two".into()];
|
||||
let participants2: Vec<Participant> = vec!["three".into(), "four".into()];
|
||||
|
||||
let guid1 = uuid::Uuid::new_v4().to_string();
|
||||
let conversation1 = ConversationBuilder::new()
|
||||
.guid(&guid1)
|
||||
.display_name("Test 1")
|
||||
.participants(participants1.clone())
|
||||
.build();
|
||||
|
||||
let guid2 = uuid::Uuid::new_v4().to_string();
|
||||
let conversation2 = ConversationBuilder::new()
|
||||
.guid(&guid2)
|
||||
.display_name("Test 2")
|
||||
.participants(participants2.clone())
|
||||
.build();
|
||||
|
||||
// Insert both conversations
|
||||
db.insert_conversation(conversation1).unwrap();
|
||||
db.insert_conversation(conversation2).unwrap();
|
||||
|
||||
// Get all conversations and verify the results
|
||||
let all_conversations = db.all_conversations().unwrap();
|
||||
assert_eq!(all_conversations.len(), 2);
|
||||
|
||||
// Find and verify each conversation's participants
|
||||
let conv1 = all_conversations.iter().find(|c| c.guid == guid1).unwrap();
|
||||
let conv2 = all_conversations.iter().find(|c| c.guid == guid2).unwrap();
|
||||
|
||||
assert_eq!(conv1.participants, participants1);
|
||||
assert_eq!(conv2.participants, participants2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user