Skip to content

Commit b73bd05

Browse files
committed
feat(testing): add mock for get device endpoint
Signed-off-by: Johannes Marbach <[email protected]>
1 parent 430304f commit b73bd05

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

crates/matrix-sdk/src/test_utils/mocks/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,12 @@ impl MatrixMockServer {
14271427
self.mock_endpoint(mock, DevicesEndpoint).expect_default_access_token()
14281428
}
14291429

1430+
/// Create a prebuilt mock for the endpoint used to query a single device.
1431+
pub fn mock_get_device(&self) -> MockEndpoint<'_, GetDeviceEndpoint> {
1432+
let mock = Mock::given(method("GET")).and(path_regex("/_matrix/client/v3/devices/.*"));
1433+
self.mock_endpoint(mock, GetDeviceEndpoint).expect_default_access_token()
1434+
}
1435+
14301436
/// Create a prebuilt mock for the endpoint used to search in the user
14311437
/// directory.
14321438
pub fn mock_user_directory(&self) -> MockEndpoint<'_, UserDirectoryEndpoint> {
@@ -4139,6 +4145,16 @@ impl<'a> MockEndpoint<'a, DevicesEndpoint> {
41394145
}
41404146
}
41414147

4148+
/// A prebuilt mock for `GET /devices/{deviceId}` requests.
4149+
pub struct GetDeviceEndpoint;
4150+
4151+
impl<'a> MockEndpoint<'a, GetDeviceEndpoint> {
4152+
/// Returns a successful response.
4153+
pub fn ok(self) -> MatrixMock<'a> {
4154+
self.respond_with(ResponseTemplate::new(200).set_body_json(&*test_json::DEVICE))
4155+
}
4156+
}
4157+
41424158
/// A prebuilt mock for `POST /user_directory/search` requests.
41434159
pub struct UserDirectoryEndpoint;
41444160

testing/matrix-sdk-test/src/test_json/api_responses.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ pub static DEVICES: Lazy<JsonValue> = Lazy::new(|| {
2525
})
2626
});
2727

28+
/// `GET /_matrix/client/v3/device/{deviceId}`
29+
pub static DEVICE: Lazy<JsonValue> = Lazy::new(|| {
30+
json!({
31+
"device_id": "QBUAZIFURK",
32+
"display_name": "android",
33+
"last_seen_ip": "1.2.3.4",
34+
"last_seen_ts": 1474491775024u64
35+
})
36+
});
37+
2838
/// `GET /_matrix/client/v3/directory/room/{roomAlias}`
2939
pub static GET_ALIAS: Lazy<JsonValue> = Lazy::new(|| {
3040
json!({

testing/matrix-sdk-test/src/test_json/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub mod sync;
1818
pub mod sync_events;
1919

2020
pub use api_responses::{
21-
DEVICES, GET_ALIAS, KEYS_QUERY, KEYS_QUERY_TWO_DEVICES_ONE_SIGNED, KEYS_UPLOAD, LOGIN,
21+
DEVICE, DEVICES, GET_ALIAS, KEYS_QUERY, KEYS_QUERY_TWO_DEVICES_ONE_SIGNED, KEYS_UPLOAD, LOGIN,
2222
LOGIN_RESPONSE_ERR, LOGIN_TYPES, LOGIN_WITH_DISCOVERY, LOGIN_WITH_REFRESH_TOKEN, NOT_FOUND,
2323
PUBLIC_ROOMS, PUBLIC_ROOMS_FINAL_PAGE, REFRESH_TOKEN, REFRESH_TOKEN_WITH_REFRESH_TOKEN,
2424
REGISTRATION_RESPONSE_ERR, UNKNOWN_TOKEN_SOFT_LOGOUT, VERSIONS, WELL_KNOWN, WHOAMI,

0 commit comments

Comments
 (0)