@@ -6,6 +6,7 @@ struct CallSetup {
6
6
pub alice : TestContext ,
7
7
pub alice2 : TestContext ,
8
8
pub alice_call : Message ,
9
+ pub alice2_call : Message ,
9
10
pub bob : TestContext ,
10
11
pub bob2 : TestContext ,
11
12
pub bob_call : Message ,
@@ -61,6 +62,7 @@ async fn setup_call() -> Result<CallSetup> {
61
62
alice,
62
63
alice2,
63
64
alice_call,
65
+ alice2_call,
64
66
bob,
65
67
bob2,
66
68
bob_call,
@@ -73,13 +75,14 @@ async fn accept_call() -> Result<CallSetup> {
73
75
alice,
74
76
alice2,
75
77
alice_call,
78
+ alice2_call,
76
79
bob,
77
80
bob2,
78
81
bob_call,
79
82
bob2_call,
80
83
} = setup_call ( ) . await ?;
81
84
82
- // Bob accepts the incoming call, this does not add an additional message to the chat
85
+ // Bob accepts the incoming call
83
86
bob. accept_incoming_call ( bob_call. id , "accepted_info" . to_string ( ) )
84
87
. await ?;
85
88
bob. evtracker
@@ -91,21 +94,22 @@ async fn accept_call() -> Result<CallSetup> {
91
94
assert_eq ! ( info. place_call_info, "place_info" ) ;
92
95
assert_eq ! ( info. accept_call_info, "accepted_info" ) ;
93
96
94
- let bob_accept_msg = bob2. recv_msg ( & sent2) . await ;
95
- assert ! ( bob_accept_msg. is_info( ) ) ;
96
- assert_eq ! ( bob_accept_msg. get_info_type( ) , SystemMessage :: CallAccepted ) ;
97
+ bob2. recv_msg_trash ( & sent2) . await ;
98
+ assert_eq ! (
99
+ Message :: load_from_db( & bob, bob_call. id) . await ?. text,
100
+ "Call accepted"
101
+ ) ;
97
102
bob2. evtracker
98
103
. get_matching ( |evt| matches ! ( evt, EventType :: IncomingCallAccepted { .. } ) )
99
104
. await ;
100
105
let info = bob2. load_call_by_id ( bob2_call. id ) . await ?;
101
106
assert ! ( !info. is_accepted) ; // "accepted" is only true on the device that does the call
102
107
103
108
// Alice receives the acceptance message
104
- let alice_accept_msg = alice. recv_msg ( & sent2) . await ;
105
- assert ! ( alice_accept_msg. is_info( ) ) ;
109
+ alice. recv_msg_trash ( & sent2) . await ;
106
110
assert_eq ! (
107
- alice_accept_msg . get_info_type ( ) ,
108
- SystemMessage :: CallAccepted
111
+ Message :: load_from_db ( & alice , alice_call . id ) . await ? . text ,
112
+ "Call accepted"
109
113
) ;
110
114
alice
111
115
. evtracker
@@ -116,11 +120,10 @@ async fn accept_call() -> Result<CallSetup> {
116
120
assert_eq ! ( info. place_call_info, "place_info" ) ;
117
121
assert_eq ! ( info. accept_call_info, "accepted_info" ) ;
118
122
119
- let alice2_accept_msg = alice2. recv_msg ( & sent2) . await ;
120
- assert ! ( alice2_accept_msg. is_info( ) ) ;
123
+ alice2. recv_msg_trash ( & sent2) . await ;
121
124
assert_eq ! (
122
- alice2_accept_msg . get_info_type ( ) ,
123
- SystemMessage :: CallAccepted
125
+ Message :: load_from_db ( & alice2 , alice2_call . id ) . await ? . text ,
126
+ "Call accepted"
124
127
) ;
125
128
alice2
126
129
. evtracker
@@ -131,53 +134,58 @@ async fn accept_call() -> Result<CallSetup> {
131
134
alice,
132
135
alice2,
133
136
alice_call,
137
+ alice2_call,
134
138
bob,
135
139
bob2,
136
140
bob_call,
137
141
bob2_call,
138
142
} )
139
143
}
140
144
141
- fn assert_is_call_ended_info_msg ( msg : Message ) {
142
- assert ! ( msg . is_info ( ) ) ;
143
- assert_eq ! ( msg . get_info_type ( ) , SystemMessage :: CallEnded ) ;
145
+ async fn assert_is_call_ended ( t : & TestContext , call_id : MsgId ) -> Result < ( ) > {
146
+ assert_eq ! ( Message :: load_from_db ( t , call_id ) . await ? . text , "Call ended" ) ;
147
+ Ok ( ( ) )
144
148
}
145
149
146
150
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
147
151
async fn test_accept_call_callee_ends ( ) -> Result < ( ) > {
148
152
// Alice calls Bob, Bob accepts
149
153
let CallSetup {
150
154
alice,
155
+ alice_call,
151
156
alice2,
157
+ alice2_call,
152
158
bob,
153
159
bob2,
154
160
bob_call,
161
+ bob2_call,
155
162
..
156
163
} = accept_call ( ) . await ?;
157
164
158
165
// Bob has accepted the call and also ends it
159
166
bob. end_call ( bob_call. id ) . await ?;
167
+ assert_is_call_ended ( & bob, bob_call. id ) . await ?;
160
168
bob. evtracker
161
169
. get_matching ( |evt| matches ! ( evt, EventType :: CallEnded { .. } ) )
162
170
. await ;
163
171
let sent3 = bob. pop_sent_msg ( ) . await ;
164
172
165
- let bob2_end_call_msg = bob2. recv_msg ( & sent3) . await ;
166
- assert_is_call_ended_info_msg ( bob2_end_call_msg ) ;
173
+ bob2. recv_msg_trash ( & sent3) . await ;
174
+ assert_is_call_ended ( & bob2 , bob2_call . id ) . await ? ;
167
175
bob2. evtracker
168
176
. get_matching ( |evt| matches ! ( evt, EventType :: CallEnded { .. } ) )
169
177
. await ;
170
178
171
179
// Alice receives the ending message
172
- let alice_end_call_msg = alice. recv_msg ( & sent3) . await ;
173
- assert_is_call_ended_info_msg ( alice_end_call_msg ) ;
180
+ alice. recv_msg_trash ( & sent3) . await ;
181
+ assert_is_call_ended ( & alice , alice_call . id ) . await ? ;
174
182
alice
175
183
. evtracker
176
184
. get_matching ( |evt| matches ! ( evt, EventType :: CallEnded { .. } ) )
177
185
. await ;
178
186
179
- let alice2_end_call_msg = alice2. recv_msg ( & sent3) . await ;
180
- assert_is_call_ended_info_msg ( alice2_end_call_msg ) ;
187
+ alice2. recv_msg_trash ( & sent3) . await ;
188
+ assert_is_call_ended ( & alice2 , alice2_call . id ) . await ? ;
181
189
alice2
182
190
. evtracker
183
191
. get_matching ( |evt| matches ! ( evt, EventType :: CallEnded { .. } ) )
@@ -192,9 +200,11 @@ async fn test_accept_call_caller_ends() -> Result<()> {
192
200
let CallSetup {
193
201
alice,
194
202
alice2,
203
+ alice2_call,
195
204
bob,
196
205
bob2,
197
206
bob_call,
207
+ bob2_call,
198
208
..
199
209
} = accept_call ( ) . await ?;
200
210
@@ -206,22 +216,22 @@ async fn test_accept_call_caller_ends() -> Result<()> {
206
216
. await ;
207
217
let sent3 = alice. pop_sent_msg ( ) . await ;
208
218
209
- let alice2_end_call_msg = alice2. recv_msg ( & sent3) . await ;
210
- assert_is_call_ended_info_msg ( alice2_end_call_msg ) ;
219
+ alice2. recv_msg_trash ( & sent3) . await ;
220
+ assert_is_call_ended ( & alice2 , alice2_call . id ) . await ? ;
211
221
alice2
212
222
. evtracker
213
223
. get_matching ( |evt| matches ! ( evt, EventType :: CallEnded { .. } ) )
214
224
. await ;
215
225
216
226
// Bob receives the ending message
217
- let bob_end_call_msg = bob. recv_msg ( & sent3) . await ;
218
- assert_is_call_ended_info_msg ( bob_end_call_msg ) ;
227
+ bob. recv_msg_trash ( & sent3) . await ;
228
+ assert_is_call_ended ( & bob , bob_call . id ) . await ? ;
219
229
bob. evtracker
220
230
. get_matching ( |evt| matches ! ( evt, EventType :: CallEnded { .. } ) )
221
231
. await ;
222
232
223
- let bob2_end_call_msg = bob2. recv_msg ( & sent3) . await ;
224
- assert_is_call_ended_info_msg ( bob2_end_call_msg ) ;
233
+ bob2. recv_msg_trash ( & sent3) . await ;
234
+ assert_is_call_ended ( & bob2 , bob2_call . id ) . await ? ;
225
235
bob2. evtracker
226
236
. get_matching ( |evt| matches ! ( evt, EventType :: CallEnded { .. } ) )
227
237
. await ;
@@ -236,18 +246,21 @@ async fn test_callee_rejects_call() -> Result<()> {
236
246
bob,
237
247
bob2,
238
248
bob_call,
249
+ bob2_call,
239
250
..
240
251
} = setup_call ( ) . await ?;
241
252
242
253
// Bob does not want to talk with Alice.
243
254
// To protect Bob's privacy, no message is sent to Alice (who will time out).
244
255
// To let Bob close the call window on all devices, a sync message is used instead.
245
256
bob. end_call ( bob_call. id ) . await ?;
257
+ assert_is_call_ended ( & bob, bob_call. id ) . await ?;
246
258
bob. evtracker
247
259
. get_matching ( |evt| matches ! ( evt, EventType :: CallEnded { .. } ) )
248
260
. await ;
249
261
250
262
sync ( & bob, & bob2) . await ;
263
+ assert_is_call_ended ( & bob2, bob2_call. id ) . await ?;
251
264
bob2. evtracker
252
265
. get_matching ( |evt| matches ! ( evt, EventType :: CallEnded { .. } ) )
253
266
. await ;
@@ -262,35 +275,39 @@ async fn test_caller_cancels_call() -> Result<()> {
262
275
alice,
263
276
alice2,
264
277
alice_call,
278
+ alice2_call,
265
279
bob,
266
280
bob2,
281
+ bob_call,
282
+ bob2_call,
267
283
..
268
284
} = setup_call ( ) . await ?;
269
285
270
286
// Alice changes their mind before Bob picks up
271
287
alice. end_call ( alice_call. id ) . await ?;
288
+ assert_is_call_ended ( & alice, alice_call. id ) . await ?;
272
289
alice
273
290
. evtracker
274
291
. get_matching ( |evt| matches ! ( evt, EventType :: CallEnded { .. } ) )
275
292
. await ;
276
293
let sent3 = alice. pop_sent_msg ( ) . await ;
277
294
278
- let alice2_call_ended_msg = alice2. recv_msg ( & sent3) . await ;
279
- assert_is_call_ended_info_msg ( alice2_call_ended_msg ) ;
295
+ alice2. recv_msg_trash ( & sent3) . await ;
296
+ assert_is_call_ended ( & alice2 , alice2_call . id ) . await ? ;
280
297
alice2
281
298
. evtracker
282
299
. get_matching ( |evt| matches ! ( evt, EventType :: CallEnded { .. } ) )
283
300
. await ;
284
301
285
302
// Bob receives the ending message
286
- let bob_call_ended_msg = bob. recv_msg ( & sent3) . await ;
287
- assert_is_call_ended_info_msg ( bob_call_ended_msg ) ;
303
+ bob. recv_msg_trash ( & sent3) . await ;
304
+ assert_is_call_ended ( & bob , bob_call . id ) . await ? ;
288
305
bob. evtracker
289
306
. get_matching ( |evt| matches ! ( evt, EventType :: CallEnded { .. } ) )
290
307
. await ;
291
308
292
- let bob2_call_ended_msg = bob2. recv_msg ( & sent3) . await ;
293
- assert_is_call_ended_info_msg ( bob2_call_ended_msg ) ;
309
+ bob2. recv_msg_trash ( & sent3) . await ;
310
+ assert_is_call_ended ( & bob2 , bob2_call . id ) . await ? ;
294
311
bob2. evtracker
295
312
. get_matching ( |evt| matches ! ( evt, EventType :: CallEnded { .. } ) )
296
313
. await ;
0 commit comments