test overwriting maps integration

This commit is contained in:
B. Petersen
2024-06-06 14:01:58 +02:00
parent b4f62fb199
commit 41f0a0ecb4
4 changed files with 56 additions and 2 deletions

View File

@@ -105,7 +105,10 @@ impl Message {
#[cfg(test)]
mod tests {
use crate::chat;
use crate::config::Config;
use crate::context::Context;
use crate::message::{Message, Viewtype};
use crate::test_utils::TestContext;
use anyhow::Result;
use std::time::Duration;
@@ -126,4 +129,55 @@ 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;
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?; // still the default integration
Ok(())
}
}

View File

@@ -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(

Binary file not shown.