diff --git a/crates/matrix-sdk-common/src/deserialized_responses.rs b/crates/matrix-sdk-common/src/deserialized_responses.rs index 90a950ba2..0bda30b75 100644 --- a/crates/matrix-sdk-common/src/deserialized_responses.rs +++ b/crates/matrix-sdk-common/src/deserialized_responses.rs @@ -332,9 +332,11 @@ mod tests { events::{room::message::RoomMessageEventContent, AnySyncTimelineEvent}, serde::Raw, }; + use serde::Deserialize; use serde_json::json; - use super::{SyncTimelineEvent, TimelineEvent}; + use super::{SyncTimelineEvent, TimelineEvent, VerificationState}; + use crate::deserialized_responses::{DeviceLinkProblem, VerificationLevel}; fn example_event() -> serde_json::Value { json!({ @@ -368,4 +370,44 @@ mod tests { assert_eq!(converted_event.event_id(), "$xxxxx:example.org"); assert_eq!(converted_event.sender(), "@carl:example.com"); } + + #[test] + fn old_verification_state_to_new_migration() { + #[derive(Deserialize)] + struct State { + state: VerificationState, + } + + let state = json!({ + "state": "Trusted", + }); + let deserialized: State = + serde_json::from_value(state).expect("We can deserialize the old trusted value"); + assert_eq!(deserialized.state, VerificationState::Verified); + + let state = json!({ + "state": "UnknownDevice", + }); + + let deserialized: State = + serde_json::from_value(state).expect("We can deserialize the old unknown device value"); + + assert_eq!( + deserialized.state, + VerificationState::Unverified(VerificationLevel::None( + DeviceLinkProblem::MissingDevice + )) + ); + + let state = json!({ + "state": "Untrusted", + }); + let deserialized: State = + serde_json::from_value(state).expect("We can deserialize the old trusted value"); + + assert_eq!( + deserialized.state, + VerificationState::Unverified(VerificationLevel::UnsignedDevice) + ); + } }