Skip to content

Commit

Permalink
feat: adds group sync test
Browse files Browse the repository at this point in the history
  • Loading branch information
tuddman committed Mar 27, 2024
1 parent db35dcb commit 54551bf
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions xmtp_mls/src/storage/encrypted_store/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct StoredGroup {
pub membership_state: GroupMembershipState,
/// Track when the latest, most recent installations were checked
pub installations_last_checked: i64,
/// Enum, [`Purpose`] signifies the group purpose which extends to who can access it.
/// Enum, [`Purpose`] signifies the group purpose which extends to who can access it.
pub purpose: Purpose,
}

Expand All @@ -52,7 +52,11 @@ impl StoredGroup {
}

/// Create a new [`Purpose::Sync`] group
pub fn new_sync_group(id: ID, created_at_ns: i64, membership_state: GroupMembershipState) -> Self {
pub fn new_sync_group(
id: ID,
created_at_ns: i64,
membership_state: GroupMembershipState,
) -> Self {
Self {
id,
created_at_ns,
Expand Down Expand Up @@ -95,11 +99,11 @@ impl DbConnection<'_> {
Ok(self.raw_query(|conn| query.load(conn))?)
}

/// Return only the [`Purpose::Sync`] groups
pub fn sync_groups(&self) -> Result<Vec<StoredGroup>, StorageError> {
/// Return only the [`Purpose::Sync`] groups
pub fn find_sync_groups(&self) -> Result<Vec<StoredGroup>, StorageError> {
let mut query = dsl::groups.order(dsl::created_at_ns.asc()).into_boxed();
query = query.filter(dsl::purpose.eq(Purpose::Sync));

Ok(self.raw_query(|conn| query.load(conn))?)
}

Expand Down Expand Up @@ -327,6 +331,10 @@ pub(crate) mod tests {
.unwrap();
assert_eq!(results_with_created_at_ns_after.len(), 1);
assert_eq!(results_with_created_at_ns_after[0].id, test_group_2.id);

// Sync groups SHOULD NOT be returned
let synced_groups = conn.find_sync_groups().unwrap();
assert_eq!(synced_groups.len(), 0);
})
}

Expand Down Expand Up @@ -370,4 +378,17 @@ pub(crate) mod tests {
assert_eq!(purpose, Purpose::Conversation);
})
}

#[test]
fn test_new_sync_group() {
with_connection(|_conn| {
let id = rand_vec();
let created_at_ns = now_ns();
let membership_state = GroupMembershipState::Allowed;

let sync_group = StoredGroup::new_sync_group(id, created_at_ns, membership_state);
let purpose = sync_group.purpose;
assert_eq!(purpose, Purpose::Sync);
})
}
}

0 comments on commit 54551bf

Please sign in to comment.