Skip to content

Commit a07ad0c

Browse files
committed
test call acceptance
1 parent bd8b235 commit a07ad0c

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/calls.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ pub struct CallInfo {
3737

3838
/// Was an incoming call accepted on this device?
3939
/// On other devices, this is never set and for outgoing calls, this is never set.
40-
/// Internally, this is written to Param::Arg.
4140
pub accepted: bool,
4241

4342
/// Info message referring to the call.
@@ -234,18 +233,30 @@ impl Context {
234233

235234
Ok(CallInfo {
236235
incoming: call.get_info_type() == SystemMessage::IncomingCall,
237-
accepted: call.param.get_int(Param::Arg) == Some(1),
236+
accepted: call.is_call_accepted()?,
238237
msg: call,
239238
})
240239
}
241240
}
242241

243242
impl Message {
244243
async fn mark_call_as_accepted(&mut self, context: &Context) -> Result<()> {
244+
ensure!(
245+
self.get_info_type() == SystemMessage::IncomingCall
246+
|| self.get_info_type() == SystemMessage::OutgoingCall
247+
);
245248
self.param.set_int(Param::Arg, 1);
246249
self.update_param(context).await?;
247250
Ok(())
248251
}
252+
253+
fn is_call_accepted(&self) -> Result<bool> {
254+
ensure!(
255+
self.get_info_type() == SystemMessage::IncomingCall
256+
|| self.get_info_type() == SystemMessage::OutgoingCall
257+
);
258+
Ok(self.param.get_int(Param::Arg) == Some(1))
259+
}
249260
}
250261

251262
#[cfg(test)]
@@ -504,4 +515,20 @@ mod tests {
504515

505516
Ok(())
506517
}
518+
519+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
520+
async fn test_mark_call_as_accepted() -> Result<()> {
521+
let (alice, _alice2, alice_call, _bob, _bob2, _bob_call, _bob2_call) = setup_call().await?;
522+
assert!(!alice_call.is_call_accepted()?);
523+
524+
let mut alice_call = Message::load_from_db(&alice, alice_call.id).await?;
525+
assert!(!alice_call.is_call_accepted()?);
526+
alice_call.mark_call_as_accepted(&alice).await?;
527+
assert!(alice_call.is_call_accepted()?);
528+
529+
let alice_call = Message::load_from_db(&alice, alice_call.id).await?;
530+
assert!(alice_call.is_call_accepted()?);
531+
532+
Ok(())
533+
}
507534
}

0 commit comments

Comments
 (0)