@@ -89,8 +89,9 @@ async fn test_self_report_one_contact() -> Result<()> {
8989#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
9090async fn test_message_stats ( ) -> Result < ( ) > {
9191 fn check_report ( report : & str , expected : & MessageStats ) {
92+ let key = "message_stats" ;
9293 let actual: serde_json:: Value = serde_json:: from_str ( & report) . unwrap ( ) ;
93- let actual = & actual[ "message_stats" ] ;
94+ let actual = & actual[ key ] ;
9495
9596 let expected = serde_json:: to_string_pretty ( & expected) . unwrap ( ) ;
9697 let expected: serde_json:: Value = serde_json:: from_str ( & expected) . unwrap ( ) ;
@@ -184,6 +185,17 @@ async fn send_and_read_self_report(context: &TestContext) -> String {
184185
185186#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
186187async fn test_self_report_securejoin_source_stats ( ) -> Result < ( ) > {
188+ async fn check_report ( context : & TestContext , expected : & SecurejoinSourceStats ) {
189+ let report = get_self_report ( context) . await . unwrap ( ) ;
190+ let actual: serde_json:: Value = serde_json:: from_str ( & report) . unwrap ( ) ;
191+ let actual = & actual[ "securejoin_source_stats" ] ;
192+
193+ let expected = serde_json:: to_string_pretty ( & expected) . unwrap ( ) ;
194+ let expected: serde_json:: Value = serde_json:: from_str ( & expected) . unwrap ( ) ;
195+
196+ assert_eq ! ( actual, & expected) ;
197+ }
198+
187199 let mut tcm = TestContextManager :: new ( ) ;
188200 let alice = & tcm. alice ( ) . await ;
189201 let bob = & tcm. bob ( ) . await ;
@@ -198,58 +210,123 @@ async fn test_self_report_securejoin_source_stats() -> Result<()> {
198210 scan : 0 ,
199211 } ;
200212
201- check_securejoin_report ( alice, & expected) . await ;
213+ check_report ( alice, & expected) . await ;
202214
203215 let qr = get_securejoin_qr ( bob, None ) . await ?;
204216
205217 join_securejoin ( alice, & qr) . await ?;
206218 expected. unknown += 1 ;
207- check_securejoin_report ( alice, & expected) . await ;
219+ check_report ( alice, & expected) . await ;
208220
209221 join_securejoin ( alice, & qr) . await ?;
210222 expected. unknown += 1 ;
211- check_securejoin_report ( alice, & expected) . await ;
223+ check_report ( alice, & expected) . await ;
212224
213- join_securejoin_with_source ( alice, & qr, Some ( SecurejoinSource :: Clipboard as u32 ) ) . await ?;
225+ join_securejoin_with_source ( alice, & qr, Some ( SecurejoinSource :: Clipboard as u32 ) , None ) . await ?;
214226 expected. clipboard += 1 ;
215- check_securejoin_report ( alice, & expected) . await ;
216-
217- join_securejoin_with_source ( alice, & qr, Some ( SecurejoinSource :: ExternalLink as u32 ) ) . await ?;
227+ check_report ( alice, & expected) . await ;
228+
229+ join_securejoin_with_source (
230+ alice,
231+ & qr,
232+ Some ( SecurejoinSource :: ExternalLink as u32 ) ,
233+ None ,
234+ )
235+ . await ?;
218236 expected. external_link += 1 ;
219- check_securejoin_report ( alice, & expected) . await ;
220-
221- join_securejoin_with_source ( alice, & qr, Some ( SecurejoinSource :: InternalLink as u32 ) ) . await ?;
237+ check_report ( alice, & expected) . await ;
238+
239+ join_securejoin_with_source (
240+ alice,
241+ & qr,
242+ Some ( SecurejoinSource :: InternalLink as u32 ) ,
243+ None ,
244+ )
245+ . await ?;
222246 expected. internal_link += 1 ;
223- check_securejoin_report ( alice, & expected) . await ;
247+ check_report ( alice, & expected) . await ;
224248
225- join_securejoin_with_source ( alice, & qr, Some ( SecurejoinSource :: ImageLoaded as u32 ) ) . await ?;
249+ join_securejoin_with_source ( alice, & qr, Some ( SecurejoinSource :: ImageLoaded as u32 ) , None )
250+ . await ?;
226251 expected. image_loaded += 1 ;
227- check_securejoin_report ( alice, & expected) . await ;
252+ check_report ( alice, & expected) . await ;
228253
229- join_securejoin_with_source ( alice, & qr, Some ( SecurejoinSource :: Scan as u32 ) ) . await ?;
254+ join_securejoin_with_source ( alice, & qr, Some ( SecurejoinSource :: Scan as u32 ) , None ) . await ?;
230255 expected. scan += 1 ;
231- check_securejoin_report ( alice, & expected) . await ;
256+ check_report ( alice, & expected) . await ;
232257
233- join_securejoin_with_source ( alice, & qr, Some ( SecurejoinSource :: Clipboard as u32 ) ) . await ?;
258+ join_securejoin_with_source ( alice, & qr, Some ( SecurejoinSource :: Clipboard as u32 ) , None ) . await ?;
234259 expected. clipboard += 1 ;
235- check_securejoin_report ( alice, & expected) . await ;
260+ check_report ( alice, & expected) . await ;
236261
237- join_securejoin_with_source ( alice, & qr, Some ( SecurejoinSource :: Clipboard as u32 ) ) . await ?;
262+ join_securejoin_with_source ( alice, & qr, Some ( SecurejoinSource :: Clipboard as u32 ) , None ) . await ?;
238263 expected. clipboard += 1 ;
239- check_securejoin_report ( alice, & expected) . await ;
264+ check_report ( alice, & expected) . await ;
240265
241266 Ok ( ( ) )
242267}
243268
244- async fn check_securejoin_report ( context : & TestContext , expected : & SecurejoinSourceStats ) {
245- let report = get_self_report ( context) . await . unwrap ( ) ;
246- let actual: serde_json:: Value = serde_json:: from_str ( & report) . unwrap ( ) ;
247- let actual = & actual[ "securejoin_source_stats" ] ;
269+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
270+ async fn test_self_report_securejoin_uipath_stats ( ) -> Result < ( ) > {
271+ async fn check_report ( context : & TestContext , expected : & SecurejoinUIPathStats ) {
272+ let report = get_self_report ( context) . await . unwrap ( ) ;
273+ let actual: serde_json:: Value = serde_json:: from_str ( & report) . unwrap ( ) ;
274+ let actual = & actual[ "securejoin_uipath_stats" ] ;
275+
276+ let expected = serde_json:: to_string_pretty ( & expected) . unwrap ( ) ;
277+ let expected: serde_json:: Value = serde_json:: from_str ( & expected) . unwrap ( ) ;
278+
279+ assert_eq ! ( actual, & expected) ;
280+ }
281+
282+ let mut tcm = TestContextManager :: new ( ) ;
283+ let alice = & tcm. alice ( ) . await ;
284+ let bob = & tcm. bob ( ) . await ;
285+ alice. set_config_bool ( Config :: SelfReporting , true ) . await ?;
286+
287+ let mut expected = SecurejoinUIPathStats {
288+ other : 0 ,
289+ qr_icon : 0 ,
290+ new_contact : 0 ,
291+ } ;
292+
293+ check_report ( alice, & expected) . await ;
294+
295+ let qr = get_securejoin_qr ( bob, None ) . await ?;
248296
249- let expected = serde_json:: to_string_pretty ( & expected) . unwrap ( ) ;
250- let expected: serde_json:: Value = serde_json:: from_str ( & expected) . unwrap ( ) ;
297+ join_securejoin ( alice, & qr) . await ?;
298+ expected. other += 1 ;
299+ check_report ( alice, & expected) . await ;
300+
301+ join_securejoin ( alice, & qr) . await ?;
302+ expected. other += 1 ;
303+ check_report ( alice, & expected) . await ;
304+
305+ join_securejoin_with_source (
306+ alice,
307+ & qr,
308+ Some ( 0 ) ,
309+ Some ( SecurejoinUIPath :: NewContact as u32 ) ,
310+ )
311+ . await ?;
312+ expected. new_contact += 1 ;
313+ check_report ( alice, & expected) . await ;
314+
315+ join_securejoin_with_source (
316+ alice,
317+ & qr,
318+ Some ( 0 ) ,
319+ Some ( SecurejoinUIPath :: NewContact as u32 ) ,
320+ )
321+ . await ?;
322+ expected. new_contact += 1 ;
323+ check_report ( alice, & expected) . await ;
324+
325+ join_securejoin_with_source ( alice, & qr, Some ( 0 ) , Some ( SecurejoinUIPath :: QrIcon as u32 ) ) . await ?;
326+ expected. qr_icon += 1 ;
327+ check_report ( alice, & expected) . await ;
251328
252- assert_eq ! ( actual , & expected ) ;
329+ Ok ( ( ) )
253330}
254331
255332#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
0 commit comments