Skip to content

Commit

Permalink
Add tests for transfer of tags and dm status on room upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 committed Jan 22, 2019
1 parent 742348d commit 38e5526
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
74 changes: 74 additions & 0 deletions tests/30rooms/60version_upgrade.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -59,6 +61,45 @@ sub upgrade_room {
});
}

=head2 is_direct_room
is_direct_room( $user, $room_id )->then( sub {
my ( $is_direct ) = @_;
})
Check if a room ID is considered direct by the given user.
=cut

sub is_direct_room {
my ( $user, $room_id ) = @_;

# Download account data events from sync
matrix_sync( $user )->then( sub {
my ( $sync_body ) = @_;

# Should only have the m.direct event in account_data
my $account_data = $sync_body->{account_data}{events};

# Check if the room_id is in the list of direct rooms
foreach my $event ( @$account_data ) {
if ( $event->{type} eq "m.direct" ) {
my $room_ids = $event->{content}{$user->user_id};

# Return whether the given room ID is in the response
foreach my $rid (@$room_ids) {
if ( $rid eq $room_id ) {
return Future->done( 1 );
}
}
}
}

# Didn't find an m.direct event with our room ID
Future->done( 0 );
});
}

=head2 upgrade_room_synced
upgrade_room_synced( $user, $room_id, %opts )->then( sub {
Expand Down Expand Up @@ -474,6 +515,39 @@ sub upgrade_room_synced {
});
};

test "/upgrade preserves direct room state",
requires => [
local_user_and_room_fixtures(),
qw( can_upgrade_room_version ),
],

do => sub {
my ( $creator, $room_id ) = @_;

my $new_room_id;
my $user_id = $creator->user_id;

do_request_json_for(
$creator,
method => "PUT",
uri => "/r0/user/$user_id/account_data/m.direct",
content => { $user_id => [$room_id] },
)->then( sub {
upgrade_room_synced(
$creator, $room_id,
new_version => $TEST_NEW_VERSION,
);
})->then( sub {
( $new_room_id ) = @_;

is_direct_room( $creator, $new_room_id );
})->then( sub {
my ( $is_direct_room ) = @_;

$is_direct_room == 1 or die "Expected upgraded room to be a direct room";
Future->done( 1 );
});
};

test "/upgrade restricts power levels in the old room",
requires => [
Expand Down
41 changes: 41 additions & 0 deletions tests/42tags.pl
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,44 @@ sub check_account_data {
Future->done( 1 );
});
};

test "/upgrade copies user tags to the new room",
requires => [
local_user_and_room_fixtures(),
qw( can_upgrade_room_version can_add_tag ),
],

do => sub {
my ( $user, $room_id ) = @_;
my ( $new_room_id );

matrix_add_tag(
$user, $room_id, "test_tag", {}
)->then( sub {
matrix_sync( $user );
})->then( sub {
upgrade_room_synced(
$user, $room_id,
new_version => $main::TEST_NEW_VERSION,
);
})->then( sub {
( $new_room_id, ) = @_;

matrix_sync_again( $user );
})->then( sub {
my ( $sync_body ) = @_;

log_if_fail "sync body", $sync_body;

my $room = $sync_body->{rooms}{join}{$new_room_id};

matrix_list_tags( $user, $new_room_id );
})->then( sub {
my ( $tags ) = @_;

keys %{ $tags } == 1 or die "Expected one tag in the upgraded room";
defined $tags->{test_tag} or die "Unexpected tag";

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

0 comments on commit 38e5526

Please sign in to comment.