Skip to content

Commit

Permalink
Add spec to test that messages from the bot user are ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
exul committed Feb 4, 2017
1 parent bafef8d commit 252b9f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/matrix-rocketchat/db/rocketchat_server.rs
Expand Up @@ -45,10 +45,10 @@ impl RocketchatServer {
/// Find a `RocketchatServer` by its URL, return an error if the `RocketchatServer` is not
/// found.
pub fn find(connection: &SqliteConnection, url: String) -> Result<RocketchatServer> {
rocketchat_servers::table.filter(rocketchat_servers::rocketchat_url.eq(url))
let rocketchat_server = rocketchat_servers::table.filter(rocketchat_servers::rocketchat_url.eq(url))
.first(connection)
.chain_err(|| ErrorKind::DBSelectError)
.map_err(Error::from)
.chain_err(|| ErrorKind::DBSelectError)?;
Ok(rocketchat_server)
}

/// Find a `RocketchatServer` by its URL.
Expand Down
22 changes: 21 additions & 1 deletion tests/admin_commands_unkown.rs
Expand Up @@ -50,6 +50,26 @@ fn unknown_content_types_from_the_admin_room_are_ignored() {
UserId::try_from("@spec_user:localhost").unwrap(),
"emote message".to_string());

// we don't get a message, because unkown content types are ignored and no error occurs
// we don't get a message, because unknown content types are ignored and no error occurs
receiver.recv_timeout(default_timeout()).is_err();
}

#[test]
fn messages_from_the_bot_user_are_ignored() {
let (message_forwarder, receiver) = MessageForwarder::new();
let mut matrix_router = Router::new();
matrix_router.put(SendMessageEventEndpoint::router_path(), message_forwarder, "send_message_event");

let test = Test::new()
.with_matrix_routes(matrix_router)
.with_admin_room()
.run();

helpers::send_room_message_from_matrix(&test.config.as_url,
RoomId::try_from("!admin:localhost").unwrap(),
UserId::try_from("@rocketchat:localhost").unwrap(),
"bot message".to_string());

// we don't get a message, because messages from the bot user are ignored and no error occurs
receiver.recv_timeout(default_timeout()).is_err();
}

0 comments on commit 252b9f7

Please sign in to comment.