Skip to content

Commit 351fbf6

Browse files
committed
tests: serialize Unsigned with serde
1 parent 5c35392 commit 351fbf6

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

crates/matrix-sdk/src/test_utils/events.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ impl TimestampArg for u64 {
5959
}
6060
}
6161

62-
#[derive(Debug, Default)]
62+
#[derive(Debug, Default, Serialize)]
6363
struct Unsigned {
64+
#[serde(skip_serializing_if = "Option::is_none")]
6465
transaction_id: Option<OwnedTransactionId>,
66+
#[serde(rename = "m.relations", skip_serializing_if = "Option::is_none")]
6567
relations: Option<BundledMessageLikeRelations<Raw<AnySyncTimelineEvent>>>,
6668
}
6769

@@ -156,19 +158,7 @@ where
156158
}
157159

158160
if let Some(unsigned) = self.unsigned {
159-
let mut unsigned_json = json!({});
160-
161-
// We can't plain serialize `Unsigned`, otherwise this would result in some
162-
// `null` fields when options are set to none, which Ruma rejects.
163-
let unsigned_obj = unsigned_json.as_object_mut().unwrap();
164-
if let Some(transaction_id) = unsigned.transaction_id {
165-
unsigned_obj.insert("transaction_id".to_owned(), json!(transaction_id));
166-
}
167-
if let Some(relations) = unsigned.relations {
168-
unsigned_obj.insert("m.relations".to_owned(), json!(relations));
169-
}
170-
171-
map.insert("unsigned".to_owned(), unsigned_json);
161+
map.insert("unsigned".to_owned(), json!(unsigned));
172162
}
173163

174164
if let Some(state_key) = self.state_key {

0 commit comments

Comments
 (0)