fix(bindings): Withheld code mapping

This commit is contained in:
Valere
2023-04-22 21:10:56 +02:00
committed by GitHub
parent 9ffcb8bc8a
commit f8e4e3d7d5
2 changed files with 25 additions and 1 deletions

View File

@@ -65,3 +65,4 @@ uniffi = { workspace = true, features = ["build"] }
[dev-dependencies]
tempfile = "3.3.0"
assert_matches = { workspace = true }

View File

@@ -69,7 +69,7 @@ impl From<MegolmError> for DecryptionError {
match value {
MegolmError::MissingRoomKey(withheld_code) => Self::MissingRoomKey {
error: "Withheld Inbound group session".to_owned(),
withheld_code: withheld_code.map(|w| w.to_string()),
withheld_code: withheld_code.map(|w| w.as_str().to_owned()),
},
_ => Self::Megolm { error: value.to_string() },
}
@@ -93,3 +93,26 @@ impl From<InnerStoreError> for DecryptionError {
Self::Store { error: err.to_string() }
}
}
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use super::*;
#[test]
fn test_withheld_error_mapping() {
use matrix_sdk_crypto::types::events::room_key_withheld::WithheldCode;
let inner_error = MegolmError::MissingRoomKey(Some(WithheldCode::Unverified));
let binding_error: DecryptionError = inner_error.into();
let code = assert_matches!(
binding_error,
DecryptionError::MissingRoomKey { error: _, withheld_code: Some(withheld_code) } => withheld_code
);
assert_eq!("m.unverified", code)
}
}