Skip to content

Commit

Permalink
Merge pull request #121 from matrix-org/daniel/avatarurls
Browse files Browse the repository at this point in the history
Tests for returning room avatar URLs in /publicRooms

Spec: matrix-org/matrix-spec-proposals#244
Impl: matrix-org/synapse#453
  • Loading branch information
illicitonion committed Jan 5, 2016
2 parents fb3f31b + b914bb6 commit 1337730
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions tests/30rooms/60anonymousaccess.pl
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,87 @@ sub check_events
});
};

test "GET /publicRooms includes avatar URLs",
requires => [ $main::API_CLIENTS[0], local_user_fixture() ],

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

Future->needs_all(
matrix_create_room( $user,
visibility => "public",
room_alias_name => "nonworldreadable",
)->then( sub {
my ( $room_id ) = @_;

matrix_put_room_state( $user, $room_id,
type => "m.room.avatar",
state_key => "",
content => {
url => "https://example.com/ruffed.jpg",
}
);
}),

matrix_create_room( $user,
visibility => "public",
room_alias_name => "worldreadable",
)->then( sub {
my ( $room_id ) = @_;

Future->needs_all(
matrix_set_room_history_visibility( $user, $room_id, "world_readable" ),
matrix_put_room_state( $user, $room_id,
type => "m.room.avatar",
state_key => "",
content => {
url => "https://example.com/ringtails.jpg",
}
),
);
}),
)->then( sub {
$http->do_request_json(
method => "GET",
uri => "/api/v1/publicRooms",
)})->then( sub {
my ( $body ) = @_;

log_if_fail "publicRooms", $body;

assert_json_keys( $body, qw( start end chunk ));
assert_json_list( $body->{chunk} );

my %seen = (
worldreadable => 0,
nonworldreadable => 0,
);

foreach my $room ( @{ $body->{chunk} } ) {
my $aliases = $room->{aliases};

foreach my $alias ( @{$aliases} ) {
if( $alias =~ m/^\Q#worldreadable:/ ) {
assert_json_keys( $room, qw( avatar_url ) );
assert_eq( $room->{avatar_url}, "https://example.com/ringtails.jpg", "avatar_url" );
$seen{worldreadable} = 1;
}
elsif( $alias =~ m/^\Q#nonworldreadable:/ ) {
assert_json_keys( $room, qw( avatar_url ) );
assert_eq( $room->{avatar_url}, "https://example.com/ruffed.jpg", "avatar_url" );
$seen{nonworldreadable} = 1;
}
}
}

foreach my $key (keys %seen ) {
$seen{$key} or die "Didn't see $key";
}

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

sub anonymous_user_fixture
{
fixture(
Expand Down

0 comments on commit 1337730

Please sign in to comment.