Browse Source

Test ServerLoggedInContext::new().

main
Titouan Rigoudy 2 years ago
parent
commit
0a2fea7bcb
3 changed files with 54 additions and 3 deletions
  1. +51
    -0
      client/src/server/context.rs
  2. +2
    -2
      client/src/server/room/map.rs
  3. +1
    -1
      client/src/server/user/map.rs

+ 51
- 0
client/src/server/context.rs View File

@ -224,3 +224,54 @@ impl ServerContext {
} }
} }
} }
#[cfg(test)]
mod tests {
use solstice_proto::{User, UserStatus};
use tokio::sync::mpsc::channel;
use crate::server::room::{RoomMap, RoomState, RoomVisibility};
use crate::server::user::UserMap;
use super::{ServerLoggedInContext, ServerLoggedInContextOptions};
#[test]
fn server_logged_in_context_new() {
let mut rooms = RoomMap::default();
rooms.insert(
"foo".to_string(),
RoomState::new(RoomVisibility::Public, 42),
);
let mut users = UserMap::default();
users.insert(User {
name: "kim".to_string(),
status: UserStatus::Online,
average_speed: 1,
num_downloads: 2,
unknown: 3,
num_files: 4,
num_folders: 5,
num_free_slots: 6,
country: "KR".to_string(),
});
let (tx, _rx) = channel(100);
let context = ServerLoggedInContext::new(
tx.clone(),
ServerLoggedInContextOptions {
users: users.clone(),
rooms: rooms.clone(),
user_name: "bob".to_string(),
motd: "hey".to_string(),
},
);
assert_eq!(context.user_name(), "bob");
assert_eq!(context.motd(), "hey");
assert!(context.request_tx.same_channel(&tx));
assert_eq!(context.rooms, rooms);
assert_eq!(context.users, users);
}
}

+ 2
- 2
client/src/server/room/map.rs View File

@ -21,7 +21,7 @@ pub struct RoomMembershipChangeError(RoomMembership, RoomMembership);
pub struct RoomNotFoundError(String); pub struct RoomNotFoundError(String);
/// An entry in the chat room map. /// An entry in the chat room map.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct RoomEntry { pub struct RoomEntry {
name: String, name: String,
state: RoomState, state: RoomState,
@ -138,7 +138,7 @@ impl RoomEntry {
/// Contains the mapping from room names to room data and provides a clean /// Contains the mapping from room names to room data and provides a clean
/// interface to interact with it. /// interface to interact with it.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct RoomMap { pub struct RoomMap {
/// The actual map from room names to room data. /// The actual map from room names to room data.
map: HashMap<String, RoomEntry>, map: HashMap<String, RoomEntry>,


+ 1
- 1
client/src/server/user/map.rs View File

@ -11,7 +11,7 @@ pub struct UserNotFoundError(String);
/// Contains the mapping from user names to user data and provides a clean /// Contains the mapping from user names to user data and provides a clean
/// interface to interact with it. /// interface to interact with it.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct UserMap { pub struct UserMap {
/// The actual map from user names to user data and privileged status. /// The actual map from user names to user data and privileged status.
map: collections::HashMap<String, User>, map: collections::HashMap<String, User>,


Loading…
Cancel
Save