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

Add tests for transfer of tags and dm status on room upgrade #547

Merged
merged 6 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
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.
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved

=cut

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

# Download account data events from sync
matrix_sync( $user )->then( sub {
Copy link
Member

Choose a reason for hiding this comment

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

How about using GET /_matrix/client/r0/user/{user}/account_data/m.direct (matrix-org/matrix-spec-proposals#1339) ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah cool.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed this is already a function:

sub matrix_get_room_account_data
{
my ( $user, $room_id, $type, $content ) = @_;
do_request_json_for( $user,
method => "GET",
uri => "/r0/user/:user_id/rooms/$room_id/account_data/$type",
);
}

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