Skip to content

Commit ec112ca

Browse files
committed
test(base): Test that we set the joined at timestamp
1 parent 15fdf1e commit ec112ca

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

crates/matrix-sdk-base/src/client.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,4 +1737,47 @@ mod tests {
17371737

17381738
assert!(client.is_user_ignored(ignored_user_id).await);
17391739
}
1740+
1741+
#[async_test]
1742+
async fn test_joined_at_timestamp_is_set() {
1743+
let client = logged_in_base_client(None).await;
1744+
let invited_room_id = room_id!("!invited:localhost");
1745+
let unknown_room_id = room_id!("!unknown:localhost");
1746+
1747+
let mut sync_builder = SyncResponseBuilder::new();
1748+
let response = sync_builder
1749+
.add_invited_room(InvitedRoomBuilder::new(invited_room_id))
1750+
.build_sync_response();
1751+
client.receive_sync_response(response).await.unwrap();
1752+
1753+
// Let us first check the initial state, we should have a room in the invite
1754+
// state.
1755+
let invited_room = client
1756+
.get_room(invited_room_id)
1757+
.expect("The sync should have created a room in the invited state");
1758+
1759+
assert_eq!(invited_room.state(), RoomState::Invited);
1760+
assert!(invited_room.inner.get().invite_accepted_at().is_none());
1761+
1762+
// Now we join the room.
1763+
let joined_room = client
1764+
.room_joined(invited_room_id)
1765+
.await
1766+
.expect("We should be able to mark a room as joined");
1767+
1768+
// Yup, there's a timestamp now.
1769+
assert_eq!(joined_room.state(), RoomState::Joined);
1770+
assert!(joined_room.inner.get().invite_accepted_at().is_some());
1771+
1772+
// If we didn't know about the room before the join, we assume that there wasn't
1773+
// an invite and we don't record the timestamp.
1774+
assert!(client.get_room(unknown_room_id).is_none());
1775+
let unknown_room = client
1776+
.room_joined(unknown_room_id)
1777+
.await
1778+
.expect("We should be able to mark a room as joined");
1779+
1780+
assert_eq!(unknown_room.state(), RoomState::Joined);
1781+
assert!(unknown_room.inner.get().invite_accepted_at().is_none());
1782+
}
17401783
}

0 commit comments

Comments
 (0)