diff --git a/crates/matrix-sdk/src/test_utils/mocks/mod.rs b/crates/matrix-sdk/src/test_utils/mocks/mod.rs index 2dd4e58b5..b8065b28e 100644 --- a/crates/matrix-sdk/src/test_utils/mocks/mod.rs +++ b/crates/matrix-sdk/src/test_utils/mocks/mod.rs @@ -1428,6 +1428,12 @@ impl MatrixMockServer { self.mock_endpoint(mock, DevicesEndpoint).expect_default_access_token() } + /// Create a prebuilt mock for the endpoint used to query a single device. + pub fn mock_get_device(&self) -> MockEndpoint<'_, GetDeviceEndpoint> { + let mock = Mock::given(method("GET")).and(path_regex("/_matrix/client/v3/devices/.*")); + self.mock_endpoint(mock, GetDeviceEndpoint).expect_default_access_token() + } + /// Create a prebuilt mock for the endpoint used to search in the user /// directory. pub fn mock_user_directory(&self) -> MockEndpoint<'_, UserDirectoryEndpoint> { @@ -4180,6 +4186,16 @@ impl<'a> MockEndpoint<'a, DevicesEndpoint> { } } +/// A prebuilt mock for `GET /devices/{deviceId}` requests. +pub struct GetDeviceEndpoint; + +impl<'a> MockEndpoint<'a, GetDeviceEndpoint> { + /// Returns a successful response. + pub fn ok(self) -> MatrixMock<'a> { + self.respond_with(ResponseTemplate::new(200).set_body_json(&*test_json::DEVICE)) + } +} + /// A prebuilt mock for `POST /user_directory/search` requests. pub struct UserDirectoryEndpoint; diff --git a/testing/matrix-sdk-test/src/test_json/api_responses.rs b/testing/matrix-sdk-test/src/test_json/api_responses.rs index 6e726aa60..0dc2429d2 100644 --- a/testing/matrix-sdk-test/src/test_json/api_responses.rs +++ b/testing/matrix-sdk-test/src/test_json/api_responses.rs @@ -25,6 +25,16 @@ pub static DEVICES: Lazy = Lazy::new(|| { }) }); +/// `GET /_matrix/client/v3/device/{deviceId}` +pub static DEVICE: Lazy = Lazy::new(|| { + json!({ + "device_id": "QBUAZIFURK", + "display_name": "android", + "last_seen_ip": "1.2.3.4", + "last_seen_ts": 1474491775024u64 + }) +}); + /// `GET /_matrix/client/v3/directory/room/{roomAlias}` pub static GET_ALIAS: Lazy = Lazy::new(|| { json!({ diff --git a/testing/matrix-sdk-test/src/test_json/mod.rs b/testing/matrix-sdk-test/src/test_json/mod.rs index dfe30ad7a..285955ae1 100644 --- a/testing/matrix-sdk-test/src/test_json/mod.rs +++ b/testing/matrix-sdk-test/src/test_json/mod.rs @@ -18,7 +18,7 @@ pub mod sync; pub mod sync_events; pub use api_responses::{ - DEVICES, GET_ALIAS, KEYS_QUERY, KEYS_QUERY_TWO_DEVICES_ONE_SIGNED, KEYS_UPLOAD, LOGIN, + DEVICE, DEVICES, GET_ALIAS, KEYS_QUERY, KEYS_QUERY_TWO_DEVICES_ONE_SIGNED, KEYS_UPLOAD, LOGIN, LOGIN_RESPONSE_ERR, LOGIN_TYPES, LOGIN_WITH_DISCOVERY, LOGIN_WITH_REFRESH_TOKEN, NOT_FOUND, PUBLIC_ROOMS, PUBLIC_ROOMS_FINAL_PAGE, REFRESH_TOKEN, REFRESH_TOKEN_WITH_REFRESH_TOKEN, REGISTRATION_RESPONSE_ERR, UNKNOWN_TOKEN_SOFT_LOGOUT, VERSIONS, WELL_KNOWN, WHOAMI,