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

Tests for returning room avatar URLs in /publicRooms #121

Merged
merged 1 commit into from
Jan 5, 2016
Merged
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
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a slight danger of these "unique" alias names becoming fragile across many test files.
I don't have any better suggestion currently, but perhaps something to think about for the future. Maybe a fixture for allocating new unique alias names?

)->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