Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jan 6, 2025
1 parent a8a0847 commit d7321c5
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions xmtp_mls/src/storage/encrypted_store/conversation_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ impl DbConnection {
if *consent_state == ConsentState::Unknown {
let query = query
.left_join(
consent_dsl::consent_records
.on(sql::<diesel::sql_types::Text>("lower(hex(conversation_list.id))")
.eq(consent_dsl::entity)),
consent_dsl::consent_records.on(sql::<diesel::sql_types::Text>(
"lower(hex(conversation_list.id))",
)
.eq(consent_dsl::entity)),
)
.filter(
consent_dsl::state
Expand All @@ -131,9 +132,10 @@ impl DbConnection {
} else {
let query = query
.inner_join(
consent_dsl::consent_records
.on(sql::<diesel::sql_types::Text>("lower(hex(conversation_list.id))")
.eq(consent_dsl::entity)),
consent_dsl::consent_records.on(sql::<diesel::sql_types::Text>(
"lower(hex(conversation_list.id))",
)
.eq(consent_dsl::entity)),
)
.filter(consent_dsl::state.eq(*consent_state))
.select(conversation_list::all_columns())
Expand All @@ -154,13 +156,14 @@ impl DbConnection {

Ok(conversations)
}

}

#[cfg(test)]
pub(crate) mod tests {
use crate::storage::consent_record::{ConsentState, ConsentType};
use crate::storage::group::tests::{generate_consent_record, generate_dm, generate_group, generate_group_with_created_at};
use crate::storage::group::tests::{
generate_consent_record, generate_dm, generate_group, generate_group_with_created_at,
};
use crate::storage::group::{GroupMembershipState, GroupQueryArgs};
use crate::storage::tests::with_connection;
use crate::Store;
Expand Down Expand Up @@ -326,22 +329,30 @@ pub(crate) mod tests {
);
test_group_3_consent.store(conn).unwrap();

let all_results = conn.fetch_conversation_list(GroupQueryArgs::default()).unwrap();
let all_results = conn
.fetch_conversation_list(GroupQueryArgs::default())
.unwrap();
assert_eq!(all_results.len(), 4);

let allowed_results = conn
.fetch_conversation_list(GroupQueryArgs::default().consent_state(ConsentState::Allowed))
.fetch_conversation_list(
GroupQueryArgs::default().consent_state(ConsentState::Allowed),
)
.unwrap();
assert_eq!(allowed_results.len(), 2);

let denied_results = conn
.fetch_conversation_list(GroupQueryArgs::default().consent_state(ConsentState::Denied))
.fetch_conversation_list(
GroupQueryArgs::default().consent_state(ConsentState::Denied),
)
.unwrap();
assert_eq!(denied_results.len(), 1);
assert_eq!(denied_results[0].id, test_group_2.id);

let unknown_results = conn
.fetch_conversation_list(GroupQueryArgs::default().consent_state(ConsentState::Unknown))
.fetch_conversation_list(
GroupQueryArgs::default().consent_state(ConsentState::Unknown),
)
.unwrap();
assert_eq!(unknown_results.len(), 1);
assert_eq!(unknown_results[0].id, test_group_4.id);
Expand Down

0 comments on commit d7321c5

Please sign in to comment.