@@ -82,6 +82,54 @@ async fn test_self_report_one_contact() -> Result<()> {
82
82
Ok ( ( ) )
83
83
}
84
84
85
+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
86
+ async fn test_message_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
+ let email_chat = alice. create_email_chat ( bob) . await ;
92
+ let encrypted_chat = alice. create_chat ( bob) . await ;
93
+
94
+ let mut expected = MessageStats {
95
+ to_verified : 0 ,
96
+ unverified_encrypted : 0 ,
97
+ unencrypted : 0 ,
98
+ } ;
99
+
100
+ check_message_stats_report ( alice, & expected) . await ;
101
+
102
+ alice. send_text ( email_chat. id , "foo" ) . await ;
103
+ expected. unencrypted += 1 ;
104
+ check_message_stats_report ( alice, & expected) . await ;
105
+
106
+ alice. send_text ( encrypted_chat. id , "foo" ) . await ;
107
+ expected. unverified_encrypted += 1 ;
108
+ check_message_stats_report ( alice, & expected) . await ;
109
+
110
+ alice. send_text ( encrypted_chat. id , "foo" ) . await ;
111
+ expected. unverified_encrypted += 1 ;
112
+ check_message_stats_report ( alice, & expected) . await ;
113
+
114
+ tcm. execute_securejoin ( alice, bob) . await ;
115
+ expected. to_verified = expected. unverified_encrypted ;
116
+ expected. unverified_encrypted = 0 ;
117
+ check_message_stats_report ( alice, & expected) . await ;
118
+
119
+ Ok ( ( ) )
120
+ }
121
+
122
+ async fn check_message_stats_report ( context : & TestContext , expected : & MessageStats ) {
123
+ let report = get_self_report ( context, 0 ) . await . unwrap ( ) ;
124
+ let actual: serde_json:: Value = serde_json:: from_str ( & report) . unwrap ( ) ;
125
+ let actual = & actual[ "message_stats" ] ;
126
+
127
+ let expected = serde_json:: to_string_pretty ( & expected) . unwrap ( ) ;
128
+ let expected: serde_json:: Value = serde_json:: from_str ( & expected) . unwrap ( ) ;
129
+
130
+ assert_eq ! ( actual, & expected) ;
131
+ }
132
+
85
133
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
86
134
async fn test_self_report_securejoin_source_stats ( ) -> Result < ( ) > {
87
135
let mut tcm = TestContextManager :: new ( ) ;
@@ -149,5 +197,5 @@ async fn check_securejoin_report(context: &TestContext, expected: &SecurejoinSou
149
197
let expected = serde_json:: to_string_pretty ( & expected) . unwrap ( ) ;
150
198
let expected: serde_json:: Value = serde_json:: from_str ( & expected) . unwrap ( ) ;
151
199
152
- assert_eq ! ( & expected , actual ) ;
200
+ assert_eq ! ( actual , & expected ) ;
153
201
}
0 commit comments