mirror of
https://github.com/chatmail/core.git
synced 2026-04-20 15:06:30 +03:00
let render_webxdc_status_update_object() return an Option; add a test for that
This commit is contained in:
@@ -157,7 +157,8 @@ impl Context {
|
||||
instance_msg_id,
|
||||
Some(status_update_id),
|
||||
)
|
||||
.await?,
|
||||
.await?
|
||||
.ok_or_else(|| format_err!("Status object expected."))?,
|
||||
);
|
||||
status_update.set_quote(self, Some(&instance)).await?;
|
||||
let status_update_msg_id =
|
||||
@@ -257,11 +258,15 @@ impl Context {
|
||||
&self,
|
||||
instance_msg_id: MsgId,
|
||||
status_update_id: Option<StatusUpdateId>,
|
||||
) -> Result<String> {
|
||||
) -> Result<Option<String>> {
|
||||
let updates_array = self
|
||||
.get_webxdc_status_updates(instance_msg_id, status_update_id)
|
||||
.await?;
|
||||
Ok(format!(r#"{{"updates":{}}}"#, updates_array))
|
||||
if updates_array == "[]" {
|
||||
Ok(None)
|
||||
} else {
|
||||
Ok(Some(format!(r#"{{"updates":{}}}"#, updates_array)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -717,6 +722,31 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_render_webxdc_status_update_object() -> Result<()> {
|
||||
let t = TestContext::new_alice().await;
|
||||
let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "a chat").await?;
|
||||
let mut instance = create_webxdc_instance(
|
||||
&t,
|
||||
"minimal.xdc",
|
||||
include_bytes!("../test-data/webxdc/minimal.xdc"),
|
||||
)
|
||||
.await?;
|
||||
chat_id.set_draft(&t, Some(&mut instance)).await?;
|
||||
assert!(t
|
||||
.render_webxdc_status_update_object(instance.id, None)
|
||||
.await?
|
||||
.is_none());
|
||||
|
||||
t.send_webxdc_status_update(instance.id, "1", "bla").await?;
|
||||
assert!(t
|
||||
.render_webxdc_status_update_object(instance.id, None)
|
||||
.await?
|
||||
.is_some());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_draft_and_send_webxdc_status_update() -> Result<()> {
|
||||
let alice = TestContext::new_alice().await;
|
||||
|
||||
Reference in New Issue
Block a user