kordophone-db: switch to diesel for more features
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
pub mod models;
|
||||
pub mod chat_database;
|
||||
pub mod schema;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
@@ -18,18 +19,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_add_conversation() {
|
||||
let db = ChatDatabase::new_in_memory().unwrap();
|
||||
let mut db = ChatDatabase::new_in_memory().unwrap();
|
||||
|
||||
let guid = "test";
|
||||
let test_conversation = Conversation::builder()
|
||||
.guid("test")
|
||||
.guid(guid)
|
||||
.unread_count(2)
|
||||
.display_name("Test Conversation")
|
||||
.build();
|
||||
|
||||
let id = db.insert_conversation(test_conversation.clone()).unwrap();
|
||||
db.insert_conversation(test_conversation.clone()).unwrap();
|
||||
|
||||
// Try to fetch with id now
|
||||
let conversation = db.get_conversation_by_id(id).unwrap().unwrap();
|
||||
let conversation = db.get_conversation_by_guid(guid).unwrap().unwrap();
|
||||
assert_eq!(conversation.guid, "test");
|
||||
|
||||
// Modify the conversation and update it
|
||||
@@ -44,38 +46,40 @@ mod tests {
|
||||
assert_eq!(all_conversations.len(), 1);
|
||||
|
||||
// And make sure the display name was updated
|
||||
let conversation = db.get_conversation_by_id(id).unwrap().unwrap();
|
||||
let conversation = db.get_conversation_by_guid(guid).unwrap().unwrap();
|
||||
assert_eq!(conversation.display_name.unwrap(), "Modified Conversation");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversation_participants() {
|
||||
let db = ChatDatabase::new_in_memory().unwrap();
|
||||
let mut db = ChatDatabase::new_in_memory().unwrap();
|
||||
|
||||
let participants: Vec<Participant> = vec!["one".into(), "two".into()];
|
||||
|
||||
let guid = uuid::Uuid::new_v4().to_string();
|
||||
let conversation = ConversationBuilder::new()
|
||||
.guid(&guid)
|
||||
.display_name("Test")
|
||||
.participant_display_names(participants.clone())
|
||||
.participants(participants.clone())
|
||||
.build();
|
||||
|
||||
let id = db.insert_conversation(conversation).unwrap();
|
||||
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();
|
||||
let read_conversation = db.get_conversation_by_guid(&guid).unwrap().unwrap();
|
||||
let read_participants = read_conversation.participants;
|
||||
|
||||
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())
|
||||
.participants(participants.clone())
|
||||
.build();
|
||||
|
||||
let id = db.insert_conversation(conversation).unwrap();
|
||||
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();
|
||||
let read_conversation = db.get_conversation_by_guid(&guid).unwrap().unwrap();
|
||||
let read_participants: Vec<Participant> = read_conversation.participants;
|
||||
|
||||
assert_eq!(participants, read_participants);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user