From 4c4841e51e21274996bf4518fda678f86a0d268d Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 6 Jun 2024 17:13:20 +0200 Subject: [PATCH] add a test for overwriting integrations --- src/webxdc/integration.rs | 64 ++++++++++++++++++ src/webxdc/maps_integration.rs | 4 +- test-data/webxdc/mapstest-integration-set.xdc | Bin 0 -> 411 bytes ...est.xdc => mapstest-integration-unset.xdc} | Bin 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 test-data/webxdc/mapstest-integration-set.xdc rename test-data/webxdc/{mapstest.xdc => mapstest-integration-unset.xdc} (100%) diff --git a/src/webxdc/integration.rs b/src/webxdc/integration.rs index e6a936cce4..90abb92193 100644 --- a/src/webxdc/integration.rs +++ b/src/webxdc/integration.rs @@ -128,7 +128,10 @@ impl Message { #[cfg(test)] mod tests { use crate::config::Config; + use crate::context::Context; + use crate::message::{Message, Viewtype}; use crate::test_utils::TestContext; + use crate::{chat, message}; use anyhow::Result; use std::time::Duration; @@ -148,4 +151,65 @@ mod tests { Ok(()) } + + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_overwrite_default_integration() -> Result<()> { + let t = TestContext::new_alice().await; + let self_chat = &t.get_self_chat().await; + assert!(t.init_webxdc_integration(None).await?.is_none()); + + async fn assert_integration(t: &Context, name: &str) -> Result<()> { + let integration_id = t.init_webxdc_integration(None).await?.unwrap(); + let integration = Message::load_from_db(&t, integration_id).await?; + let integration_info = integration.get_webxdc_info(&t).await?; + assert_eq!(integration_info.name, name); + Ok(()) + } + + // set default integration + let bytes = include_bytes!("../../test-data/webxdc/with-manifest-and-png-icon.xdc"); + let file = t.get_blobdir().join("maps.xdc"); + tokio::fs::write(&file, bytes).await.unwrap(); + t.set_webxdc_integration(file.to_str().unwrap()).await?; + assert_integration(&t, "with some icon").await?; + + // send a maps.xdc with insufficient manifest + let mut msg = Message::new(Viewtype::Webxdc); + msg.set_file_from_bytes( + &t, + "mapstest.xdc", + include_bytes!("../../test-data/webxdc/mapstest-integration-unset.xdc"), + None, + ) + .await?; + chat::send_msg(&t, self_chat.id, &mut msg).await?; + let sent = t.pop_sent_msg_opt(Duration::from_secs(1)).await; + assert!(sent.is_some()); + assert_integration(&t, "with some icon").await?; // still the default integration + + // send a maps.xdc with manifest including the line `integration = "maps"` + let mut msg = Message::new(Viewtype::Webxdc); + msg.set_file_from_bytes( + &t, + "mapstest.xdc", + include_bytes!("../../test-data/webxdc/mapstest-integration-set.xdc"), + None, + ) + .await?; + chat::send_msg(&t, self_chat.id, &mut msg).await?; + let sent = t.pop_sent_msg_opt(Duration::from_secs(1)).await; + assert!(sent.is_some()); + assert_integration(&t, "Maps Test 2").await?; + + // when maps.xdc is received on another device, the integration is not accepted + let t2 = TestContext::new_alice().await; + t2.recv_msg(&sent.unwrap()).await; + assert!(t2.init_webxdc_integration(None).await?.is_none()); + + // deleting maps.xdc removes the user's integration - the UI will go back to default calling set_webxdc_integration() then + message::delete_msgs(&t, &[msg.id]).await?; + assert!(t.init_webxdc_integration(None).await?.is_none()); + + Ok(()) + } } diff --git a/src/webxdc/maps_integration.rs b/src/webxdc/maps_integration.rs index 38d3f5c0b1..a1eec55699 100644 --- a/src/webxdc/maps_integration.rs +++ b/src/webxdc/maps_integration.rs @@ -180,7 +180,7 @@ mod tests { async fn test_maps_integration() -> Result<()> { let t = TestContext::new_alice().await; - let bytes = include_bytes!("../../test-data/webxdc/mapstest.xdc"); + let bytes = include_bytes!("../../test-data/webxdc/mapstest-integration-set.xdc"); let file = t.get_blobdir().join("maps.xdc"); tokio::fs::write(&file, bytes).await.unwrap(); t.set_webxdc_integration(file.to_str().unwrap()).await?; @@ -198,7 +198,7 @@ mod tests { let integration = Message::load_from_db(&t, integration_id).await?; let info = integration.get_webxdc_info(&t).await?; - assert_eq!(info.name, "Maps Test"); + assert_eq!(info.name, "Maps Test 2"); assert_eq!(info.internet_access, true); t.send_webxdc_status_update( diff --git a/test-data/webxdc/mapstest-integration-set.xdc b/test-data/webxdc/mapstest-integration-set.xdc new file mode 100644 index 0000000000000000000000000000000000000000..76ea721b948aeee0799564ae5bf5cae4ecaebf81 GIT binary patch literal 411 zcmWIWW@h1HU}9ikNX$4Eq0+*8T?EJmVJ-$4hRnQ_)C#?flH8oo5Kac>wCRay9Y9=K z!Og(P@|BT+fd!<}M$yIJIV3W`RRN^Zjw>&-f-3-Mt_aXv4u%4txo1l)zBvO`dIB*o z(A?a_yv(%J;u5`*e5lbaKx11mjXv#t#y50BXuv059gQ#!PhGu0gP=#J&S-o3>U-&& zJaeA;87g!vFw8 CLuvW| literal 0 HcmV?d00001 diff --git a/test-data/webxdc/mapstest.xdc b/test-data/webxdc/mapstest-integration-unset.xdc similarity index 100% rename from test-data/webxdc/mapstest.xdc rename to test-data/webxdc/mapstest-integration-unset.xdc