Skip to content

Commit

Permalink
Pass all matrix_create_room options through
Browse files Browse the repository at this point in the history
It's annoying to have to edit each time createRoom gets a new knob. Just pass
everything through.

There are a couple of related changes to make this work:

* in matrix_create_and_join_room, filter out the options which apply to that
  function before calling matrix_create_room

* in local_user_and_room_fixtures, distinguish between opts which are meant for
  the user fixture and those that are meant for the room fixture - and then
  update the handful of points which actually pass in such options

* the 'publicroomslist' used to pass 'undef' for a couple of parameters to
  matrix_create_room; that was wrongheaded and we should not pass those params
  at all.
  • Loading branch information
richvdh committed Aug 3, 2018
1 parent aebf152 commit db6a661
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 29 deletions.
47 changes: 29 additions & 18 deletions tests/10apidoc/30room-create.pl
Original file line number Diff line number Diff line change
Expand Up @@ -91,33 +91,42 @@
matrix_create_room_synced( $user );
};


=head2 matrix_create_room
matrix_create_room( $creator, %opts )->then( sub {
my ( $room_id, $room_alias ) = @_;
});
Create a new room.
Any options given in %opts are passed into the /createRoom API.
The following options have defaults:
visibility => 'private'
preset => 'public_chat'
The resultant future completes with two values: the room_id from the
/createRoom response; the room_alias from the /createRoom response (which is
non-standard and its use is deprecated).
=cut

push our @EXPORT, qw( matrix_create_room );

sub matrix_create_room
{
my ( $user, %opts ) = @_;
is_User( $user ) or croak "Expected a User; got $user";

$opts{visibility} //= "private";
$opts{preset} //= "public_chat";

do_request_json_for( $user,
method => "POST",
uri => "/r0/createRoom",

content => {
visibility => $opts{visibility} || "private",
preset => $opts{preset} || "public_chat",
( defined $opts{room_alias_name} ?
( room_alias_name => $opts{room_alias_name} ) : () ),
( defined $opts{invite} ?
( invite => $opts{invite} ) : () ),
( defined $opts{invite_3pid} ?
( invite_3pid => $opts{invite_3pid} ) : () ),
( defined $opts{creation_content} ?
( creation_content => $opts{creation_content} ) : () ),
( defined $opts{name} ?
( name => $opts{name} ) : () ),
( defined $opts{topic} ?
( topic => $opts{topic} ) : () ),
}
content => \%opts,
)->then( sub {
my ( $body ) = @_;

Expand Down Expand Up @@ -195,7 +204,9 @@ sub room_alias_fixture

=head2 matrix_create_room_synced
my ( $room_id, $room_alias, $sync_body ) = matrix_create_room_synced( %params );
matrix_create_room_synced( $creator, %params )->then( sub {
my ( $room_id, $room_alias, $sync_body ) = @_;
});
Creates a new room, and waits for it to appear in the /sync response.
Expand Down
49 changes: 45 additions & 4 deletions tests/10apidoc/33room-members.pl
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,41 @@ sub _invite_users
);
}

=head2 matrix_create_and_join_room
matrix_create_and_join_room( [ $creator, $user2, ... ], %opts )->then( sub {
my ( $room_id ) = @_;
});
matrix_create_and_join_room( [ $creator, $user2, ... ],
with_alias => 1, %opts,
)->then( sub {
my ( $room_id, $room_alias ) = @_;
});
Create a new room, and have a list of users join it.
The following may be passed as optional parametrs:
=over
=item with_alias => SCALAR
Make this truthy to return the newly created alias
=item with_invite => SCALAR
Make this truthy to send invites to the other users before they join.
=item (everything else)
Other parameters are passed into C<matrix_create_room>, whence they are
passed on to the server.
=back
=cut

push @EXPORT, qw( matrix_create_and_join_room );

sub matrix_create_and_join_room
Expand All @@ -413,6 +448,9 @@ sub matrix_create_and_join_room

my $n_joiners = scalar @other_members;

my $with_invite = delete $options{with_invite};
my $with_alias = delete $options{with_alias};

matrix_create_room( $creator,
%options,
room_alias_name => sprintf( "test-%s-%d", $TEST_RUN_ID, $next_alias++ ),
Expand All @@ -421,7 +459,7 @@ sub matrix_create_and_join_room

log_if_fail "room_id=$room_id";

( $options{with_invite} ?
( $with_invite ?
_invite_users( $creator, $room_id, @other_members ) :
Future->done() )
})->then( sub {
Expand All @@ -445,7 +483,7 @@ sub matrix_create_and_join_room
)
})->then( sub {
Future->done( $room_id,
( $options{with_alias} ? ( $room_alias_fullname ) : () )
( $with_alias ? ( $room_alias_fullname ) : () )
);
});
}
Expand Down Expand Up @@ -497,11 +535,14 @@ sub local_user_and_room_fixtures
{
my %args = @_;

my $user_fixture = local_user_fixture( %args );
my $user_opts = $args{user_opts} // {};
my $room_opts = $args{room_opts} // {};

my $user_fixture = local_user_fixture( %$user_opts );

return (
$user_fixture,
room_fixture( $user_fixture, %args ),
room_fixture( $user_fixture, %$room_opts ),
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/30rooms/21receipts.pl
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ sub find_receipt
};

test "Read receipts are sent as events",
requires => [ local_user_and_room_fixtures( with_events => 1 ),
requires => [ local_user_and_room_fixtures( user_opts => { with_events => 1 }),
qw( can_post_room_receipts )],

do => sub {
Expand Down
3 changes: 1 addition & 2 deletions tests/30rooms/70publicroomslist.pl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
matrix_create_room( $user,
visibility => "public",
room_alias_name => $alias_local,
name => $room->{name},
topic => $room->{topic},
%{$room},
)
} keys %rooms )
->then( sub {
Expand Down
2 changes: 1 addition & 1 deletion tests/50federation/31room-send.pl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

test "Inbound federation can receive events",
requires => [ $main::OUTBOUND_CLIENT, $main::HOMESERVER_INFO[0],
local_user_and_room_fixtures( with_events => 1 ),
local_user_and_room_fixtures( user_opts => { with_events => 1 }),
federation_user_id_fixture() ],

do => sub {
Expand Down
2 changes: 1 addition & 1 deletion tests/50federation/33room-get-missing-events.pl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test "Outbound federation can request missing events",
requires => [ $main::OUTBOUND_CLIENT, $main::INBOUND_SERVER, $main::HOMESERVER_INFO[0],
local_user_and_room_fixtures( with_events => 1 ),
local_user_and_room_fixtures( user_opts => { with_events => 1 }),
federation_user_id_fixture() ],

do => sub {
Expand Down
4 changes: 2 additions & 2 deletions tests/50federation/36-state.pl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@

test "Outbound federation requests /state_ids and correctly handles 404",
requires => [ $main::OUTBOUND_CLIENT, $main::INBOUND_SERVER, $main::HOMESERVER_INFO[0],
local_user_and_room_fixtures( with_events => 1 ),
local_user_and_room_fixtures( user_opts => { with_events => 1 } ),
federation_user_id_fixture() ],

do => sub {
Expand Down Expand Up @@ -174,7 +174,7 @@
# Disabled as Synapse now checks the state of the missing item's ancestors instead
bug => "DISABLED",
requires => [ $main::OUTBOUND_CLIENT, $main::INBOUND_SERVER, $main::HOMESERVER_INFO[0],
local_user_and_room_fixtures( with_events => 1 ),
local_user_and_room_fixtures( user_opts => { with_events => 1 } ),
federation_user_id_fixture() ],

do => sub {
Expand Down

0 comments on commit db6a661

Please sign in to comment.