Skip to content

Commit

Permalink
Send a second message when testing forwarding to Matrix
Browse files Browse the repository at this point in the history
To make sure the user creation/invites work as intended
  • Loading branch information
exul committed Mar 16, 2017
1 parent f81aac5 commit f5a118d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/matrix-rocketchat/handlers/rocketchat/forwarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use slog::Logger;
use api::MatrixApi;
use api::rocketchat::Message;
use config::Config;
use db::{NewUser, NewUserInRoom, NewUserOnRocketchatServer, RocketchatServer, Room, User, UserInRoom,
UserOnRocketchatServer};
use db::{NewUser, NewUserInRoom, NewUserOnRocketchatServer, RocketchatServer, Room, User, UserInRoom, UserOnRocketchatServer};
use errors::*;
use i18n::DEFAULT_LANGUAGE;

Expand All @@ -33,15 +32,14 @@ impl<'a> Forwarder<'a> {
let user_on_rocketchat_server =
match UserOnRocketchatServer::find_by_rocketchat_user_id(self.connection,
rocketchat_server.id,
message.user_id
.clone())? {
message.user_id.clone())? {
Some(user_on_rocketchat_server) => user_on_rocketchat_server,
None => self.create_virtual_user_on_rocketchat_server(rocketchat_server.id, message)?,
};

let room = match Room::find_by_rocketchat_room_id(self.connection,
rocketchat_server.id,
message.channel_id.clone())? {
rocketchat_server.id,
message.channel_id.clone())? {
Some(room) => room,
None => {
debug!(self.logger,
Expand Down Expand Up @@ -92,7 +90,6 @@ impl<'a> Forwarder<'a> {
rocketchat_user_id: Some(message.user_id.clone()),
rocketchat_username: Some(message.user_name.clone()),
};

UserOnRocketchatServer::upsert(self.connection, &new_user_on_rocketchat_server)
}

Expand Down
16 changes: 16 additions & 0 deletions tests/rocketchat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ fn successfully_forwards_a_text_message_to_matrix() {
// the virtual user was create with the Rocket.Chat user ID
let user_on_rocketchat = UserOnRocketchatServer::find(&connection, new_user_id, rocketchat_server_id).unwrap();
assert_eq!(user_on_rocketchat.rocketchat_user_id.unwrap(), "new_user_id".to_string());

let second_message = Message {
message_id: "spec_id_2".to_string(),
token: Some(RS_TOKEN.to_string()),
channel_id: "spec_channel_id".to_string(),
channel_name: "spec_channel".to_string(),
user_id: "new_user_id".to_string(),
user_name: "new_spec_user".to_string(),
text: "spec_message 2".to_string(),
};
let second_payload = to_string(&second_message).unwrap();

helpers::simulate_message_from_rocketchat(&test.config.as_url, &second_payload);

let message_received_by_matrix = receiver.recv_timeout(default_timeout()).unwrap();
assert!(message_received_by_matrix.contains("spec_message 2"));
}

#[test]
Expand Down

0 comments on commit f5a118d

Please sign in to comment.