diff --git a/tests/10apidoc/09synced.pl b/tests/10apidoc/09synced.pl index d20a85b37..a6099ad9a 100644 --- a/tests/10apidoc/09synced.pl +++ b/tests/10apidoc/09synced.pl @@ -205,7 +205,35 @@ sub await_sync_presence_contains { } -push @EXPORT, qw( assert_room_members assert_state_room_members_matches ); +push @EXPORT, qw( assert_room_members assert_state_room_members_matches assert_room_state); + +# assert that the state body of a sync response is made up of the given state types. +sub assert_room_state { + my ( $body, $room_id, $state_types ) = @_; + + my $room = $body->{rooms}{join}{$room_id}; + my $state = $room->{state}{events}; + + log_if_fail "Room", $room; + + my $found_types = []; + foreach (@$state) { + push @$found_types, [ $_->{type}, $_->{state_key} ]; + } + + my $comp = sub { + my ($a, $b) = @_; + return ($a->[0] cmp $b->[0]) || ($a->[1] cmp $b->[1]); + }; + + $found_types = [ sort { &$comp($a, $b) } @$found_types ]; + $state_types = [ sort { &$comp($a, $b) } @$state_types ]; + + log_if_fail "Found state types", $found_types; + log_if_fail "Desired state types", $state_types; + + assert_deeply_eq($found_types, $state_types); +} # assert that the given members are in the body of a sync response sub assert_room_members { diff --git a/tests/31sync/15lazy-members.pl b/tests/31sync/15lazy-members.pl index 9e1ffebbd..e0282e767 100644 --- a/tests/31sync/15lazy-members.pl +++ b/tests/31sync/15lazy-members.pl @@ -161,7 +161,14 @@ matrix_sync( $alice, filter => $filter_id ); })->then( sub { my ( $body ) = @_; - assert_room_members( $body, $room_id, [ $bob->user_id ]); + assert_room_state( $body, $room_id, [ + [ 'm.room.create', '' ], + [ 'm.room.join_rules', '' ], + [ 'm.room.power_levels', '' ], + [ 'm.room.name', '' ], + [ 'm.room.history_visibility', '' ], + [ 'm.room.member', $bob->user_id ], + ]); matrix_send_room_text_message_synced( $charlie, $room_id, body => "Message from charlie", @@ -170,7 +177,9 @@ matrix_sync_again( $alice, filter => $filter_id ); })->then( sub { my ( $body ) = @_; - assert_room_members( $body, $room_id, [ $charlie->user_id ]); + assert_room_state( $body, $room_id, [ + [ 'm.room.member', $charlie->user_id ], + ]); Future->done(1); }); }; @@ -258,7 +267,6 @@ }); }; - test "We don't send redundant membership state across incremental syncs by default", requires => [ local_user_fixtures( 3 ), qw( can_sync ) ],