Skip to content

Commit

Permalink
rejected state test
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Nov 8, 2019
1 parent fc7cf56 commit f723e9f
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions tests/50federation/36-state.pl → tests/50federation/36state.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,90 @@ sub get_state_ids_from_server {
);
}

test "Room state at a rejected event is the same as its predecessor",
requires => [
$main::OUTBOUND_CLIENT,
federated_rooms_fixture(),
],

do => sub {
my ( $outbound_client, $creator_user, $sytest_user_id, $room ) = @_;

my $first_home_server = $creator_user->server_name;

my @initial_state_events = sort map { $room->id_for_event( $_ ) }
values %{ $room->{current_state} };

log_if_fail "initial state", @initial_state_events;

# we send a rejected state event, a rejected non-state event, and a
# regular event, and check that the end state is the same as the initial state.

my ( $rejected_state_event, $rejected_state_event_id ) = $room->create_and_insert_event(
type => "m.room.test_state",
event_key => "",

sender => '@fake_sender:' . $outbound_client->server_name,
content => {
body => "Rejected",
},
);

my ( $rejected_msg_event, $rejected_msg_event_id ) = $room->create_and_insert_event(
type => "m.room.message",

sender => '@fake_sender:' . $outbound_client->server_name,
content => {
body => "Rejected",
},
);

my ( $regular_event, $regular_event_id ) = $room->create_and_insert_event(
type => "m.room.message",

sender => $sytest_user_id,
content => {
body => "Hello",
},
);

$outbound_client->send_event(
event => $rejected_state_event,
destination => $first_home_server,
)->then( sub {
$outbound_client->send_event(
event => $rejected_msg_event,
destination => $first_home_server,
);
})->then( sub {
$outbound_client->send_event(
event => $regular_event,
destination => $first_home_server,
);
})->then( sub {
log_if_fail "sent events";
await_sync_timeline_contains( $creator_user, $room->room_id, check => sub {
my ( $event ) = @_;
return unless $event->{type} eq "m.room.message";
return unless $event->{content}->{body} eq "Hello";
return 1;
});
})->then( sub {
get_state_ids_from_server(
$outbound_client, $first_home_server, $room->room_id, $regular_event_id
);
})->then( sub {
my ( $body ) = @_;
log_if_fail "state_ids response", $body;

my @sorted_state = sort @{ $body->{pdu_ids} };
assert_deeply_eq( \@sorted_state, \@initial_state_events );

Future->done;
});
};


test "Inbound federation can get state for a room",
requires => [
$main::OUTBOUND_CLIENT,
Expand Down

0 comments on commit f723e9f

Please sign in to comment.