Skip to content

Commit

Permalink
task(tests): introduce prebuilt mocks and mocking helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjbvr committed Oct 31, 2024
1 parent 75683d2 commit e9016b2
Show file tree
Hide file tree
Showing 7 changed files with 586 additions and 563 deletions.
8 changes: 7 additions & 1 deletion crates/matrix-sdk-common/src/deserialized_responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl SyncTimelineEvent {
/// Get the event id of this `SyncTimelineEvent` if the event has any valid
/// id.
pub fn event_id(&self) -> Option<OwnedEventId> {
self.kind.raw().get_field::<OwnedEventId>("event_id").ok().flatten()
self.kind.event_id()
}

/// Returns a reference to the (potentially decrypted) Matrix event inside
Expand Down Expand Up @@ -529,6 +529,12 @@ impl TimelineEventKind {
}
}

/// Get the event id of this `TimelineEventKind` if the event has any valid
/// id.
pub fn event_id(&self) -> Option<OwnedEventId> {
self.raw().get_field::<OwnedEventId>("event_id").ok().flatten()
}

/// If the event was a decrypted event that was successfully decrypted, get
/// its encryption info. Otherwise, `None`.
pub fn encryption_info(&self) -> Option<&EncryptionInfo> {
Expand Down
4 changes: 4 additions & 0 deletions crates/matrix-sdk/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Testing utilities - DO NOT USE IN PRODUCTION.

#![allow(missing_docs)]
#![allow(dead_code)]

use assert_matches2::assert_let;
Expand All @@ -14,6 +15,9 @@ use url::Url;

pub mod events;

#[cfg(not(target_arch = "wasm32"))]
pub mod mocks;

use crate::{
config::RequestConfig,
matrix_auth::{MatrixSession, MatrixSessionTokens},
Expand Down
2 changes: 0 additions & 2 deletions crates/matrix-sdk/src/test_utils/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![allow(missing_docs)]

use std::sync::atomic::{AtomicU64, Ordering::SeqCst};

use as_variant::as_variant;
Expand Down
Loading

0 comments on commit e9016b2

Please sign in to comment.