From f38eb490c19f1829518605d93b55a84c975460ed Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 25 Jan 2019 14:07:50 +0000 Subject: [PATCH 1/2] Add test for upgraded room search --- tests/30rooms/60version_upgrade.pl | 2 + tests/43search.pl | 79 ++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/tests/30rooms/60version_upgrade.pl b/tests/30rooms/60version_upgrade.pl index b415479aa..6731911be 100644 --- a/tests/30rooms/60version_upgrade.pl +++ b/tests/30rooms/60version_upgrade.pl @@ -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'; diff --git a/tests/43search.pl b/tests/43search.pl index 0bbaa0a0a..5504ff867 100644 --- a/tests/43search.pl +++ b/tests/43search.pl @@ -228,3 +228,82 @@ Future->done( 1 ); }); }; + +test "Search works across an upgraded room", + 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); + }); + }; \ No newline at end of file From f8d78e1adc9ab479e80f4b76e3993ebf4b9e0c3a Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 25 Jan 2019 14:09:37 +0000 Subject: [PATCH 2/2] Fix test title --- tests/43search.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/43search.pl b/tests/43search.pl index 5504ff867..555ea0250 100644 --- a/tests/43search.pl +++ b/tests/43search.pl @@ -229,7 +229,7 @@ }); }; -test "Search works across an upgraded room", +test "Search works across an upgraded room and its predecessor", requires => [ local_user_and_room_fixtures(), qw ( can_upgrade_room_version ),