kordophone-db: participants, but still need to "upsert" these
Might move to SeaORM instead of trying to do this with microrm
This commit is contained in:
@@ -3,9 +3,13 @@ pub mod chat_database;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use microrm::prelude::Queryable;
|
||||
|
||||
use crate::{chat_database::{self, ChatDatabase}, models::conversation::{Conversation, ConversationBuilder, Participant}};
|
||||
use crate::{
|
||||
chat_database::ChatDatabase,
|
||||
models::{
|
||||
conversation::{Conversation, ConversationBuilder},
|
||||
participant::Participant
|
||||
}
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_database_init() {
|
||||
@@ -48,7 +52,8 @@ mod tests {
|
||||
fn test_conversation_participants() {
|
||||
let db = ChatDatabase::new_in_memory().unwrap();
|
||||
|
||||
let participants: Vec<String> = vec!["one".into(), "two".into()];
|
||||
let participants: Vec<Participant> = vec!["one".into(), "two".into()];
|
||||
|
||||
let conversation = ConversationBuilder::new()
|
||||
.display_name("Test")
|
||||
.participant_display_names(participants.clone())
|
||||
@@ -57,12 +62,20 @@ mod tests {
|
||||
let id = db.insert_conversation(conversation).unwrap();
|
||||
|
||||
let read_conversation = db.get_conversation_by_id(id).unwrap().unwrap();
|
||||
let read_participants: Vec<String> = read_conversation.participant_display_names
|
||||
.get()
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|p| p.wrapped().display_name)
|
||||
.collect();
|
||||
let read_participants: Vec<Participant> = read_conversation.get_participant_display_names();
|
||||
|
||||
assert_eq!(participants, read_participants);
|
||||
|
||||
// Try making another conversation with the same participants
|
||||
let conversation = ConversationBuilder::new()
|
||||
.display_name("A Different Test")
|
||||
.participant_display_names(participants.clone())
|
||||
.build();
|
||||
|
||||
let id = db.insert_conversation(conversation).unwrap();
|
||||
|
||||
let read_conversation = db.get_conversation_by_id(id).unwrap().unwrap();
|
||||
let read_participants: Vec<Participant> = read_conversation.get_participant_display_names();
|
||||
|
||||
assert_eq!(participants, read_participants);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user