From 54551bff3e8c1e0150e7501f24b46d342b930491 Mon Sep 17 00:00:00 2001 From: tuddman Date: Wed, 27 Mar 2024 21:56:21 +0100 Subject: [PATCH] feat: adds group sync test --- xmtp_mls/src/storage/encrypted_store/group.rs | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/xmtp_mls/src/storage/encrypted_store/group.rs b/xmtp_mls/src/storage/encrypted_store/group.rs index 386092c64..dbc19477e 100644 --- a/xmtp_mls/src/storage/encrypted_store/group.rs +++ b/xmtp_mls/src/storage/encrypted_store/group.rs @@ -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, } @@ -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, @@ -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, StorageError> { + /// Return only the [`Purpose::Sync`] groups + pub fn find_sync_groups(&self) -> Result, 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))?) } @@ -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); }) } @@ -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); + }) + } }