-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Send ParticipantsChanged event when occupant availability change…
…s (refs #40)
- Loading branch information
Showing
5 changed files
with
96 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,12 +55,12 @@ async fn test_adds_participant() -> Result<()> { | |
|
||
deps.client_event_dispatcher | ||
.expect_dispatch_room_event() | ||
.once() | ||
.times(2) | ||
.with( | ||
predicate::eq(room.clone()), | ||
predicate::eq(ClientRoomEventType::ParticipantsChanged), | ||
) | ||
.return_once(|_, _| ()); | ||
.returning(|_, _| ()); | ||
|
||
let event_handler = RoomsEventHandler::from(&deps.into_deps()); | ||
|
||
|
@@ -200,12 +200,12 @@ async fn test_handles_disconnected_participant() -> Result<()> { | |
|
||
deps.client_event_dispatcher | ||
.expect_dispatch_room_event() | ||
.once() | ||
.times(2) | ||
.with( | ||
predicate::eq(room.clone()), | ||
predicate::eq(ClientRoomEventType::ParticipantsChanged), | ||
) | ||
.return_once(|_, _| ()); | ||
.returning(|_, _| ()); | ||
|
||
let event_handler = RoomsEventHandler::from(&deps.into_deps()); | ||
|
||
|
@@ -535,7 +535,7 @@ async fn test_handles_invite() -> Result<()> { | |
} | ||
|
||
#[tokio::test] | ||
async fn test_handles_presence() -> Result<()> { | ||
async fn test_handles_user_presence() -> Result<()> { | ||
let mut deps = MockAppDependencies::default(); | ||
|
||
let room = Room::for_direct_message( | ||
|
@@ -596,6 +596,69 @@ async fn test_handles_presence() -> Result<()> { | |
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_handles_occupant_presence() -> Result<()> { | ||
let mut deps = MockAppDependencies::default(); | ||
|
||
let room = Room::group(room_id!("[email protected]")).with_participants([( | ||
occupant_id!("[email protected]/nick"), | ||
Participant::owner() | ||
.set_real_id(&user_id!("[email protected]")) | ||
.set_availability(Availability::Available), | ||
)]); | ||
|
||
{ | ||
let room = room.clone(); | ||
deps.connected_rooms_repo | ||
.expect_get() | ||
.once() | ||
.with(predicate::eq(room_id!("[email protected]"))) | ||
.return_once(move |_| Some(room.clone())); | ||
} | ||
|
||
{ | ||
let room = room.clone(); | ||
deps.client_event_dispatcher | ||
.expect_dispatch_room_event() | ||
.once() | ||
.with( | ||
predicate::eq(room.clone()), | ||
predicate::eq(ClientRoomEventType::ParticipantsChanged), | ||
) | ||
.return_once(|_, _| ()); | ||
} | ||
|
||
let event_handler = RoomsEventHandler::from(&deps.into_deps()); | ||
|
||
assert_eq!( | ||
room.participants() | ||
.get(&occupant_id!("[email protected]/nick").into()) | ||
.unwrap() | ||
.availability, | ||
Availability::Available | ||
); | ||
|
||
event_handler | ||
.handle_event(ServerEvent::UserStatus(UserStatusEvent { | ||
user_id: occupant_id!("[email protected]/nick").into(), | ||
r#type: UserStatusEventType::AvailabilityChanged { | ||
availability: Availability::DoNotDisturb, | ||
priority: 1, | ||
}, | ||
})) | ||
.await?; | ||
|
||
assert_eq!( | ||
room.participants() | ||
.get(&occupant_id!("[email protected]/nick").into()) | ||
.unwrap() | ||
.availability, | ||
Availability::DoNotDisturb | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_handles_contact_presence_with_no_room() -> Result<()> { | ||
let mut deps = MockAppDependencies::default(); | ||
|