|
1 | 1 | use super::*;
|
2 | 2 | use crate::chat::Chat;
|
3 | 3 | use crate::mimeparser::SystemMessage;
|
4 |
| -use crate::test_utils::{get_chat_msg, TestContext, TestContextManager}; |
| 4 | +use crate::securejoin::{get_securejoin_qr, join_securejoin, join_securejoin_with_source}; |
| 5 | +use crate::test_utils::{TestContext, TestContextManager, get_chat_msg}; |
| 6 | +use pretty_assertions::assert_eq; |
5 | 7 |
|
6 | 8 | #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
7 | 9 | async fn test_send_self_report() -> Result<()> {
|
@@ -79,3 +81,73 @@ async fn test_self_report_one_contact() -> Result<()> {
|
79 | 81 |
|
80 | 82 | Ok(())
|
81 | 83 | }
|
| 84 | + |
| 85 | +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] |
| 86 | +async fn test_self_report_securejoin_source_stats() -> Result<()> { |
| 87 | + let mut tcm = TestContextManager::new(); |
| 88 | + let alice = &tcm.alice().await; |
| 89 | + let bob = &tcm.bob().await; |
| 90 | + alice.set_config_bool(Config::SelfReporting, true).await?; |
| 91 | + |
| 92 | + let mut expected = SecurejoinSourceStats { |
| 93 | + unknown: 0, |
| 94 | + external_link: 0, |
| 95 | + internal_link: 0, |
| 96 | + clipboard: 0, |
| 97 | + image_loaded: 0, |
| 98 | + scan: 0, |
| 99 | + }; |
| 100 | + |
| 101 | + check_securejoin_report(alice, &expected).await; |
| 102 | + |
| 103 | + let qr = get_securejoin_qr(bob, None).await?; |
| 104 | + |
| 105 | + join_securejoin(alice, &qr).await?; |
| 106 | + expected.unknown += 1; |
| 107 | + check_securejoin_report(alice, &expected).await; |
| 108 | + |
| 109 | + join_securejoin(alice, &qr).await?; |
| 110 | + expected.unknown += 1; |
| 111 | + check_securejoin_report(alice, &expected).await; |
| 112 | + |
| 113 | + join_securejoin_with_source(alice, &qr, Some(SecurejoinSource::Clipboard as u32)).await?; |
| 114 | + expected.clipboard += 1; |
| 115 | + check_securejoin_report(alice, &expected).await; |
| 116 | + |
| 117 | + join_securejoin_with_source(alice, &qr, Some(SecurejoinSource::ExternalLink as u32)).await?; |
| 118 | + expected.external_link += 1; |
| 119 | + check_securejoin_report(alice, &expected).await; |
| 120 | + |
| 121 | + join_securejoin_with_source(alice, &qr, Some(SecurejoinSource::InternalLink as u32)).await?; |
| 122 | + expected.internal_link += 1; |
| 123 | + check_securejoin_report(alice, &expected).await; |
| 124 | + |
| 125 | + join_securejoin_with_source(alice, &qr, Some(SecurejoinSource::ImageLoaded as u32)).await?; |
| 126 | + expected.image_loaded += 1; |
| 127 | + check_securejoin_report(alice, &expected).await; |
| 128 | + |
| 129 | + join_securejoin_with_source(alice, &qr, Some(SecurejoinSource::Scan as u32)).await?; |
| 130 | + expected.scan += 1; |
| 131 | + check_securejoin_report(alice, &expected).await; |
| 132 | + |
| 133 | + join_securejoin_with_source(alice, &qr, Some(SecurejoinSource::Clipboard as u32)).await?; |
| 134 | + expected.clipboard += 1; |
| 135 | + check_securejoin_report(alice, &expected).await; |
| 136 | + |
| 137 | + join_securejoin_with_source(alice, &qr, Some(SecurejoinSource::Clipboard as u32)).await?; |
| 138 | + expected.clipboard += 1; |
| 139 | + check_securejoin_report(alice, &expected).await; |
| 140 | + |
| 141 | + Ok(()) |
| 142 | +} |
| 143 | + |
| 144 | +async fn check_securejoin_report(context: &TestContext, expected: &SecurejoinSourceStats) { |
| 145 | + let report = get_self_report(context).await.unwrap(); |
| 146 | + let actual: serde_json::Value = serde_json::from_str(&report).unwrap(); |
| 147 | + let actual = &actual["securejoin_source_stats"]; |
| 148 | + |
| 149 | + let expected = serde_json::to_string_pretty(&expected).unwrap(); |
| 150 | + let expected: serde_json::Value = serde_json::from_str(&expected).unwrap(); |
| 151 | + |
| 152 | + assert_eq!(&expected, actual); |
| 153 | +} |
0 commit comments