@@ -89,8 +89,9 @@ async fn test_self_report_one_contact() -> Result<()> {
89
89
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
90
90
async fn test_message_stats ( ) -> Result < ( ) > {
91
91
fn check_report ( report : & str , expected : & MessageStats ) {
92
+ let key = "message_stats" ;
92
93
let actual: serde_json:: Value = serde_json:: from_str ( & report) . unwrap ( ) ;
93
- let actual = & actual[ "message_stats" ] ;
94
+ let actual = & actual[ key ] ;
94
95
95
96
let expected = serde_json:: to_string_pretty ( & expected) . unwrap ( ) ;
96
97
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 {
184
185
185
186
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
186
187
async 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
+
187
199
let mut tcm = TestContextManager :: new ( ) ;
188
200
let alice = & tcm. alice ( ) . await ;
189
201
let bob = & tcm. bob ( ) . await ;
@@ -198,58 +210,123 @@ async fn test_self_report_securejoin_source_stats() -> Result<()> {
198
210
scan : 0 ,
199
211
} ;
200
212
201
- check_securejoin_report ( alice, & expected) . await ;
213
+ check_report ( alice, & expected) . await ;
202
214
203
215
let qr = get_securejoin_qr ( bob, None ) . await ?;
204
216
205
217
join_securejoin ( alice, & qr) . await ?;
206
218
expected. unknown += 1 ;
207
- check_securejoin_report ( alice, & expected) . await ;
219
+ check_report ( alice, & expected) . await ;
208
220
209
221
join_securejoin ( alice, & qr) . await ?;
210
222
expected. unknown += 1 ;
211
- check_securejoin_report ( alice, & expected) . await ;
223
+ check_report ( alice, & expected) . await ;
212
224
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 ?;
214
226
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 ?;
218
236
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 ?;
222
246
expected. internal_link += 1 ;
223
- check_securejoin_report ( alice, & expected) . await ;
247
+ check_report ( alice, & expected) . await ;
224
248
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 ?;
226
251
expected. image_loaded += 1 ;
227
- check_securejoin_report ( alice, & expected) . await ;
252
+ check_report ( alice, & expected) . await ;
228
253
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 ?;
230
255
expected. scan += 1 ;
231
- check_securejoin_report ( alice, & expected) . await ;
256
+ check_report ( alice, & expected) . await ;
232
257
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 ?;
234
259
expected. clipboard += 1 ;
235
- check_securejoin_report ( alice, & expected) . await ;
260
+ check_report ( alice, & expected) . await ;
236
261
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 ?;
238
263
expected. clipboard += 1 ;
239
- check_securejoin_report ( alice, & expected) . await ;
264
+ check_report ( alice, & expected) . await ;
240
265
241
266
Ok ( ( ) )
242
267
}
243
268
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 ?;
248
296
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 ;
251
328
252
- assert_eq ! ( actual , & expected ) ;
329
+ Ok ( ( ) )
253
330
}
254
331
255
332
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
0 commit comments