Skip to content

Commit

Permalink
tests: serialize Unsigned with serde
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjbvr committed Oct 7, 2024
1 parent 5c35392 commit 351fbf6
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions crates/matrix-sdk/src/test_utils/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ impl TimestampArg for u64 {
}
}

#[derive(Debug, Default)]
#[derive(Debug, Default, Serialize)]
struct Unsigned {
#[serde(skip_serializing_if = "Option::is_none")]
transaction_id: Option<OwnedTransactionId>,
#[serde(rename = "m.relations", skip_serializing_if = "Option::is_none")]
relations: Option<BundledMessageLikeRelations<Raw<AnySyncTimelineEvent>>>,
}

Expand Down Expand Up @@ -156,19 +158,7 @@ where
}

if let Some(unsigned) = self.unsigned {
let mut unsigned_json = json!({});

// We can't plain serialize `Unsigned`, otherwise this would result in some
// `null` fields when options are set to none, which Ruma rejects.
let unsigned_obj = unsigned_json.as_object_mut().unwrap();
if let Some(transaction_id) = unsigned.transaction_id {
unsigned_obj.insert("transaction_id".to_owned(), json!(transaction_id));
}
if let Some(relations) = unsigned.relations {
unsigned_obj.insert("m.relations".to_owned(), json!(relations));
}

map.insert("unsigned".to_owned(), unsigned_json);
map.insert("unsigned".to_owned(), json!(unsigned));
}

if let Some(state_key) = self.state_key {
Expand Down

0 comments on commit 351fbf6

Please sign in to comment.