Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for upgraded room search #549

Merged
merged 2 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
};