Skip to content

Commit 71a6b73

Browse files
committed
test(threads): add test for the thread subscription endpoints
1 parent ced39f1 commit 71a6b73

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

crates/matrix-sdk/tests/integration/room/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ mod left;
77
mod notification_mode;
88
mod spaces;
99
mod tags;
10+
mod thread;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use matrix_sdk::test_utils::mocks::MatrixMockServer;
2+
use matrix_sdk_test::async_test;
3+
use ruma::{owned_event_id, room_id};
4+
5+
#[async_test]
6+
async fn test_subscribe_thread() {
7+
let server = MatrixMockServer::new().await;
8+
let client = server.client_builder().build().await;
9+
10+
let room_id = room_id!("!test:example.org");
11+
let room = server.sync_joined_room(&client, room_id).await;
12+
13+
let root_id = owned_event_id!("$root");
14+
15+
server
16+
.mock_put_thread_subscription()
17+
.match_room_id(room_id.to_owned())
18+
.match_thread_id(root_id.clone())
19+
.ok()
20+
.mock_once()
21+
.mount()
22+
.await;
23+
24+
// I can subscribe to a thread.
25+
room.subscribe_thread(root_id.clone(), true).await.unwrap();
26+
27+
server
28+
.mock_get_thread_subscription()
29+
.match_room_id(room_id.to_owned())
30+
.match_thread_id(root_id.clone())
31+
.ok(true)
32+
.mock_once()
33+
.mount()
34+
.await;
35+
36+
// I can get the subscription status for that same thread.
37+
let subscription = room.get_thread_subscription(root_id.clone()).await.unwrap().unwrap();
38+
assert!(subscription.automatic);
39+
40+
// If I try to get a subscription for a thread event that's unknown, I get no
41+
// `ThreadSubscription`, not an error.
42+
let subscription =
43+
room.get_thread_subscription(owned_event_id!("$another_root")).await.unwrap();
44+
assert!(subscription.is_none());
45+
46+
// I can also unsubscribe from a thread.
47+
server
48+
.mock_delete_thread_subscription()
49+
.match_room_id(room_id.to_owned())
50+
.match_thread_id(root_id.clone())
51+
.ok()
52+
.mock_once()
53+
.mount()
54+
.await;
55+
56+
room.unsubscribe_thread(root_id).await.unwrap();
57+
}

0 commit comments

Comments
 (0)