Skip to content

Commit

Permalink
Merge pull request #549 from matrix-org/anoa/upgraded_room_search
Browse files Browse the repository at this point in the history
Add test for upgraded room search
  • Loading branch information
anoadragon453 authored Jan 28, 2019
2 parents 9ca46a4 + f8d78e1 commit 0fda808
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/30rooms/60version_upgrade.pl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Future::Utils qw( repeat );
use List::Util qw( all first );

push our @EXPORT, qw ( upgrade_room_synced $TEST_NEW_VERSION );

# TODO: switch this to '2' once that is released
my $TEST_NEW_VERSION = 'vdh-test-version';

Expand Down
79 changes: 79 additions & 0 deletions tests/43search.pl
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,82 @@
Future->done( 1 );
});
};

test "Search works across an upgraded room and its predecessor",
requires => [
local_user_and_room_fixtures(),
qw ( can_upgrade_room_version ),
],

check => sub {
my ( $user, $room_id ) = @_;

my ( $event_id_one, $event_id_two );

matrix_send_room_text_message( $user, $room_id,
body => "message 1",
)->then( sub {
( $event_id_one ) = @_;

upgrade_room_synced(
$user, $room_id,
new_version => $main::TEST_NEW_VERSION,
);
})->then( sub {
my ( $new_room_id ) = @_;

matrix_send_room_text_message( $user, $new_room_id,
body => "message 2",
);
})->then( sub {
( $event_id_two ) = @_;

do_request_json_for( $user,
method => "POST",
uri => "/r0/search",
content => {
search_categories => {
room_events => {
keys => [ "content.body" ],
search_term => "message",
}
}
}
);
})->then( sub {
my ( $body ) = @_;

log_if_fail "Search Result Body:", $body;

assert_json_keys( $body, qw( search_categories ) );
assert_json_keys( $body->{search_categories}, qw ( room_events ) );

my $room_events = $body->{search_categories}{room_events};
assert_json_keys( $room_events, qw( count results ) );

$room_events->{count} == 2 or die "Expected two search results";

my $results = $room_events->{results};
my $result = first { $_->{result}{event_id} eq $event_id_one } @$results;

assert_json_keys( $result, qw( rank result ) );
assert_json_keys( $result->{result}, qw(
event_id room_id user_id content type
));

$result->{result}{content}{body} eq "message 1"
or die "Unexpected event content in search result";

my $result_two = first { $_->{result}{event_id} eq $event_id_two } @$results;

assert_json_keys( $result_two, qw( rank result ) );
assert_json_keys( $result_two->{result}, qw(
event_id room_id user_id content type
));

$result_two->{result}{content}{body} eq "message 2"
or die "Unexpected event content in search result";

Future->done(1);
});
};

0 comments on commit 0fda808

Please sign in to comment.