Browse Source

Write tests for RoomJoinResponseHandler.

wip
Titouan Rigoudy 4 years ago
parent
commit
3c4487f764
2 changed files with 37 additions and 22 deletions
  1. +30
    -22
      client/src/handlers/room_join_response_handler.rs
  2. +7
    -0
      client/src/room.rs

+ 30
- 22
client/src/handlers/room_join_response_handler.rs View File

@ -50,45 +50,53 @@ impl MessageHandler for RoomJoinResponseHandler {
#[cfg(test)]
mod tests {
/*
use solstice_proto::server::RoomJoinResponse;
use crate::context::ContextBundle;
use crate::context::{ContextBundle, ContextOptions};
use crate::control;
use crate::message_handler::MessageHandler;
use crate::room::{Room, Visibility};
use crate::room::{Membership, Room, Visibility};
use super::RoomJoinResponseHandler;
// Cannot get the compiler to be satisfied when borrowing the name...
fn room_name(pair: &(String, Room)) -> String {
pair.0.clone()
}
#[test]
fn run_sets_room_list() {
let bundle = ContextBundle::default();
fn run_updates_room_state_and_forwards_response() {
let mut room = Room::new(Visibility::Public, 42);
let mut options = ContextOptions::default();
options
.initial_state
.rooms
.insert("apple".to_string(), room.clone());
let mut bundle = ContextBundle::new(options);
let response = RoomJoinResponse {
rooms: vec![("potato".to_string(), 123), ("apple".to_string(), 42)],
owned_private_rooms: vec![],
other_private_rooms: vec![],
operated_private_room_names: vec![],
room_name: "apple".to_string(),
operators: vec!["shruti".to_string()],
owner: Some("kim".to_string()),
users: vec![],
};
RoomJoinResponseHandler::default()
.run(&bundle.context, &response)
.unwrap();
let mut rooms = bundle.context.state.lock().rooms.get_room_list();
rooms.sort_by_key(room_name);
room.membership = Membership::Member;
room.user_count = 0;
room.operators = ["shruti"].iter().map(|s| s.to_string()).collect();
room.owner = Some("kim".to_string());
let rooms = bundle.context.state.lock().rooms.get_room_list();
assert_eq!(rooms, vec![("apple".to_string(), room.clone())]);
let response = bundle.control_response_rx.blocking_recv().unwrap();
assert_eq!(
rooms,
vec![
("apple".to_string(), Room::new(Visibility::Public, 42)),
("potato".to_string(), Room::new(Visibility::Public, 123)),
]
response,
control::Response::RoomJoinResponse(control::RoomJoinResponse {
room_name: "apple".to_string(),
room,
})
);
}
*/
}

+ 7
- 0
client/src/room.rs View File

@ -131,6 +131,13 @@ impl RoomMap {
Self::default()
}
/// Inserts the given room in the map under the given name.
/// Same semantics as `std::collections::HashMap::insert()`.
#[cfg(test)]
pub fn insert(&mut self, name: String, room: Room) -> Option<Room> {
self.map.insert(name, room)
}
/// Looks up the given room name in the map, returning an immutable
/// reference to the associated data if found, or an error if not found.
#[cfg(test)]


Loading…
Cancel
Save